Skip to content

Commit

Permalink
fix lifetime shadowing check in GATs
Browse files Browse the repository at this point in the history
  • Loading branch information
basil-cow committed Feb 7, 2020
1 parent b5e21db commit 953f6ec
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 953f6ec

Please sign in to comment.