Skip to content

Commit 9b432e0

Browse files
authored
Rollup merge of #84377 - jackh726:binder-refactor-fix, r=nikomatsakis
Followup to #83944 Some cleanups requested by ``@nikomatsakis`` r? ``@nikomatsakis``
2 parents 7b6fd61 + c78724f commit 9b432e0

File tree

2 files changed

+254
-422
lines changed

2 files changed

+254
-422
lines changed

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+35-10
Original file line numberDiff line numberDiff line change
@@ -1213,8 +1213,41 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12131213
deny_equality_constraints(self, predicate, generics);
12141214
}
12151215
}
1216-
1217-
visit::walk_generics(self, generics)
1216+
walk_list!(self, visit_generic_param, &generics.params);
1217+
for predicate in &generics.where_clause.predicates {
1218+
match predicate {
1219+
WherePredicate::BoundPredicate(bound_pred) => {
1220+
// A type binding, eg `for<'c> Foo: Send+Clone+'c`
1221+
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
1222+
1223+
// This is slightly complicated. Our representation for poly-trait-refs contains a single
1224+
// binder and thus we only allow a single level of quantification. However,
1225+
// the syntax of Rust permits quantification in two places in where clauses,
1226+
// e.g., `T: for <'a> Foo<'a>` and `for <'a, 'b> &'b T: Foo<'a>`. If both are
1227+
// defined, then error.
1228+
if !bound_pred.bound_generic_params.is_empty() {
1229+
for bound in &bound_pred.bounds {
1230+
match bound {
1231+
GenericBound::Trait(t, _) => {
1232+
if !t.bound_generic_params.is_empty() {
1233+
struct_span_err!(
1234+
self.err_handler(),
1235+
t.span,
1236+
E0316,
1237+
"nested quantification of lifetimes"
1238+
)
1239+
.emit();
1240+
}
1241+
}
1242+
GenericBound::Outlives(_) => {}
1243+
}
1244+
}
1245+
}
1246+
}
1247+
_ => {}
1248+
}
1249+
self.visit_where_predicate(predicate);
1250+
}
12181251
}
12191252

12201253
fn visit_generic_param(&mut self, param: &'a GenericParam) {
@@ -1263,14 +1296,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12631296
visit::walk_pat(self, pat)
12641297
}
12651298

1266-
fn visit_where_predicate(&mut self, p: &'a WherePredicate) {
1267-
if let &WherePredicate::BoundPredicate(ref bound_predicate) = p {
1268-
// A type binding, eg `for<'c> Foo: Send+Clone+'c`
1269-
self.check_late_bound_lifetime_defs(&bound_predicate.bound_generic_params);
1270-
}
1271-
visit::walk_where_predicate(self, p);
1272-
}
1273-
12741299
fn visit_poly_trait_ref(&mut self, t: &'a PolyTraitRef, m: &'a TraitBoundModifier) {
12751300
self.check_late_bound_lifetime_defs(&t.bound_generic_params);
12761301
visit::walk_poly_trait_ref(self, t, m);

0 commit comments

Comments
 (0)