Auto merge of #9156 - Rqnsom:manual_flatten, r=Alexendoo
fix [`manual_flatten`] help texts order fixes #8948 Whenever suggestion for this lint does not fit in one line, legacy solution has some unexpected/unhandled behavior: lint will then generate two help messages which seem to be shown in the wrong order. The second help message in that case will contain the suggestion. The first help message always refers to a suggestion message, and **it should adapt** depending on the location of the suggestion: - inline suggestion within the error/warning message - suggestion separated into a second help text This is my first contribution here, so I hope I didn't miss anything for creating this PR. changelog: fix [`manual_flatten`] help texts order
This commit is contained in:
commit
f78292a4ad
4 changed files with 59 additions and 4 deletions
|
|
@ -51,22 +51,32 @@ pub(super) fn check<'tcx>(
|
|||
_ => ""
|
||||
};
|
||||
|
||||
let sugg = format!("{arg_snippet}{copied}.flatten()");
|
||||
|
||||
// If suggestion is not a one-liner, it won't be shown inline within the error message. In that case,
|
||||
// it will be shown in the extra `help` message at the end, which is why the first `help_msg` needs
|
||||
// to refer to the correct relative position of the suggestion.
|
||||
let help_msg = if sugg.contains('\n') {
|
||||
"remove the `if let` statement in the for loop and then..."
|
||||
} else {
|
||||
"...and remove the `if let` statement in the for loop"
|
||||
};
|
||||
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
MANUAL_FLATTEN,
|
||||
span,
|
||||
&msg,
|
||||
|diag| {
|
||||
let sugg = format!("{}{}.flatten()", arg_snippet, copied);
|
||||
diag.span_suggestion(
|
||||
arg.span,
|
||||
"try",
|
||||
sugg,
|
||||
Applicability::MaybeIncorrect,
|
||||
applicability,
|
||||
);
|
||||
diag.span_help(
|
||||
inner_expr.span,
|
||||
"...and remove the `if let` statement in the for loop",
|
||||
help_msg,
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue