Fix for `needless_return` replaces no-value returns with blank lines
Description
When fixing needless_return, if the return statement has no value, clippy will fix it by replacing it with a blank line. Specifically, the blank line is a series of spaces whose ending matches the start of
Example diff (it's not visible; select the text with the mouse in order to visualize it):
@@ -1072,7 +1072,7 @@ fn gargthink(gs: &mut GlobalState, pas: &mut PcrlibAState, pcs: &mut PcrlibCStat
}
_ => {}
}
- return;
+
} else {
chasethink(false, gs, pas, pcs);
};
@@ -1109,7 +1109,7 @@ fn dragonthink(gs: &mut GlobalState, pas: &mut PcrlibAState, pcs: &mut PcrlibCSt
}
_ => {}
}
- return;
+
} else {
chasethink(false, gs, pas, pcs);
};
Version
rustc 1.64.0-nightly (fe3342816 2022-08-01)
binary: rustc
commit-hash: fe3342816a282949f014caa05ea2e669ff9d3d3c
commit-date: 2022-08-01
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6
Additional Labels
No response
I believe this is because when we make the suggestion, we use only the span of return. The spaces before it are outside of said span, and thus will be untouched by the lint.
Not sure if this would be a trivial fix.
I think it's not exactly trivial, but the two steps are
- Detect if we return unit (get the type, check if unit)
- Get the Span
.lo, go backwards while encountering whitespace, extend the lintSpanto the new.lo
@rustbot claim