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/errors.rs | |
| 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/errors.rs')
| -rw-r--r-- | compiler/rustc_parse/src/errors.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index aeb4fd0a304..311d573d1fc 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -1370,6 +1370,34 @@ pub(crate) struct FnPtrWithGenericsSugg { pub for_param_list_exists: bool, } +pub(crate) struct FnTraitMissingParen { + pub span: Span, + pub machine_applicable: bool, +} + +impl AddToDiagnostic for FnTraitMissingParen { + fn add_to_diagnostic_with<F>(self, diag: &mut rustc_errors::Diagnostic, _: F) + where + F: Fn( + &mut rustc_errors::Diagnostic, + rustc_errors::SubdiagnosticMessage, + ) -> rustc_errors::SubdiagnosticMessage, + { + diag.span_label(self.span, crate::fluent_generated::parse_fn_trait_missing_paren); + let applicability = if self.machine_applicable { + Applicability::MachineApplicable + } else { + Applicability::MaybeIncorrect + }; + diag.span_suggestion_short( + self.span.shrink_to_hi(), + crate::fluent_generated::parse_add_paren, + "()", + applicability, + ); + } +} + #[derive(Diagnostic)] #[diag(parse_unexpected_if_with_if)] pub(crate) struct UnexpectedIfWithIf( |
