{print,write}-with-newline: do not suggest empty format string

This commit is contained in:
Andy Russell 2020-09-14 14:58:39 -04:00
parent 231444d989
commit 0261e341fd
No known key found for this signature in database
GPG key ID: BE2221033EDBC374
5 changed files with 41 additions and 13 deletions

View file

@ -322,11 +322,15 @@ impl EarlyLintPass for Write {
}
/// Given a format string that ends in a newline and its span, calculates the span of the
/// newline.
/// newline, or the format string itself if the format string consists solely of a newline.
fn newline_span(fmtstr: &StrLit) -> Span {
let sp = fmtstr.span;
let contents = &fmtstr.symbol.as_str();
if *contents == r"\n" {
return sp;
}
let newline_sp_hi = sp.hi()
- match fmtstr.style {
StrStyle::Cooked => BytePos(1),