diff options
| author | clubby789 <jamie@hill-daniel.co.uk> | 2023-10-27 19:51:51 +0000 |
|---|---|---|
| committer | clubby789 <jamie@hill-daniel.co.uk> | 2023-11-01 15:33:46 +0000 |
| commit | 904aceec7d9595d49b1ce6e9e8a04f64f6a814fd (patch) | |
| tree | 7c0e33b4bc2216337c101bd7b037fec7d955ac9d /compiler/rustc_parse/src/parser | |
| parent | 9d6d5d48948945debca5a693f6030246f7bb2baf (diff) | |
| download | rust-904aceec7d9595d49b1ce6e9e8a04f64f6a814fd.tar.gz rust-904aceec7d9595d49b1ce6e9e8a04f64f6a814fd.zip | |
Give a better diagnostic for missing parens in Fn* bounds
Diffstat (limited to 'compiler/rustc_parse/src/parser')
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 982f601c0d5..aa06fd9df51 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -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); } } |
