Skip to content

Commit f6c13af

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 The .fixed and .stderr were hacked without the `cargo dev bless`, so might be incorrect.
1 parent f2968e2 commit f6c13af

File tree

4 files changed

+114
-84
lines changed

4 files changed

+114
-84
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

+7-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
#![feature(custom_inner_attributes)]
45
#![warn(clippy::uninlined_format_args)]
@@ -10,6 +11,8 @@
1011
clippy::print_literal
1112
)]
1213

14+
extern crate proc_macro_indoc;
15+
1316
macro_rules! no_param_str {
1417
() => {
1518
"{}"
@@ -150,11 +153,10 @@ fn tester(fn_arg: i32) {
150153
);
151154
println!(no_param_str!(), local_i32);
152155

153-
// FIXME: bugs!
154-
// println!(pass_through!("foo={local_i32}"), local_i32 = local_i32);
155-
// println!(pass_through!("foo={}"), local_i32);
156-
// println!(indoc!("foo={}"), local_i32);
157-
// printdoc!("foo={}", local_i32);
156+
println!(pass_through!("foo={}"), local_i32);
157+
println!(pass_through!("foo={a}"), a = local_i32);
158+
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
159+
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
158160
}
159161

160162
fn main() {

tests/ui/uninlined_format_args.rs

+7-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
#![feature(custom_inner_attributes)]
45
#![warn(clippy::uninlined_format_args)]
@@ -10,6 +11,8 @@
1011
clippy::print_literal
1112
)]
1213

14+
extern crate proc_macro_indoc;
15+
1316
macro_rules! no_param_str {
1417
() => {
1518
"{}"
@@ -153,11 +156,10 @@ fn tester(fn_arg: i32) {
153156
);
154157
println!(no_param_str!(), local_i32);
155158

156-
// FIXME: bugs!
157-
// println!(pass_through!("foo={local_i32}"), local_i32 = local_i32);
158-
// println!(pass_through!("foo={}"), local_i32);
159-
// println!(indoc!("foo={}"), local_i32);
160-
// printdoc!("foo={}", local_i32);
159+
println!(pass_through!("foo={}"), local_i32);
160+
println!(pass_through!("foo={a}"), a = local_i32);
161+
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
162+
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
161163
}
162164

163165
fn main() {

0 commit comments

Comments
 (0)