Skip to content

Commit 82af0ee

Browse files
authored
Rollup merge of #149714 - reddevilmidzy:atd, r=fmease
Check associated type where-clauses for lifetimes resolves: #148627 resolves: #149233
2 parents fa9a8f4 + d53f767 commit 82af0ee

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,17 +301,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
301301
visit::walk_ty(self, ty)
302302
}
303303

304-
fn visit_generics(&mut self, g: &'a ast::Generics) {
305-
for predicate in &g.where_clause.predicates {
306-
match &predicate.kind {
307-
ast::WherePredicateKind::BoundPredicate(bound_pred) => {
308-
// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
309-
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
310-
}
311-
_ => {}
312-
}
304+
fn visit_where_predicate_kind(&mut self, kind: &'a ast::WherePredicateKind) {
305+
if let ast::WherePredicateKind::BoundPredicate(bound) = kind {
306+
// A type bound (e.g., `for<'c> Foo: Send + Clone + 'c`).
307+
self.check_late_bound_lifetime_defs(&bound.bound_generic_params);
313308
}
314-
visit::walk_generics(self, g);
309+
visit::walk_where_predicate_kind(self, kind);
315310
}
316311

317312
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! regression test for #148627
2+
3+
#![feature(associated_type_defaults)]
4+
5+
trait Trait {
6+
type Assoc2
7+
= ()
8+
where
9+
for<const C: usize> [(); C]: Copy;
10+
//~^ ERROR: only lifetime parameters can be used in this context
11+
}
12+
13+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: only lifetime parameters can be used in this context
2+
--> $DIR/associated-type-where-non-lifetime-const.rs:9:19
3+
|
4+
LL | for<const C: usize> [(); C]: Copy;
5+
| ^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//! regression test for #149233
2+
3+
trait Foo {
4+
type Bar<'a>
5+
where
6+
Self: Sized;
7+
fn test(&self);
8+
}
9+
impl Foo for () {
10+
type Bar<'a>
11+
= ()
12+
where
13+
for<T> T:;
14+
//~^ ERROR: only lifetime parameters can be used in this context
15+
fn test(&self) {}
16+
}
17+
18+
fn main() {}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: only lifetime parameters can be used in this context
2+
--> $DIR/associated-type-where-non-lifetime-type.rs:13:13
3+
|
4+
LL | for<T> T:;
5+
| ^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= help: add `#![feature(non_lifetime_binders)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)