Skip to content

Commit

Permalink
Auto merge of #68938 - Areredify:gat_lifetime_shadowing, r=<try>
Browse files Browse the repository at this point in the history
fix lifetime shadowing check in GATs

closes #67512
  • Loading branch information
bors committed Feb 7, 2020
2 parents a29424a + 953f6ec commit 26ab07b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/librustc_resolve/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
track_lifetime_uses: true,
opaque_type_parent: true,
};
self.with(scope, |_old_scope, this| {
self.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &generics.params);
this.visit_generics(generics);
for bound in bounds {
this.visit_param_bound(bound);
Expand Down Expand Up @@ -804,7 +805,8 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
track_lifetime_uses: true,
opaque_type_parent: true,
};
self.with(scope, |_old_scope, this| {
self.with(scope, |old_scope, this| {
this.check_lifetime_params(old_scope, &generics.params);
this.visit_generics(generics);
this.visit_ty(ty);
});
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/generic-associated-types/shadowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
#![feature(generic_associated_types)]

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

trait NoShadow<'a> {
type Bar<'b>; // OK
}

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

trait ShadowT<T> {
Expand Down
21 changes: 19 additions & 2 deletions src/test/ui/generic-associated-types/shadowing.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,22 @@ LL | impl<T> NoShadowT<T> for Option<T> {
LL | type Bar<T> = i32;
| ^ already used

error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
--> $DIR/shadowing.rs:5:14
|
LL | trait Shadow<'a> {
| -- first declared here
LL | type Bar<'a>;
| ^^ lifetime 'a already in scope

error[E0496]: lifetime name `'a` shadows a lifetime name that is already in scope
--> $DIR/shadowing.rs:14:14
|
LL | impl<'a> NoShadow<'a> for &'a u32 {
| -- first declared here
LL | type Bar<'a> = i32;
| ^^ lifetime 'a already in scope

error: type-generic associated types are not yet implemented
--> $DIR/shadowing.rs:19:5
|
Expand All @@ -30,6 +46,7 @@ LL | type Bar<U>; // OK
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265

error: aborting due to 4 previous errors
error: aborting due to 6 previous errors

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

0 comments on commit 26ab07b

Please sign in to comment.