Skip to content

Commit

Permalink
rm indoc, ignore expanded macros
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Sep 25, 2022
1 parent ba320c7 commit 97a2f80
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 90 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ clap = { version = "3.1", features = ["derive"] }
clippy_utils = { path = "clippy_utils" }
derive-new = "0.5"
if_chain = "1.0"
indoc = "1.0"
itertools = "0.10.1"
quote = "1.0"
serde = { version = "1.0.125", features = ["derive"] }
Expand Down
22 changes: 13 additions & 9 deletions clippy_lints/src/format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
}

fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_site: Span) {
if args.format_string.span.from_expansion() {
return;
}

let mut fixes = Vec::new();
// If any of the arguments are referenced by an index number,
// and that argument is not a simple variable and cannot be inlined,
Expand Down Expand Up @@ -204,17 +208,17 @@ fn check_one_arg(cx: &LateContext<'_>, param: &FormatParam<'_>, fixes: &mut Vec<
&& let [segment] = segments
{
let replacement = match param.usage {
FormatParamUsage::Argument => segment.ident.name.to_string(),
FormatParamUsage::Argument => segment.ident.name.to_string(),
FormatParamUsage::Width => format!("{}$", segment.ident.name),
FormatParamUsage::Precision => format!(".{}$", segment.ident.name),
};
fixes.push((param.span, replacement));
let arg_span = expand_past_previous_comma(cx, *span);
fixes.push((arg_span, String::new()));
true // successful inlining, continue checking
} else {
// if we can't inline a numbered argument, we can't continue
param.kind != Numbered
};
fixes.push((param.span, replacement));
let arg_span = expand_past_previous_comma(cx, *span);
fixes.push((arg_span, String::new()));
true // successful inlining, continue checking
} else {
// if we can't inline a numbered argument, we can't continue
param.kind != Numbered
}
}

Expand Down
3 changes: 0 additions & 3 deletions tests/compile-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static TEST_DEPENDENCIES: &[&str] = &[
"tokio",
"parking_lot",
"rustc_semver",
"indoc",
];

// Test dependencies may need an `extern crate` here to ensure that they show up
Expand All @@ -53,8 +52,6 @@ extern crate futures;
#[allow(unused_extern_crates)]
extern crate if_chain;
#[allow(unused_extern_crates)]
extern crate indoc;
#[allow(unused_extern_crates)]
extern crate itertools;
#[allow(unused_extern_crates)]
extern crate parking_lot;
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/uninlined_format_args.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#![warn(clippy::uninlined_format_args)]
#![feature(custom_inner_attributes)]

use indoc::{indoc, printdoc};

macro_rules! no_param_str {
() => {
"{}"
Expand Down Expand Up @@ -130,8 +128,9 @@ fn tester(fn_arg: i32) {
"val='{local_i32
}'"
);
println!(no_param_str!(), local_i32);

// FIXME: bugs!
// println!(no_param_str!(), local_i32);
// println!(pass_through!("foo={local_i32}"), local_i32 = local_i32);
// println!(pass_through!("foo={}"), local_i32);
// println!(indoc!("foo={}"), local_i32);
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/uninlined_format_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#![warn(clippy::uninlined_format_args)]
#![feature(custom_inner_attributes)]

use indoc::{indoc, printdoc};

macro_rules! no_param_str {
() => {
"{}"
Expand Down Expand Up @@ -133,8 +131,9 @@ fn tester(fn_arg: i32) {
"val='{local_i32
}'"
);
println!(no_param_str!(), local_i32);

// FIXME: bugs!
// println!(no_param_str!(), local_i32);
// println!(pass_through!("foo={local_i32}"), local_i32 = local_i32);
// println!(pass_through!("foo={}"), local_i32);
// println!(indoc!("foo={}"), local_i32);
Expand Down
Loading

0 comments on commit 97a2f80

Please sign in to comment.