Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions clippy_lints/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::borrow::Cow;
use std::ops::Range;

use crate::utils::{snippet_with_applicability, span_lint, span_lint_and_sugg, span_lint_and_then};
use rustc_ast::ast::{Expr, ExprKind, Item, ItemKind, MacCall, StrLit, StrStyle};
use if_chain::if_chain;
use rustc_ast::ast::{Expr, ExprKind, Item, ItemKind, LitKind, MacCall, StrLit, StrStyle};
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_errors::Applicability;
Expand Down Expand Up @@ -442,7 +443,7 @@ impl Write {
return (Some(fmtstr), None);
};
match &token_expr.kind {
ExprKind::Lit(_) => {
ExprKind::Lit(lit) if !matches!(lit.kind, LitKind::Int(..) | LitKind::Float(..)) => {
let mut all_simple = true;
let mut seen = false;
for arg in &args {
Expand All @@ -462,8 +463,11 @@ impl Write {
idx += 1;
},
ExprKind::Assign(lhs, rhs, _) => {
if let ExprKind::Lit(_) = rhs.kind {
if let ExprKind::Path(_, p) = &lhs.kind {
if_chain! {
if let ExprKind::Lit(ref lit) = rhs.kind;
if !matches!(lit.kind, LitKind::Int(..) | LitKind::Float(..));
if let ExprKind::Path(_, p) = &lhs.kind;
then {
let mut all_simple = true;
let mut seen = false;
for arg in &args {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/crashes/ice-3891.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error: invalid suffix `x` for integer literal
error: invalid suffix `x` for number literal
--> $DIR/ice-3891.rs:2:5
|
LL | 1x;
| ^^ invalid suffix `x`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
= help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this change? This is a rustc lint and should be unaffected by a Clippy PR. (rebase gone wrong?)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same thing... but since CI is passing... I guess this is the lack of a rebase? (master has this change already) Like this change will go away when rebased over master. Though that does make me wonder how git managed to not treat this as a conflict... I guess because the change is exactly the same.


error: aborting due to previous error

6 changes: 3 additions & 3 deletions tests/ui/print_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ fn main() {
println!("{bar:8} {foo:>8}", foo = "hello", bar = "world");
println!("{number:>width$}", number = 1, width = 6);
println!("{number:>0width$}", number = 1, width = 6);
println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
println!("10 / 4 is {}", 2.5);
println!("2 + 1 = {}", 3);

// these should throw warnings
println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
print!("Hello {}", "world");
println!("Hello {} {}", world, "world");
println!("Hello {}", "world");
println!("10 / 4 is {}", 2.5);
println!("2 + 1 = {}", 3);

// positional args don't change the fact
// that we're using a literal -- this should
Expand Down
30 changes: 6 additions & 24 deletions tests/ui/print_literal.stderr
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
error: literal with an empty format string
--> $DIR/print_literal.rs:22:71
|
LL | println!("{} of {:b} people know binary, the other half doesn't", 1, 2);
| ^
|
= note: `-D clippy::print-literal` implied by `-D warnings`

error: literal with an empty format string
--> $DIR/print_literal.rs:23:24
--> $DIR/print_literal.rs:25:24
|
LL | print!("Hello {}", "world");
| ^^^^^^^
|
= note: `-D clippy::print-literal` implied by `-D warnings`

error: literal with an empty format string
--> $DIR/print_literal.rs:24:36
--> $DIR/print_literal.rs:26:36
|
LL | println!("Hello {} {}", world, "world");
| ^^^^^^^

error: literal with an empty format string
--> $DIR/print_literal.rs:25:26
--> $DIR/print_literal.rs:27:26
|
LL | println!("Hello {}", "world");
| ^^^^^^^

error: literal with an empty format string
--> $DIR/print_literal.rs:26:30
|
LL | println!("10 / 4 is {}", 2.5);
| ^^^

error: literal with an empty format string
--> $DIR/print_literal.rs:27:28
|
LL | println!("2 + 1 = {}", 3);
| ^

error: literal with an empty format string
--> $DIR/print_literal.rs:32:25
|
Expand Down Expand Up @@ -84,5 +66,5 @@ error: literal with an empty format string
LL | println!("{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^

error: aborting due to 14 previous errors
error: aborting due to 11 previous errors

6 changes: 3 additions & 3 deletions tests/ui/write_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ fn main() {
writeln!(&mut v, "{bar:8} {foo:>8}", foo = "hello", bar = "world");
writeln!(&mut v, "{number:>width$}", number = 1, width = 6);
writeln!(&mut v, "{number:>0width$}", number = 1, width = 6);
writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
writeln!(&mut v, "10 / 4 is {}", 2.5);
writeln!(&mut v, "2 + 1 = {}", 3);

// these should throw warnings
writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
write!(&mut v, "Hello {}", "world");
writeln!(&mut v, "Hello {} {}", world, "world");
writeln!(&mut v, "Hello {}", "world");
writeln!(&mut v, "10 / 4 is {}", 2.5);
writeln!(&mut v, "2 + 1 = {}", 3);

// positional args don't change the fact
// that we're using a literal -- this should
Expand Down
30 changes: 6 additions & 24 deletions tests/ui/write_literal.stderr
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
error: literal with an empty format string
--> $DIR/write_literal.rs:27:79
|
LL | writeln!(&mut v, "{} of {:b} people know binary, the other half doesn't", 1, 2);
| ^
|
= note: `-D clippy::write-literal` implied by `-D warnings`

error: literal with an empty format string
--> $DIR/write_literal.rs:28:32
--> $DIR/write_literal.rs:30:32
|
LL | write!(&mut v, "Hello {}", "world");
| ^^^^^^^
|
= note: `-D clippy::write-literal` implied by `-D warnings`

error: literal with an empty format string
--> $DIR/write_literal.rs:29:44
--> $DIR/write_literal.rs:31:44
|
LL | writeln!(&mut v, "Hello {} {}", world, "world");
| ^^^^^^^

error: literal with an empty format string
--> $DIR/write_literal.rs:30:34
--> $DIR/write_literal.rs:32:34
|
LL | writeln!(&mut v, "Hello {}", "world");
| ^^^^^^^

error: literal with an empty format string
--> $DIR/write_literal.rs:31:38
|
LL | writeln!(&mut v, "10 / 4 is {}", 2.5);
| ^^^

error: literal with an empty format string
--> $DIR/write_literal.rs:32:36
|
LL | writeln!(&mut v, "2 + 1 = {}", 3);
| ^

error: literal with an empty format string
--> $DIR/write_literal.rs:37:33
|
Expand Down Expand Up @@ -84,5 +66,5 @@ error: literal with an empty format string
LL | writeln!(&mut v, "{bar} {foo}", foo = "hello", bar = "world");
| ^^^^^^^

error: aborting due to 14 previous errors
error: aborting due to 11 previous errors