Skip to content

Commit 7d090b1

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 extra parens test `println!("{}", (local_i32))` * added a `pass_through!(...)` macro test The .fixed and .stderr were hacked without the `cargo dev bless`, so might be incorrect.
1 parent e8c1b54 commit 7d090b1

File tree

4 files changed

+164
-82
lines changed

4 files changed

+164
-82
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

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-rustfix
2+
// aux-build:proc_macro_indoc.rs
23

34
#![allow(clippy::eq_op)]
45
#![allow(clippy::format_in_format_args)]
@@ -8,6 +9,8 @@
89
#![warn(clippy::uninlined_format_args)]
910
#![feature(custom_inner_attributes)]
1011

12+
extern crate proc_macro_indoc;
13+
1114
macro_rules! no_param_str {
1215
() => {
1316
"{}"
@@ -129,6 +132,10 @@ fn tester(fn_arg: i32) {
129132
println!("{}", format!("{local_i32}"));
130133
my_println!("{}", local_i32);
131134
my_println_args!("{}", local_i32);
135+
println!("{local_i32}");
136+
#[rustfmt::skip]
137+
println!("{local_i32}");
138+
println!("{local_i32:width$.prec$}");
132139

133140
// these should NOT be modified by the lint
134141
println!(concat!("nope ", "{}"), local_i32);
@@ -144,11 +151,10 @@ fn tester(fn_arg: i32) {
144151
);
145152
println!(no_param_str!(), local_i32);
146153

147-
// FIXME: bugs!
148-
// println!(pass_through!("foo={local_i32}"), local_i32 = local_i32);
149-
// println!(pass_through!("foo={}"), local_i32);
150-
// println!(indoc!("foo={}"), local_i32);
151-
// printdoc!("foo={}", local_i32);
154+
println!(pass_through!("foo={}"), local_i32);
155+
println!(pass_through!("foo={a}"), a = local_i32);
156+
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
157+
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
152158
}
153159

154160
fn main() {

tests/ui/uninlined_format_args.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-rustfix
2+
// aux-build:proc_macro_indoc.rs
23

34
#![allow(clippy::eq_op)]
45
#![allow(clippy::format_in_format_args)]
@@ -8,6 +9,8 @@
89
#![warn(clippy::uninlined_format_args)]
910
#![feature(custom_inner_attributes)]
1011

12+
extern crate proc_macro_indoc;
13+
1114
macro_rules! no_param_str {
1215
() => {
1316
"{}"
@@ -132,6 +135,10 @@ fn tester(fn_arg: i32) {
132135
println!("{}", format!("{}", local_i32));
133136
my_println!("{}", local_i32);
134137
my_println_args!("{}", local_i32);
138+
println!("{}", (local_i32));
139+
#[rustfmt::skip]
140+
println!("{}", ((local_i32)));
141+
println!("{0:1$.2$}", (local_i32), (width), (prec));
135142

136143
// these should NOT be modified by the lint
137144
println!(concat!("nope ", "{}"), local_i32);
@@ -147,11 +154,10 @@ fn tester(fn_arg: i32) {
147154
);
148155
println!(no_param_str!(), local_i32);
149156

150-
// FIXME: bugs!
151-
// println!(pass_through!("foo={local_i32}"), local_i32 = local_i32);
152-
// println!(pass_through!("foo={}"), local_i32);
153-
// println!(indoc!("foo={}"), local_i32);
154-
// printdoc!("foo={}", local_i32);
157+
println!(pass_through!("foo={}"), local_i32);
158+
println!(pass_through!("foo={a}"), a = local_i32);
159+
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
160+
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
155161
}
156162

157163
fn main() {

0 commit comments

Comments
 (0)