Auto merge of #48326 - RalfJung:generic-bounds, r=petrochenkov
Warn about ignored generic bounds in `for` This adds a new lint to fix #42181. For consistency and to avoid code duplication, I also moved the existing "bounds in type aliases are ignored" here. Questions to the reviewer: * Is it okay to just remove a diagnostic error code like this? Should I instead keep the warning about type aliases where it is? The old code provided a detailed explanation of what's going on when asked, that information is now lost. On the other hand, `span_warn!` seems deprecated (after this patch, it has exactly one user left!). * Did I miss any syntactic construct that can appear as `for` in the surface syntax? I covered function types (`for<'a> fn(...)`), generic traits (`for <'a> Fn(...)`, can appear both as bounds as as trait objects) and bounds (`for<'a> F: ...`). * For the sake of backwards compatibility, this adds a warning, not an error. @nikomatsakis suggested an error in https://github.com/rust-lang/rust/issues/42181#issuecomment-306924389, but I feel that can only happen in a new epoch -- right? Cc @eddyb
This commit is contained in:
commit
fedce67cd2
20 changed files with 325 additions and 109 deletions
|
@ -4951,6 +4951,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
));
|
||||
// FIXME: Decide what should be used here, `=` or `==`.
|
||||
// FIXME: We are just dropping the binders in lifetime_defs on the floor here.
|
||||
} else if self.eat(&token::Eq) || self.eat(&token::EqEq) {
|
||||
let rhs_ty = self.parse_ty()?;
|
||||
where_clause.predicates.push(ast::WherePredicate::EqPredicate(
|
||||
|
@ -5608,18 +5609,8 @@ impl<'a> Parser<'a> {
|
|||
self.expect_lt()?;
|
||||
let params = self.parse_generic_params()?;
|
||||
self.expect_gt()?;
|
||||
|
||||
let first_non_lifetime_param_span = params.iter()
|
||||
.filter_map(|param| match *param {
|
||||
ast::GenericParam::Lifetime(_) => None,
|
||||
ast::GenericParam::Type(ref t) => Some(t.span),
|
||||
})
|
||||
.next();
|
||||
|
||||
if let Some(span) = first_non_lifetime_param_span {
|
||||
self.span_err(span, "only lifetime parameters can be used in this context");
|
||||
}
|
||||
|
||||
// We rely on AST validation to rule out invalid cases: There must not be type
|
||||
// parameters, and the lifetime parameters must not have bounds.
|
||||
Ok(params)
|
||||
} else {
|
||||
Ok(Vec::new())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue