-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Open
Labels
A-proc-macrosArea: Procedural macrosArea: Procedural macrosC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Hi.
It looks like when you generate non-items in a custom derive, they are silently dropped.
For instance, with the following custom derive:
#[proc_macro_derive(HelloWorld)]
pub fn hello_world(input: TokenStream) -> TokenStream {
let ast = syn::parse(input).unwrap();
let gen = impl_hello_world(&ast);
gen.into()
}
fn impl_hello_world(ast: &syn::DeriveInput) -> quote::Tokens {
let name = &ast.ident;
quote! {{
fn hello_world() {
println!("Hello, World! My name is {}", stringify!(#name));
}
hello_world();
}}
}and the following code:
fn main() {
#[derive(HelloWorld)]
struct _Toto {
}
}nothing is printed on the screen.
So, is it normal that non-items are dropped?
Could they be generated as well if it makes sense (like in a struct that is defined within a function)?
If not, if would be nice to have a least a warning when this happen.
Thanks.
fmease
Metadata
Metadata
Assignees
Labels
A-proc-macrosArea: Procedural macrosArea: Procedural macrosC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.