You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a a proc macro from within a declarative macro, a ty is expanded to a Group.
With the latest nightly 1.63.0-nightly (42e1761c7 2022-05-15) the invisible delimiters now appear in the quoted tokens e.g.
before bool,
after /*«*/ bool /*»*/
Two-crate test case
Crate derive, Cargo.toml
[package]
name = "derive"
version = "0.0.0"
edition = "2018"
[lib]
proc-macro = true
[dependencies]
quote = "1"
proc-macro2 = "1.0"
syn = "1.0"
Crate derive, src/lib.rs
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};
use quote::quote;
#[proc_macro_derive(MyDerive)]
pub fn my_derive(input: TokenStream) -> TokenStream {
println!("{}: {:?}", input, input);
let input: DeriveInput = syn::parse(input).unwrap();
if let syn::Data::Struct(s) = input.data {
for f in s.fields {
let ty = f.ty;
match &ty {
syn::Type::Group(group) => {
let ty = &group.elem;
println!("Type::Group {:?}", quote!(#ty));
},
_ => println!("Type::Other"),
}
// prints '/*«*/ bool /*»*/` with nightly rustc 1.63.0-nightly (42e1761c7 2022-05-15)
// prints 'bool' with current stable rustc 1.60.0 (7737e0b5c 2022-04-04)
println!("{}", quote!(#ty))
}
}
quote!{ }.into()
}
macro_rules! gen_struct_with_type {
( $ty:ty ) => {
#[derive(derive::MyDerive)]
struct S($ty); // This type is parsed as a `Group` so the delimeters get added to the quoted tokens
};
}
#[derive(derive::MyDerive)]
struct T(bool);
gen_struct_with_type!(bool);
When using a a proc macro from within a declarative macro, a
ty
is expanded to aGroup
.With the latest nightly
1.63.0-nightly (42e1761c7 2022-05-15)
the invisible delimiters now appear in the quoted tokens e.g.bool
,/*«*/ bool /*»*/
Two-crate test case
Crate
derive
,Cargo.toml
Crate
derive
,src/lib.rs
Crate
impl
,Cargo.toml
Crate
impl
,src/lib.rs
Looking at recent commits, this looks suspicious: #95159. Related #96305 (comment).
The text was updated successfully, but these errors were encountered: