Fix let_and_return bad suggestion
Add a cast to the suggestion when the return expression has adjustments. These adjustments are lost when the suggestion is applied. This is similar to the problem in issue #4437. Closes #5729
This commit is contained in:
@@ -99,7 +99,10 @@ impl<'tcx> LateLintPass<'tcx> for Return {
|
||||
|err| {
|
||||
err.span_label(local.span, "unnecessary `let` binding");
|
||||
|
||||
if let Some(snippet) = snippet_opt(cx, initexpr.span) {
|
||||
if let Some(mut snippet) = snippet_opt(cx, initexpr.span) {
|
||||
if !cx.typeck_results().expr_adjustments(&retexpr).is_empty() {
|
||||
snippet.push_str(" as _");
|
||||
}
|
||||
err.multipart_suggestion(
|
||||
"return the expression directly",
|
||||
vec![
|
||||
|
||||
Reference in New Issue
Block a user