Skip to content

Commit 7c3ed8d

Browse files
committed
Add failing uninlined-format-args tests
All these tests are currently failing (generating uncompilable code). * Implement a simplified `indoc!` proc macro * added a `pass_through!(...)` macro test An edge case with format arguments being wrapped in parentesis The .fixed and .stderr were hacked without the `cargo dev bless`, so might be incorrect.
1 parent 887ba0c commit 7c3ed8d

File tree

4 files changed

+184
-76
lines changed

4 files changed

+184
-76
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// compile-flags: --emit=link
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::{TokenStream, TokenTree};
9+
use std::str::FromStr;
10+
11+
/// This code was adapted from the indoc crate
12+
#[proc_macro]
13+
pub fn simple_indoc(input: TokenStream) -> TokenStream {
14+
let token = input.into_iter().next().unwrap();
15+
let new_token = TokenStream::from_str(&token.to_string())
16+
.unwrap()
17+
.into_iter()
18+
.next()
19+
.unwrap();
20+
21+
if let TokenTree::Literal(mut lit) = new_token {
22+
lit.set_span(token.span());
23+
return TokenStream::from(TokenTree::Literal(lit));
24+
}
25+
panic!();
26+
}

tests/ui/uninlined_format_args.fixed

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
// aux-build:proc_macro_with_span.rs
22
// run-rustfix
3+
// aux-build:proc_macro_indoc.rs
4+
35
#![feature(custom_inner_attributes)]
46
#![warn(clippy::uninlined_format_args)]
57
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
6-
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
8+
#![allow(
9+
clippy::double_parens,
10+
clippy::eq_op,
11+
clippy::format_in_format_args,
12+
clippy::print_literal
13+
)]
714

15+
extern crate proc_macro_indoc;
816
extern crate proc_macro_with_span;
917
use proc_macro_with_span::with_span;
1018

@@ -14,6 +22,12 @@ macro_rules! no_param_str {
1422
};
1523
}
1624

25+
macro_rules! pass_through {
26+
($expr:expr) => {
27+
$expr
28+
};
29+
}
30+
1731
macro_rules! my_println {
1832
($($args:tt),*) => {{
1933
println!($($args),*)
@@ -123,6 +137,10 @@ fn tester(fn_arg: i32) {
123137
println!("{}", format!("{local_i32}"));
124138
my_println!("{}", local_i32);
125139
my_println_args!("{}", local_i32);
140+
println!("{local_i32}");
141+
#[rustfmt::skip]
142+
println!("{local_i32}");
143+
println!("{local_i32:width$.prec$}");
126144

127145
// these should NOT be modified by the lint
128146
println!(concat!("nope ", "{}"), local_i32);
@@ -145,6 +163,11 @@ fn tester(fn_arg: i32) {
145163

146164
println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
147165
println!("{}", with_span!(span val));
166+
167+
println!(pass_through!("foo={}"), local_i32);
168+
println!(pass_through!("foo={a}"), a = local_i32);
169+
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
170+
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
148171
}
149172

150173
fn main() {

tests/ui/uninlined_format_args.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
// aux-build:proc_macro_with_span.rs
22
// run-rustfix
3+
// aux-build:proc_macro_indoc.rs
4+
35
#![feature(custom_inner_attributes)]
46
#![warn(clippy::uninlined_format_args)]
57
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
6-
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
8+
#![allow(
9+
clippy::double_parens,
10+
clippy::eq_op,
11+
clippy::format_in_format_args,
12+
clippy::print_literal
13+
)]
714

15+
extern crate proc_macro_indoc;
816
extern crate proc_macro_with_span;
917
use proc_macro_with_span::with_span;
1018

@@ -14,6 +22,12 @@ macro_rules! no_param_str {
1422
};
1523
}
1624

25+
macro_rules! pass_through {
26+
($expr:expr) => {
27+
$expr
28+
};
29+
}
30+
1731
macro_rules! my_println {
1832
($($args:tt),*) => {{
1933
println!($($args),*)
@@ -126,6 +140,10 @@ fn tester(fn_arg: i32) {
126140
println!("{}", format!("{}", local_i32));
127141
my_println!("{}", local_i32);
128142
my_println_args!("{}", local_i32);
143+
println!("{}", (local_i32));
144+
#[rustfmt::skip]
145+
println!("{}", ((local_i32)));
146+
println!("{0:1$.2$}", (local_i32), (width), (prec));
129147

130148
// these should NOT be modified by the lint
131149
println!(concat!("nope ", "{}"), local_i32);
@@ -150,6 +168,11 @@ fn tester(fn_arg: i32) {
150168

151169
println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
152170
println!("{}", with_span!(span val));
171+
172+
println!(pass_through!("foo={}"), local_i32);
173+
println!(pass_through!("foo={a}"), a = local_i32);
174+
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
175+
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
153176
}
154177

155178
fn main() {

0 commit comments

Comments
 (0)