1
Fork 0

Rollup merge of #127350 - veera-sivarajan:bugfix-126311, r=lcnr

Parser: Suggest Placing the Return Type After Function Parameters

Fixes #126311

This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause.

This also tangentially improves diagnostics for cases like [this](86d6f1312a/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs (L1C1-L1C28)) and adds doc comments for `parser::AllowPlus`.
This commit is contained in:
Matthias Krüger 2024-07-19 10:48:03 +02:00 committed by GitHub
commit c86e13f330
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 215 additions and 39 deletions

View file

@ -1502,6 +1502,20 @@ pub(crate) struct FnPtrWithGenerics {
pub sugg: Option<FnPtrWithGenericsSugg>,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
parse_misplaced_return_type,
style = "verbose",
applicability = "maybe-incorrect"
)]
pub(crate) struct MisplacedReturnType {
#[suggestion_part(code = " {snippet}")]
pub fn_params_end: Span,
pub snippet: String,
#[suggestion_part(code = "")]
pub ret_ty_span: Span,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(parse_suggestion, applicability = "maybe-incorrect")]
pub(crate) struct FnPtrWithGenericsSugg {
@ -1516,7 +1530,6 @@ pub(crate) struct FnPtrWithGenericsSugg {
pub(crate) struct FnTraitMissingParen {
pub span: Span,
pub machine_applicable: bool,
}
impl Subdiagnostic for FnTraitMissingParen {
@ -1526,16 +1539,11 @@ impl Subdiagnostic for FnTraitMissingParen {
_: &F,
) {
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,
Applicability::MachineApplicable,
);
}
}