Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lifetime shadowing check in GATs #68938

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.