Skip to content

Commit 23a9469

Browse files
committed
Auto merge of #39158 - petrochenkov:bounds, r=nikomatsakis
Bounds parsing refactoring 2 See #37511 for previous discussion. cc @matklad Relaxed parsing rules: - zero bounds after `:` are allowed in all contexts. - zero predicates are allowed after `where`. - trailing separator `,` is allowed after predicates in `where` clauses not followed by `{`. Other parsing rules: - trailing separator `+` is still allowed in all bound lists. Code is also cleaned up and tests added. I haven't touched parsing of trait object types yet, I'll do it later.
2 parents 8430042 + bd4d5ec commit 23a9469

32 files changed

+565
-469
lines changed

src/librustc_passes/ast_validation.rs

+26
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
146146
TyKind::TraitObject(ref bounds) => {
147147
self.no_questions_in_bounds(bounds, "trait object types", false);
148148
}
149+
TyKind::ImplTrait(ref bounds) => {
150+
if !bounds.iter()
151+
.any(|b| if let TraitTyParamBound(..) = *b { true } else { false }) {
152+
self.err_handler().span_err(ty.span, "at least one trait must be specified");
153+
}
154+
}
149155
_ => {}
150156
}
151157

@@ -284,6 +290,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
284290

285291
visit::walk_vis(self, vis)
286292
}
293+
294+
fn visit_generics(&mut self, g: &'a Generics) {
295+
let mut seen_default = None;
296+
for ty_param in &g.ty_params {
297+
if ty_param.default.is_some() {
298+
seen_default = Some(ty_param.span);
299+
} else if let Some(span) = seen_default {
300+
self.err_handler()
301+
.span_err(span, "type parameters with a default must be trailing");
302+
break
303+
}
304+
}
305+
for predicate in &g.where_clause.predicates {
306+
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
307+
self.err_handler().span_err(predicate.span, "equality constraints are not yet \
308+
supported in where clauses (#20041)");
309+
}
310+
}
311+
visit::walk_generics(self, g)
312+
}
287313
}
288314

289315
pub fn check_crate(session: &Session, krate: &Crate) {

src/librustc_typeck/collect.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1833,11 +1833,8 @@ fn ty_generic_predicates<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
18331833
}
18341834
}
18351835

1836-
&hir::WherePredicate::EqPredicate(ref eq_pred) => {
1836+
&hir::WherePredicate::EqPredicate(..) => {
18371837
// FIXME(#20041)
1838-
span_bug!(eq_pred.span,
1839-
"Equality constraints are not yet \
1840-
implemented (#20041)")
18411838
}
18421839
}
18431840
}

src/librustdoc/clean/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,11 @@ impl Clean<WherePredicate> for hir::WherePredicate {
842842
}
843843
}
844844

845-
hir::WherePredicate::EqPredicate(_) => {
846-
unimplemented!() // FIXME(#20041)
845+
hir::WherePredicate::EqPredicate(ref wrp) => {
846+
WherePredicate::EqPredicate {
847+
lhs: wrp.lhs_ty.clean(cx),
848+
rhs: wrp.rhs_ty.clean(cx)
849+
}
847850
}
848851
}
849852
}

0 commit comments

Comments
 (0)