Correctly handle unescape warnings

This commit is contained in:
Jason Newcomb 2022-08-31 23:24:29 -04:00
parent c782767d47
commit d4a0785464
5 changed files with 36 additions and 4 deletions

View File

@ -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
}

View File

@ -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;

View File

@ -389,8 +389,10 @@ impl FormatString {
};
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();

View File

@ -0,0 +1,11 @@
#![warn(clippy::useless_format)]
#![allow(clippy::print_literal)]
fn main() {
println!(
"\
{}",
"multiple skipped lines"
);
}

View 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