Skip to content

Commit 2b30ce0

Browse files
committed
Merge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyup
2 parents db490d0 + 8f1ebdd commit 2b30ce0

File tree

6 files changed

+20
-69
lines changed

6 files changed

+20
-69
lines changed

src/tools/clippy/clippy_lints/src/attrs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
357357
"wildcard_imports"
358358
| "enum_glob_use"
359359
| "redundant_pub_crate"
360-
| "macro_use_imports",
360+
| "macro_use_imports"
361+
| "unsafe_removed_from_name",
361362
)
362363
})
363364
{

src/tools/clippy/clippy_lints/src/format_args.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use if_chain::if_chain;
88
use itertools::Itertools;
99
use rustc_errors::Applicability;
1010
use rustc_hir::{Expr, ExprKind, HirId, QPath};
11-
use rustc_lint::{LateContext, LateLintPass};
11+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::ty::adjustment::{Adjust, Adjustment};
1313
use rustc_middle::ty::Ty;
1414
use rustc_semver::RustcVersion;
@@ -173,17 +173,10 @@ fn check_uninlined_args(cx: &LateContext<'_>, args: &FormatArgsExpn<'_>, call_si
173173
return;
174174
}
175175

176-
// FIXME: Properly ignore a rare case where the format string is wrapped in a macro.
177-
// Example: `format!(indoc!("{}"), foo);`
178-
// If inlined, they will cause a compilation error:
179-
// > to avoid ambiguity, `format_args!` cannot capture variables
180-
// > when the format string is expanded from a macro
181-
// @Alexendoo explanation:
182-
// > indoc! is a proc macro that is producing a string literal with its span
183-
// > set to its input it's not marked as from expansion, and since it's compatible
184-
// > tokenization wise clippy_utils::is_from_proc_macro wouldn't catch it either
185-
// This might be a relatively expensive test, so do it only we are ready to replace.
186-
// See more examples in tests/ui/uninlined_format_args.rs
176+
// Temporarily ignore multiline spans: https://github.com/rust-lang/rust/pull/102729#discussion_r988704308
177+
if fixes.iter().any(|(span, _)| cx.sess().source_map().is_multiline(*span)) {
178+
return;
179+
}
187180

188181
span_lint_and_then(
189182
cx,

src/tools/clippy/clippy_utils/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl FormatString {
414414

415415
struct FormatArgsValues<'tcx> {
416416
/// Values passed after the format string and implicit captures. `[1, z + 2, x]` for
417-
/// `format!("{x} {} {y}", 1, z + 2)`.
417+
/// `format!("{x} {} {}", 1, z + 2)`.
418418
value_args: Vec<&'tcx Expr<'tcx>>,
419419
/// Maps an `rt::v1::Argument::position` or an `rt::v1::Count::Param` to its index in
420420
/// `value_args`

src/tools/clippy/tests/ui/uninlined_format_args.fixed

+8-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ fn tester(fn_arg: i32) {
4444
println!("val='{local_i32}'"); // space+tab
4545
println!("val='{local_i32}'"); // tab+space
4646
println!(
47-
"val='{local_i32}'"
47+
"val='{
48+
}'",
49+
local_i32
4850
);
4951
println!("{local_i32}");
5052
println!("{fn_arg}");
@@ -108,7 +110,8 @@ fn tester(fn_arg: i32) {
108110
println!("{local_f64:width$.prec$}");
109111
println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
110112
println!(
111-
"{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}",
113+
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
114+
local_i32, width, prec,
112115
);
113116
println!(
114117
"{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$} {3}",
@@ -139,7 +142,9 @@ fn tester(fn_arg: i32) {
139142
println!(no_param_str!(), local_i32);
140143

141144
println!(
142-
"{val}",
145+
"{}",
146+
// comment with a comma , in it
147+
val,
143148
);
144149
println!("{val}");
145150

src/tools/clippy/tests/ui/uninlined_format_args.stderr

+1-52
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,6 @@ LL - println!("val='{ }'", local_i32); // tab+space
5959
LL + println!("val='{local_i32}'"); // tab+space
6060
|
6161

62-
error: variables can be used directly in the `format!` string
63-
--> $DIR/uninlined_format_args.rs:46:5
64-
|
65-
LL | / println!(
66-
LL | | "val='{
67-
LL | | }'",
68-
LL | | local_i32
69-
LL | | );
70-
| |_____^
71-
|
72-
help: change this to
73-
|
74-
LL - "val='{
75-
LL + "val='{local_i32}'"
76-
|
77-
7862
error: variables can be used directly in the `format!` string
7963
--> $DIR/uninlined_format_args.rs:51:5
8064
|
@@ -783,25 +767,6 @@ LL - println!("{:1$.2$} {0} {1} {2}", local_f64, width, prec);
783767
LL + println!("{local_f64:width$.prec$} {local_f64} {width} {prec}");
784768
|
785769

786-
error: variables can be used directly in the `format!` string
787-
--> $DIR/uninlined_format_args.rs:112:5
788-
|
789-
LL | / println!(
790-
LL | | "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
791-
LL | | local_i32, width, prec,
792-
LL | | );
793-
| |_____^
794-
|
795-
help: change this to
796-
|
797-
LL ~ "{local_i32:width$.prec$} {local_i32:prec$.width$} {width:local_i32$.prec$} {width:prec$.local_i32$} {prec:local_i32$.width$} {prec:width$.local_i32$}", width, prec,
798-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
799-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
800-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
801-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}", width, prec,
802-
LL ~ "{0:1$.2$} {0:2$.1$} {1:0$.2$} {1:2$.0$} {2:0$.1$} {2:1$.0$}",
803-
|
804-
805770
error: variables can be used directly in the `format!` string
806771
--> $DIR/uninlined_format_args.rs:123:5
807772
|
@@ -850,22 +815,6 @@ LL - println!("{}", format!("{}", local_i32));
850815
LL + println!("{}", format!("{local_i32}"));
851816
|
852817

853-
error: variables can be used directly in the `format!` string
854-
--> $DIR/uninlined_format_args.rs:144:5
855-
|
856-
LL | / println!(
857-
LL | | "{}",
858-
LL | | // comment with a comma , in it
859-
LL | | val,
860-
LL | | );
861-
| |_____^
862-
|
863-
help: change this to
864-
|
865-
LL - "{}",
866-
LL + "{val}",
867-
|
868-
869818
error: variables can be used directly in the `format!` string
870819
--> $DIR/uninlined_format_args.rs:149:5
871820
|
@@ -890,5 +839,5 @@ LL - println!("expand='{}'", local_i32);
890839
LL + println!("expand='{local_i32}'");
891840
|
892841

893-
error: aborting due to 73 previous errors
842+
error: aborting due to 70 previous errors
894843

src/tools/clippy/tests/ui/unsafe_removed_from_name.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ use mod_with_some_unsafe_things::Unsafe as LieAboutModSafety;
2424
use mod_with_some_unsafe_things::Safe as IPromiseItsSafeThisTime;
2525
use mod_with_some_unsafe_things::Unsafe as SuperUnsafeModThing;
2626

27+
#[allow(clippy::unsafe_removed_from_name)]
28+
use mod_with_some_unsafe_things::Unsafe as SuperSafeThing;
29+
2730
fn main() {}

0 commit comments

Comments
 (0)