-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-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
For some reason ommiting the "C"
in extern "C" fn
causes the spans to get lost in error messages.
I've created this repository to demonstrate it,simply git clone it and try to build the using_proc_macro
crate.
The proc_macro_crate
crate:
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::{
visit::{self, Visit},
Lifetime, Type, TypeBareFn, TypeReference,
};
#[proc_macro_derive(ProcMacro)]
pub fn stable_abi(input: TokenStream) -> TokenStream {
syn::parse::<syn::DeriveInput>(input)
.and_then(|di|{
let mut res=Ok(());
Visitor { err:&mut res }.visit_derive_input(&di);
res.map(|_| quote::quote!() )
})
.unwrap_or_else(|e| e.to_compile_error() )
.into()
}
pub(crate) struct Visitor<'a> {
err:&'a mut Result<(),syn::Error>,
}
/////////////
impl<'a> Visit<'_> for Visitor<'a> {
fn visit_type_reference(&mut self, ref_: &TypeReference) {
*self.err=Err(syn::Error::new_spanned(ref_,format!("hello from proc macro")));
}
fn visit_lifetime(&mut self, lt: &Lifetime) {
*self.err=Err(syn::Error::new_spanned(lt,format!("hello from proc macro")));
}
}
The using_proc_macro
crate:
#[derive(proc_macro_crate::ProcMacro)]
struct Hello(
&'a (),
extern fn(),
);
#[derive(proc_macro_crate::ProcMacro)]
struct World(
&'a (),
extern "C" fn(),
);
The error message
error: hello from proc macro
error: hello from proc macro
--> src/lib.rs:10:5
|
10 | &'a (),
| ^^^^^^
The first error is for Hello
and the second is for World
.
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-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.