fix span calculation for non-ascii in needless_return
This commit is contained in:
parent
660b058ba2
commit
d3f8f3e9d7
@ -465,8 +465,8 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
|
||||
// Go backwards while encountering whitespace and extend the given Span to that point.
|
||||
fn extend_span_to_previous_non_ws(cx: &LateContext<'_>, sp: Span) -> Span {
|
||||
if let Ok(prev_source) = cx.sess().source_map().span_to_prev_source(sp) {
|
||||
let ws = [' ', '\t', '\n'];
|
||||
if let Some(non_ws_pos) = prev_source.rfind(|c| !ws.contains(&c)) {
|
||||
let ws = [b' ', b'\t', b'\n'];
|
||||
if let Some(non_ws_pos) = prev_source.bytes().rposition(|c| !ws.contains(&c)) {
|
||||
let len = prev_source.len() - non_ws_pos - 1;
|
||||
return sp.with_lo(sp.lo() - BytePos::from_usize(len));
|
||||
}
|
||||
|
7
tests/ui/crashes/ice-12491.fixed
Normal file
7
tests/ui/crashes/ice-12491.fixed
Normal file
@ -0,0 +1,7 @@
|
||||
#![warn(clippy::needless_return)]
|
||||
|
||||
fn main() {
|
||||
if (true) {
|
||||
// anything一些中文
|
||||
}
|
||||
}
|
8
tests/ui/crashes/ice-12491.rs
Normal file
8
tests/ui/crashes/ice-12491.rs
Normal file
@ -0,0 +1,8 @@
|
||||
#![warn(clippy::needless_return)]
|
||||
|
||||
fn main() {
|
||||
if (true) {
|
||||
// anything一些中文
|
||||
return;
|
||||
}
|
||||
}
|
19
tests/ui/crashes/ice-12491.stderr
Normal file
19
tests/ui/crashes/ice-12491.stderr
Normal file
@ -0,0 +1,19 @@
|
||||
error: unneeded `return` statement
|
||||
--> tests/ui/crashes/ice-12491.rs:5:24
|
||||
|
|
||||
LL | // anything一些中文
|
||||
| ____________________________^
|
||||
LL | | return;
|
||||
| |______________^
|
||||
|
|
||||
= note: `-D clippy::needless-return` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::needless_return)]`
|
||||
help: remove `return`
|
||||
|
|
||||
LL - // anything一些中文
|
||||
LL - return;
|
||||
LL + // anything一些中文
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user