Skip to content

Commit 3dca17e

Browse files
committed
Disallow duplicate lifetime parameters with legacy hygiene
They were resolved with modern hygiene, making this just a strange way to shadow lifetimes.
1 parent 9a239ef commit 3dca17e

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

src/librustc/middle/resolve_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
25682568
let lifetimes: Vec<_> = params
25692569
.iter()
25702570
.filter_map(|param| match param.kind {
2571-
GenericParamKind::Lifetime { .. } => Some((param, param.name)),
2571+
GenericParamKind::Lifetime { .. } => Some((param, param.name.modern())),
25722572
_ => None,
25732573
})
25742574
.collect();
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Ensure that lifetime parameter names are modernized before we check for
2+
// duplicates.
3+
4+
#![feature(decl_macro, rustc_attrs)]
5+
6+
#[rustc_macro_transparency = "semitransparent"]
7+
macro m($a:lifetime) {
8+
fn g<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice
9+
}
10+
11+
#[rustc_macro_transparency = "transparent"]
12+
macro n($a:lifetime) {
13+
fn h<$a, 'a>() {} //~ ERROR lifetime name `'a` declared twice
14+
}
15+
16+
m!('a);
17+
n!('a);
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0263]: lifetime name `'a` declared twice in the same scope
2+
--> $DIR/duplicate_lifetimes.rs:8:14
3+
|
4+
LL | fn g<$a, 'a>() {}
5+
| ^^ declared twice
6+
...
7+
LL | m!('a);
8+
| -------
9+
| | |
10+
| | previous declaration here
11+
| in this macro invocation
12+
13+
error[E0263]: lifetime name `'a` declared twice in the same scope
14+
--> $DIR/duplicate_lifetimes.rs:13:14
15+
|
16+
LL | fn h<$a, 'a>() {}
17+
| ^^ declared twice
18+
...
19+
LL | n!('a);
20+
| -------
21+
| | |
22+
| | previous declaration here
23+
| in this macro invocation
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0263`.

0 commit comments

Comments
 (0)