Skip to content

Commit 314023f

Browse files
committed
Check associated type where-clauses for lifetimes
1 parent b4f1098 commit 314023f

File tree

5 files changed

+67
-1
lines changed

5 files changed

+67
-1
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ impl<'a> PostExpansionVisitor<'a> {
119119
ImplTraitVisitor { vis: self, in_associated_ty }.visit_ty(ty);
120120
}
121121

122+
fn check_ty_alias_after_where_clause(&self, clause: &ast::WhereClause) {
123+
for predicate in &clause.predicates {
124+
if let ast::WherePredicateKind::BoundPredicate(bound_pred) = &predicate.kind {
125+
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
126+
}
127+
}
128+
}
129+
122130
fn check_late_bound_lifetime_defs(&self, params: &[ast::GenericParam]) {
123131
// Check only lifetime parameters are present and that the
124132
// generic parameters that are present have no bounds.
@@ -410,7 +418,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
410418
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
411419
let is_fn = match &i.kind {
412420
ast::AssocItemKind::Fn(_) => true,
413-
ast::AssocItemKind::Type(box ast::TyAlias { ty, .. }) => {
421+
ast::AssocItemKind::Type(box ast::TyAlias { ty, after_where_clause, .. }) => {
422+
self.check_ty_alias_after_where_clause(after_where_clause);
414423
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
415424
gate!(
416425
&self,
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)