-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make generic parameters always use modern hygiene #63083
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Ensure that lifetime parameter names are modernized before we check for | ||
// duplicates. | ||
|
||
#![feature(decl_macro, rustc_attrs)] | ||
|
||
#[rustc_macro_transparency = "semitransparent"] | ||
macro m($a:lifetime) { | ||
fn g<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice | ||
} | ||
|
||
#[rustc_macro_transparency = "transparent"] | ||
macro n($a:lifetime) { | ||
fn h<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice | ||
} | ||
|
||
m!('a); | ||
n!('a); | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error[E0263]: lifetime name `'a` declared twice in the same scope | ||
--> $DIR/duplicate_lifetimes.rs:8:14 | ||
| | ||
LL | fn g<$a, 'a>() {} | ||
| ^^ declared twice | ||
... | ||
LL | m!('a); | ||
| ------- | ||
| | | | ||
| | previous declaration here | ||
| in this macro invocation | ||
|
||
error[E0263]: lifetime name `'a` declared twice in the same scope | ||
--> $DIR/duplicate_lifetimes.rs:13:14 | ||
| | ||
LL | fn h<$a, 'a>() {} | ||
| ^^ declared twice | ||
... | ||
LL | n!('a); | ||
| ------- | ||
| | | | ||
| | previous declaration here | ||
| in this macro invocation | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0263`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Ensure that generic parameters always have modern hygiene. | ||
|
||
// check-pass | ||
// ignore-pretty pretty-printing is unhygienic | ||
|
||
#![feature(decl_macro, rustc_attrs, const_generics)] | ||
|
||
mod type_params { | ||
macro m($T:ident) { | ||
fn f<$T: Clone, T: PartialEq>(t1: $T, t2: T) -> ($T, bool) { | ||
(t1.clone(), t2 == t2) | ||
} | ||
} | ||
|
||
#[rustc_macro_transparency = "semitransparent"] | ||
macro n($T:ident) { | ||
fn g<$T: Clone>(t1: $T, t2: T) -> (T, $T) { | ||
(t1.clone(), t2.clone()) | ||
} | ||
fn h<T: Clone>(t1: $T, t2: T) -> (T, $T) { | ||
(t1.clone(), t2.clone()) | ||
} | ||
} | ||
|
||
#[rustc_macro_transparency = "transparent"] | ||
macro p($T:ident) { | ||
fn j<$T: Clone>(t1: $T, t2: T) -> (T, $T) { | ||
(t1.clone(), t2.clone()) | ||
} | ||
fn k<T: Clone>(t1: $T, t2: T) -> (T, $T) { | ||
(t1.clone(), t2.clone()) | ||
} | ||
} | ||
|
||
m!(T); | ||
n!(T); | ||
p!(T); | ||
} | ||
|
||
mod lifetime_params { | ||
macro m($a:lifetime) { | ||
fn f<'b, 'c, $a: 'b, 'a: 'c>(t1: &$a(), t2: &'a ()) -> (&'b (), &'c ()) { | ||
(t1, t2) | ||
} | ||
} | ||
|
||
#[rustc_macro_transparency = "semitransparent"] | ||
macro n($a:lifetime) { | ||
fn g<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) { | ||
(t1, t2) | ||
} | ||
fn h<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) { | ||
(t1, t2) | ||
} | ||
} | ||
|
||
#[rustc_macro_transparency = "transparent"] | ||
macro p($a:lifetime) { | ||
fn j<$a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) { | ||
(t1, t2) | ||
} | ||
fn k<'a>(t1: &$a(), t2: &'a ()) -> (&'a (), &$a ()) { | ||
(t1, t2) | ||
} | ||
} | ||
|
||
m!('a); | ||
n!('a); | ||
p!('a); | ||
} | ||
|
||
mod const_params { | ||
macro m($C:ident) { | ||
fn f<const $C: usize, const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); $C], [(); C]) { | ||
(t1, t2) | ||
} | ||
} | ||
|
||
#[rustc_macro_transparency = "semitransparent"] | ||
macro n($C:ident) { | ||
fn g<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) { | ||
(t1, t2) | ||
} | ||
fn h<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) { | ||
(t1, t2) | ||
} | ||
} | ||
|
||
#[rustc_macro_transparency = "transparent"] | ||
macro p($C:ident) { | ||
fn j<const $C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) { | ||
(t1, t2) | ||
} | ||
fn k<const C: usize>(t1: [(); $C], t2: [(); C]) -> ([(); C], [(); $C]) { | ||
(t1, t2) | ||
} | ||
} | ||
|
||
m!(C); | ||
n!(C); | ||
p!(C); | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/generic_params.rs:6:37 | ||
| | ||
LL | #![feature(decl_macro, rustc_attrs, const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
|
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this changed, and why did it work previously?
I don't quite remember all the differences between many kinds of ribs that act as "barriers" for names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason that this has little effect is that there is already an AssocItemRib around all associated items that holds any generic parameters. Since generic parameters can be seen through associated items, this rib isn't stopping any names from being visible.
The reason for the change is so that function parameters don't end up in an associated item rib, and get resolved with the wrong hygiene.