Skip to content

Commit 998daf3

Browse files
authored
Rollup merge of #68938 - Areredify:gat_lifetime_shadowing, r=estebank
fix lifetime shadowing check in GATs closes #67512
2 parents 89f5dcf + 953f6ec commit 998daf3

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

src/librustc_resolve/lifetimes.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
747747
track_lifetime_uses: true,
748748
opaque_type_parent: true,
749749
};
750-
self.with(scope, |_old_scope, this| {
750+
self.with(scope, |old_scope, this| {
751+
this.check_lifetime_params(old_scope, &generics.params);
751752
this.visit_generics(generics);
752753
for bound in bounds {
753754
this.visit_param_bound(bound);
@@ -804,7 +805,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
804805
track_lifetime_uses: true,
805806
opaque_type_parent: true,
806807
};
807-
self.with(scope, |_old_scope, this| {
808+
self.with(scope, |old_scope, this| {
809+
this.check_lifetime_params(old_scope, &generics.params);
808810
this.visit_generics(generics);
809811
this.visit_ty(ty);
810812
});

src/test/ui/generic-associated-types/shadowing.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#![feature(generic_associated_types)]
33

44
trait Shadow<'a> {
5-
//FIXME(#44265): The lifetime parameter shadowing should cause an error.
65
type Bar<'a>;
6+
//~^ ERROR lifetime name `'a` shadows a lifetime name that is already in scope
77
}
88

99
trait NoShadow<'a> {
1010
type Bar<'b>; // OK
1111
}
1212

1313
impl<'a> NoShadow<'a> for &'a u32 {
14-
//FIXME(#44265): The lifetime parameter shadowing should cause an error.
1514
type Bar<'a> = i32;
15+
//~^ ERROR lifetime name `'a` shadows a lifetime name that is already in scope
1616
}
1717

1818
trait ShadowT<T> {

src/test/ui/generic-associated-types/shadowing.stderr

+19-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ LL | impl<T> NoShadowT<T> for Option<T> {
1414
LL | type Bar<T> = i32;
1515
| ^ already used
1616

17+
error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
18+
--> $DIR/shadowing.rs:5:14
19+
|
20+
LL | trait Shadow<'a> {
21+
| -- first declared here
22+
LL | type Bar<'a>;
23+
| ^^ lifetime 'a already in scope
24+
25+
error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
26+
--> $DIR/shadowing.rs:14:14
27+
|
28+
LL | impl<'a> NoShadow<'a> for &'a u32 {
29+
| -- first declared here
30+
LL | type Bar<'a> = i32;
31+
| ^^ lifetime 'a already in scope
32+
1733
error: type-generic associated types are not yet implemented
1834
--> $DIR/shadowing.rs:19:5
1935
|
@@ -30,6 +46,7 @@ LL | type Bar<U>; // OK
3046
|
3147
= note: for more information, see issue #44265 <https://github.com/rust-lang/rust/issues/44265> for more information
3248

33-
error: aborting due to 4 previous errors
49+
error: aborting due to 6 previous errors
3450

35-
For more information about this error, try `rustc --explain E0403`.
51+
Some errors have detailed explanations: E0403, E0496.
52+
For more information about an error, try `rustc --explain E0403`.

0 commit comments

Comments
 (0)