forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#8253 - Alexendoo:print-in-fmt, r=camsteffen
Add `print_in_format_impl` lint changelog: new lint: [`print_in_format_impl`] Lints the use of `print`-like macros in manual `Display`/`Debug` impls. I feel like I make this mistake every time I write one 😄 r? `@camsteffen`
- Loading branch information
Showing
9 changed files
with
228 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#![allow(unused, clippy::print_literal, clippy::write_literal)] | ||
#![warn(clippy::print_in_format_impl)] | ||
use std::fmt::{Debug, Display, Error, Formatter}; | ||
|
||
macro_rules! indirect { | ||
() => {{ println!() }}; | ||
} | ||
|
||
macro_rules! nested { | ||
($($tt:tt)*) => { | ||
$($tt)* | ||
}; | ||
} | ||
|
||
struct Foo; | ||
impl Debug for Foo { | ||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { | ||
static WORKS_WITH_NESTED_ITEMS: bool = true; | ||
|
||
print!("{}", 1); | ||
println!("{}", 2); | ||
eprint!("{}", 3); | ||
eprintln!("{}", 4); | ||
nested! { | ||
println!("nested"); | ||
}; | ||
|
||
write!(f, "{}", 5); | ||
writeln!(f, "{}", 6); | ||
indirect!(); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl Display for Foo { | ||
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { | ||
print!("Display"); | ||
write!(f, "Display"); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
struct UnnamedFormatter; | ||
impl Debug for UnnamedFormatter { | ||
fn fmt(&self, _: &mut Formatter) -> Result<(), Error> { | ||
println!("UnnamedFormatter"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
print!("outside fmt"); | ||
println!("outside fmt"); | ||
eprint!("outside fmt"); | ||
eprintln!("outside fmt"); | ||
} |
Oops, something went wrong.