Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/ui/auxiliary/proc_macro_indoc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// compile-flags: --emit=link
// no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;

use proc_macro::{TokenStream, TokenTree};
use std::str::FromStr;

/// This code was adapted from the indoc crate
#[proc_macro]
pub fn simple_indoc(input: TokenStream) -> TokenStream {
let token = input.into_iter().next().unwrap();
let new_token = TokenStream::from_str(&token.to_string())
.unwrap()
.into_iter()
.next()
.unwrap();

if let TokenTree::Literal(mut lit) = new_token {
lit.set_span(token.span());
return TokenStream::from(TokenTree::Literal(lit));
}
panic!();
}
25 changes: 24 additions & 1 deletion tests/ui/uninlined_format_args.fixed
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// aux-build:proc_macro_with_span.rs
// run-rustfix
// aux-build:proc_macro_indoc.rs

#![feature(custom_inner_attributes)]
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
#![allow(
clippy::double_parens,
clippy::eq_op,
clippy::format_in_format_args,
clippy::print_literal
)]

extern crate proc_macro_indoc;
extern crate proc_macro_with_span;
use proc_macro_with_span::with_span;

Expand All @@ -14,6 +22,12 @@ macro_rules! no_param_str {
};
}

macro_rules! pass_through {
($expr:expr) => {
$expr
};
}

macro_rules! my_println {
($($args:tt),*) => {{
println!($($args),*)
Expand Down Expand Up @@ -123,6 +137,10 @@ fn tester(fn_arg: i32) {
println!("{}", format!("{local_i32}"));
my_println!("{}", local_i32);
my_println_args!("{}", local_i32);
println!("{local_i32}");
#[rustfmt::skip]
println!("{local_i32}");
println!("{local_i32:width$.prec$}");

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

println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
println!("{}", with_span!(span val));

println!(pass_through!("foo={}"), local_i32);
println!(pass_through!("foo={a}"), a = local_i32);
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
}

fn main() {
Expand Down
25 changes: 24 additions & 1 deletion tests/ui/uninlined_format_args.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
// aux-build:proc_macro_with_span.rs
// run-rustfix
// aux-build:proc_macro_indoc.rs

#![feature(custom_inner_attributes)]
#![warn(clippy::uninlined_format_args)]
#![allow(named_arguments_used_positionally, unused_imports, unused_macros, unused_variables)]
#![allow(clippy::eq_op, clippy::format_in_format_args, clippy::print_literal)]
#![allow(
clippy::double_parens,
clippy::eq_op,
clippy::format_in_format_args,
clippy::print_literal
)]

extern crate proc_macro_indoc;
extern crate proc_macro_with_span;
use proc_macro_with_span::with_span;

Expand All @@ -14,6 +22,12 @@ macro_rules! no_param_str {
};
}

macro_rules! pass_through {
($expr:expr) => {
$expr
};
}

macro_rules! my_println {
($($args:tt),*) => {{
println!($($args),*)
Expand Down Expand Up @@ -126,6 +140,10 @@ fn tester(fn_arg: i32) {
println!("{}", format!("{}", local_i32));
my_println!("{}", local_i32);
my_println_args!("{}", local_i32);
println!("{}", (local_i32));
#[rustfmt::skip]
println!("{}", ((local_i32)));
println!("{0:1$.2$}", (local_i32), (width), (prec));

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

println!(with_span!("{0} {1}" "{1} {0}"), local_i32, local_f64);
println!("{}", with_span!(span val));

println!(pass_through!("foo={}"), local_i32);
println!(pass_through!("foo={a}"), a = local_i32);
println!(proc_macro_indoc::simple_indoc!("foo={}"), local_i32);
println!(proc_macro_indoc::simple_indoc!("foo={a}"), a = local_i32);
}

fn main() {
Expand Down
Loading