about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-09-14 15:58:21 +0000
committerbors <bors@rust-lang.org>2022-09-14 15:58:21 +0000
commit2ddbc86bef837b1072159c020c35940ce52ae696 (patch)
tree72e4ae3bf5c333d05e259deae907b63f0e5d6436 /src
parent9c9aa928980ca651a75801b90d814a8fb598ed0a (diff)
parent6fc6d87fd069470893b6a539a46fa1e2f10ae906 (diff)
Auto merge of #8518 - Alexendoo:write-late-pass, r=flip1995
Migrate write.rs to a late pass

changelog: Migrates write.rs from a pre expansion pass to a late pass
changelog: [`positional_named_format_parameters`] is renamed in favour of the rustc lint `named_arguments_used_positionally`

- Macros are now identified by diagnostic items, so will no longer lint user defined macros named, e.g. a custom `print!`
- `print_literal`/`write_literal` no longer lint no longer lint literals that come from macro expansions, e.g. `env!("FOO")`
- `print_with_newline`/`write_with_newline` no longer lint strings with any internal `\r` or `\n`s

~~A false negative, `print_literal`/`write_literal` don't lint format strings that produce `FormatSpec`s, e.g. ones containing pretty print/width/align specifiers~~

Suggestion changes:
- ~~`print_literal`/`write_literal` no longer have suggestions, as the spans for the `{}`s were not easily obtainable~~
-  `print_with_newline`/`write_with_newline` has a better suggestion for a sole literal newline, but no longer has suggestions for len > 1 strings that end in a literal newline
- ~~`use_debug` spans are less precise, now point to the whole format string~~

The diff for write.rs is pretty unwieldy, other than for the `declare_clippy_lint!`s I think you'd be better off viewing it as a brand new file rather than looking at the diff, as it's mostly written from scratch

cc #6610, fixes #5721, fixes #7195, fixes #8615
Diffstat (limited to 'src')
-rw-r--r--src/docs.rs1
-rw-r--r--src/docs/positional_named_format_parameters.txt15
-rw-r--r--src/docs/print_literal.txt4
-rw-r--r--src/docs/print_stderr.txt8
-rw-r--r--src/docs/print_stdout.txt8
-rw-r--r--src/docs/write_literal.txt4
6 files changed, 2 insertions, 38 deletions
diff --git a/src/docs.rs b/src/docs.rs
index f3a5048e7fa..9f6f1fb4727 100644
--- a/src/docs.rs
+++ b/src/docs.rs
@@ -391,7 +391,6 @@ docs! {
     "partialeq_to_none",
     "path_buf_push_overwrite",
     "pattern_type_mismatch",
-    "positional_named_format_parameters",
     "possible_missing_comma",
     "precedence",
     "print_in_format_impl",
diff --git a/src/docs/positional_named_format_parameters.txt b/src/docs/positional_named_format_parameters.txt
deleted file mode 100644
index e391d240667..00000000000
--- a/src/docs/positional_named_format_parameters.txt
+++ /dev/null
@@ -1,15 +0,0 @@
-### What it does
-This lint warns when a named parameter in a format string is used as a positional one.
-
-### Why is this bad?
-It may be confused for an assignment and obfuscates which parameter is being used.
-
-### Example
-```
-println!("{}", x = 10);
-```
-
-Use instead:
-```
-println!("{x}", x = 10);
-```
\ No newline at end of file
diff --git a/src/docs/print_literal.txt b/src/docs/print_literal.txt
index 160073414f9..a6252a68780 100644
--- a/src/docs/print_literal.txt
+++ b/src/docs/print_literal.txt
@@ -6,10 +6,6 @@ Using literals as `println!` args is inefficient
 (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
 (i.e., just put the literal in the format string)
 
-### Known problems
-Will also warn with macro calls as arguments that expand to literals
--- e.g., `println!("{}", env!("FOO"))`.
-
 ### Example
 ```
 println!("{}", "foo");
diff --git a/src/docs/print_stderr.txt b/src/docs/print_stderr.txt
index fc14511cd6a..9c6edeeef12 100644
--- a/src/docs/print_stderr.txt
+++ b/src/docs/print_stderr.txt
@@ -7,13 +7,7 @@ People often print on *stderr* while debugging an
 application and might forget to remove those prints afterward.
 
 ### Known problems
-* Only catches `eprint!` and `eprintln!` calls.
-* The lint level is unaffected by crate attributes. The level can still
-  be set for functions, modules and other items. To change the level for
-  the entire crate, please use command line flags. More information and a
-  configuration example can be found in [clippy#6610].
-
-[clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558
+Only catches `eprint!` and `eprintln!` calls.
 
 ### Example
 ```
diff --git a/src/docs/print_stdout.txt b/src/docs/print_stdout.txt
index 6c9a4b98e1e..d2cbd811d1b 100644
--- a/src/docs/print_stdout.txt
+++ b/src/docs/print_stdout.txt
@@ -7,13 +7,7 @@ People often print on *stdout* while debugging an
 application and might forget to remove those prints afterward.
 
 ### Known problems
-* Only catches `print!` and `println!` calls.
-* The lint level is unaffected by crate attributes. The level can still
-  be set for functions, modules and other items. To change the level for
-  the entire crate, please use command line flags. More information and a
-  configuration example can be found in [clippy#6610].
-
-[clippy#6610]: https://github.com/rust-lang/rust-clippy/issues/6610#issuecomment-977120558
+Only catches `print!` and `println!` calls.
 
 ### Example
 ```
diff --git a/src/docs/write_literal.txt b/src/docs/write_literal.txt
index 9c41a48f9f7..a7a884d0871 100644
--- a/src/docs/write_literal.txt
+++ b/src/docs/write_literal.txt
@@ -6,10 +6,6 @@ Using literals as `writeln!` args is inefficient
 (c.f., https://github.com/matthiaskrgr/rust-str-bench) and unnecessary
 (i.e., just put the literal in the format string)
 
-### Known problems
-Will also warn with macro calls as arguments that expand to literals
--- e.g., `writeln!(buf, "{}", env!("FOO"))`.
-
 ### Example
 ```
 writeln!(buf, "{}", "foo");