diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 2d87d8c84d7c9..ee868296d9dce 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -301,17 +301,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_ty(self, ty) } - fn visit_generics(&mut self, g: &'a ast::Generics) { - for predicate in &g.where_clause.predicates { - match &predicate.kind { - ast::WherePredicateKind::BoundPredicate(bound_pred) => { - // A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). - self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params); - } - _ => {} - } + fn visit_where_predicate_kind(&mut self, kind: &'a ast::WherePredicateKind) { + if let ast::WherePredicateKind::BoundPredicate(bound) = kind { + // A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`). + self.check_late_bound_lifetime_defs(&bound.bound_generic_params); } - visit::walk_generics(self, g); + visit::walk_where_predicate_kind(self, kind); } fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) { diff --git a/tests/ui/associated-types/associated-type-where-non-lifetime-const.rs b/tests/ui/associated-types/associated-type-where-non-lifetime-const.rs new file mode 100644 index 0000000000000..31bf139e39cdc --- /dev/null +++ b/tests/ui/associated-types/associated-type-where-non-lifetime-const.rs @@ -0,0 +1,13 @@ +//! regression test for #148627 + +#![feature(associated_type_defaults)] + +trait Trait { + type Assoc2 + = () + where + for [(); C]: Copy; + //~^ ERROR: only lifetime parameters can be used in this context +} + +fn main() {} diff --git a/tests/ui/associated-types/associated-type-where-non-lifetime-const.stderr b/tests/ui/associated-types/associated-type-where-non-lifetime-const.stderr new file mode 100644 index 0000000000000..bd1d6e13893ae --- /dev/null +++ b/tests/ui/associated-types/associated-type-where-non-lifetime-const.stderr @@ -0,0 +1,13 @@ +error[E0658]: only lifetime parameters can be used in this context + --> $DIR/associated-type-where-non-lifetime-const.rs:9:19 + | +LL | for [(); C]: Copy; + | ^ + | + = note: see issue #108185 for more information + = help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/associated-types/associated-type-where-non-lifetime-type.rs b/tests/ui/associated-types/associated-type-where-non-lifetime-type.rs new file mode 100644 index 0000000000000..d4624619e6d88 --- /dev/null +++ b/tests/ui/associated-types/associated-type-where-non-lifetime-type.rs @@ -0,0 +1,18 @@ +//! regression test for #149233 + +trait Foo { + type Bar<'a> + where + Self: Sized; + fn test(&self); +} +impl Foo for () { + type Bar<'a> + = () + where + for T:; + //~^ ERROR: only lifetime parameters can be used in this context + fn test(&self) {} +} + +fn main() {} diff --git a/tests/ui/associated-types/associated-type-where-non-lifetime-type.stderr b/tests/ui/associated-types/associated-type-where-non-lifetime-type.stderr new file mode 100644 index 0000000000000..a8a71b929d952 --- /dev/null +++ b/tests/ui/associated-types/associated-type-where-non-lifetime-type.stderr @@ -0,0 +1,13 @@ +error[E0658]: only lifetime parameters can be used in this context + --> $DIR/associated-type-where-non-lifetime-type.rs:13:13 + | +LL | for T:; + | ^ + | + = note: see issue #108185 for more information + = help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`.