diff options
| author | bors <bors@rust-lang.org> | 2023-11-07 13:04:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-11-07 13:04:56 +0000 |
| commit | 187d1afa9dc17d06e65f5e817e2bd1d9ae33830a (patch) | |
| tree | ea218bc00dede4d598b2d570ac2d96eb3f986532 /compiler/rustc_parse/src/parser | |
| parent | 61a3eea8043cc1c7a09c2adda884e27ffa8a1172 (diff) | |
| parent | 904aceec7d9595d49b1ce6e9e8a04f64f6a814fd (diff) | |
| download | rust-187d1afa9dc17d06e65f5e817e2bd1d9ae33830a.tar.gz rust-187d1afa9dc17d06e65f5e817e2bd1d9ae33830a.zip | |
Auto merge of #117297 - clubby789:fn-trait-missing-paren, r=TaKO8Ki
Give a better diagnostic for missing parens in Fn* bounds Fixes #108109 It would be nice to try and recover here, but I'm not sure it's worth the effort, especially as the bounds on the recovered function would be incorrect.
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 253dd2a3b34..65d41ea19fd 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); } } |
