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:
Matthew Jasper 2019-07-28 13:33:51 +01:00
parent 9a239ef4de
commit 3dca17e62d
3 changed files with 47 additions and 1 deletions

View File

@ -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();

View 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() {}

View 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`.