allow duplicate idents in format_args_f (#515)
This commit is contained in:
1 parent
c801d4402e
commit
baf1807338
2 files changed
+26
-12
No files matched your search
@@ -23,4 +23,10 @@ fn formatting_compiles() {
|
|||||||
format_args_f!("{x.borrow():?}").to_string(),
|
format_args_f!("{x.borrow():?}").to_string(),
|
||||||
format!("{:?}", x.borrow())
|
format!("{:?}", x.borrow())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// allows duplicate format args
|
||||||
|
assert_eq!(
|
||||||
|
format_args_f!("{x:?} {x:?}").to_string(),
|
||||||
|
format!("{:?} {:?}", x, x)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
+20
-12
@@ -1,4 +1,4 @@
|
|||||||
use std::str::FromStr;
|
use std::{collections::HashSet, str::FromStr};
|
||||||
|
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
|
|
||||||
@@ -48,17 +48,25 @@ pub fn format_args_f_impl(input: IfmtInput) -> Result<TokenStream> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let named_args = input.segments.iter().filter_map(|seg| {
|
// remove duplicate idents
|
||||||
if let Segment::Formatted {
|
let named_args_idents: HashSet<_> = input
|
||||||
segment: FormattedSegment::Ident(ident),
|
.segments
|
||||||
..
|
.iter()
|
||||||
} = seg
|
.filter_map(|seg| {
|
||||||
{
|
if let Segment::Formatted {
|
||||||
Some(quote! {#ident = #ident})
|
segment: FormattedSegment::Ident(ident),
|
||||||
} else {
|
..
|
||||||
None
|
} = seg
|
||||||
}
|
{
|
||||||
});
|
Some(ident)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let named_args = named_args_idents
|
||||||
|
.iter()
|
||||||
|
.map(|ident| quote!(#ident = #ident));
|
||||||
|
|
||||||
Ok(quote! {
|
Ok(quote! {
|
||||||
format_args!(
|
format_args!(
|
||||||
|
|||||||
Reference in new issue
Block a user