Give a better diagnostic for missing parens in Fn* bounds
This commit is contained in:
parent
9d6d5d4894
commit
904aceec7d
7 changed files with 73 additions and 0 deletions
|
@ -2278,6 +2278,18 @@ impl<'a> Parser<'a> {
|
|||
err.span_label(ident.span, "while parsing this `fn`");
|
||||
err.emit();
|
||||
} else {
|
||||
// check for typo'd Fn* trait bounds such as
|
||||
// fn foo<F>() where F: FnOnce -> () {}
|
||||
if self.token.kind == token::RArrow {
|
||||
let machine_applicable = [sym::FnOnce, sym::FnMut, sym::Fn]
|
||||
.into_iter()
|
||||
.any(|s| self.prev_token.is_ident_named(s));
|
||||
|
||||
err.subdiagnostic(errors::FnTraitMissingParen {
|
||||
span: self.prev_token.span,
|
||||
machine_applicable,
|
||||
});
|
||||
}
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue