Correctly handle unescape warnings
This commit is contained in:
parent
c782767d47
commit
d4a0785464
@ -977,7 +977,11 @@ fn remove_line_splices(s: &str) -> String {
|
||||
.and_then(|s| s.strip_suffix('"'))
|
||||
.unwrap_or_else(|| panic!("expected quoted string, found `{}`", s));
|
||||
let mut res = String::with_capacity(s.len());
|
||||
unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, _| res.push_str(&s[range]));
|
||||
unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, ch| {
|
||||
if ch.is_ok() {
|
||||
res.push_str(&s[range]);
|
||||
}
|
||||
});
|
||||
res
|
||||
}
|
||||
|
||||
|
@ -805,7 +805,11 @@ fn check_newlines(fmtstr: &StrLit) -> bool {
|
||||
let contents = fmtstr.symbol.as_str();
|
||||
|
||||
let mut cb = |r: Range<usize>, c: Result<char, EscapeError>| {
|
||||
let c = c.unwrap();
|
||||
let c = match c {
|
||||
Ok(c) => c,
|
||||
Err(e) if !e.is_fatal() => return,
|
||||
Err(e) => panic!("{:?}", e),
|
||||
};
|
||||
|
||||
if r.end == contents.len() && c == '\n' && !last_was_cr && !has_internal_newline {
|
||||
should_lint = true;
|
||||
|
@ -389,8 +389,10 @@ fn new(cx: &LateContext<'_>, pieces: &Expr<'_>) -> Option<Self> {
|
||||
};
|
||||
|
||||
let mut unescaped = String::with_capacity(inner.len());
|
||||
unescape_literal(inner, mode, &mut |_, ch| {
|
||||
unescaped.push(ch.unwrap());
|
||||
unescape_literal(inner, mode, &mut |_, ch| match ch {
|
||||
Ok(ch) => unescaped.push(ch),
|
||||
Err(e) if !e.is_fatal() => (),
|
||||
Err(e) => panic!("{:?}", e),
|
||||
});
|
||||
|
||||
let mut parts = Vec::new();
|
||||
|
11
tests/ui/crashes/ice-9405.rs
Normal file
11
tests/ui/crashes/ice-9405.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![warn(clippy::useless_format)]
|
||||
#![allow(clippy::print_literal)]
|
||||
|
||||
fn main() {
|
||||
println!(
|
||||
"\
|
||||
|
||||
{}",
|
||||
"multiple skipped lines"
|
||||
);
|
||||
}
|
11
tests/ui/crashes/ice-9405.stderr
Normal file
11
tests/ui/crashes/ice-9405.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
warning: multiple lines skipped by escaped newline
|
||||
--> $DIR/ice-9405.rs:6:10
|
||||
|
|
||||
LL | "/
|
||||
| __________^
|
||||
LL | |
|
||||
LL | | {}",
|
||||
| |____________^ skipping everything up to and including this point
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
Loading…
Reference in New Issue
Block a user