Disallow duplicate lifetime parameters with legacy hygiene
They were resolved with modern hygiene, making this just a strange way to shadow lifetimes.
This commit is contained in:
parent
9a239ef4de
commit
3dca17e62d
@ -2568,7 +2568,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
|
||||
let lifetimes: Vec<_> = params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => Some((param, param.name)),
|
||||
GenericParamKind::Lifetime { .. } => Some((param, param.name.modern())),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
|
19
src/test/ui/hygiene/duplicate_lifetimes.rs
Normal file
19
src/test/ui/hygiene/duplicate_lifetimes.rs
Normal file
@ -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() {}
|
27
src/test/ui/hygiene/duplicate_lifetimes.stderr
Normal file
27
src/test/ui/hygiene/duplicate_lifetimes.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user