mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 13:43:17 +00:00
887ba0c5a4
FormatArgsExpn: Find comma spans and ignore weird proc macro spans Fixes the following cases: A missing `, 1` from the `expect_fun_call` suggestion: ```rust Some(()).expect(&format!("{x} {}", 1)); ``` ``` warning: use of `expect` followed by a function call --> t.rs:7:14 | 7 | Some(()).expect(&format!("{x} {}", 1)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{x} {}"))` ``` The suggestion removing from the comma in the comment rather than the one after the format string: ```rust println!( "{}", // a comment, with a comma in it x ); ``` ``` warning: variables can be used directly in the `format!` string --> t.rs:9:5 | 9 | / println!( 10 | | "{}", 11 | | // a comment, with a comma in it 12 | | x 13 | | ); | |_____^ | help: change this to | 10 ~ "{x}", 11 ~ // a comment | ``` It also no longer accepts expansions where a format string or argument has a "weird" proc macro span, that is one where the literal/expression it outputs has the span of one of its inputs. Kind of like a `format_args` specific `clippy_utils::is_from_proc_macro`, e.g. `format!(indoc! {" ... "})` changelog: [`expect_fun_call`]: Fix suggestion for `format!` using captured variables changelog: [`print_literal`], [`write_literal`], [`uninlined_format_args`]: Fix suggestion when following a comment including a comma |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |