Skip to content
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
15 changes: 5 additions & 10 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Copy link
Member

@fmease fmease Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating what visit_generics is doing & manually visiting the after_where_clause, could you instead please

  1. remove the existing visit_generics implementation entirely (the entire fn)
  2. remove check_ty_alias_after_where_clause again
  3. instead, explicitly implement visit_where_predicate_kind so it's calling check_late_bound_lifetime_defs with the expected arguments, followed by visit::walk_where_predicate_kind(…) to continue the recursion
    • this should work because we automatically visit both before & after where clauses (due to derive(Walkable)) (and if that doesn't happen, then that's a bug)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the review! I've applied the suggested changes.

Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! regression test for #148627
#![feature(associated_type_defaults)]

trait Trait {
type Assoc2
= ()
where
for<const C: usize> [(); C]: Copy;
//~^ ERROR: only lifetime parameters can be used in this context
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -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<const C: usize> [(); C]: Copy;
| ^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/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`.
Original file line number Diff line number Diff line change
@@ -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> T:;
//~^ ERROR: only lifetime parameters can be used in this context
fn test(&self) {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -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> T:;
| ^
|
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/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`.
Loading