mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Rollup merge of #70266 - petrochenkov:prochead, r=varkor
proc_macro_harness: Use item header spans for errors Addresses https://github.com/rust-lang/rust/pull/70233#discussion_r396043004.
This commit is contained in:
commit
69c0bcd3d5
@ -10,6 +10,7 @@ use rustc_expand::base::{ExtCtxt, Resolver};
|
||||
use rustc_expand::expand::{AstFragment, ExpansionConfig};
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_span::hygiene::AstPass;
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::symbol::{kw, sym};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use smallvec::smallvec;
|
||||
@ -44,6 +45,7 @@ struct CollectProcMacros<'a> {
|
||||
macros: Vec<ProcMacro>,
|
||||
in_root: bool,
|
||||
handler: &'a rustc_errors::Handler,
|
||||
source_map: &'a SourceMap,
|
||||
is_proc_macro_crate: bool,
|
||||
is_test_crate: bool,
|
||||
}
|
||||
@ -65,6 +67,7 @@ pub fn inject(
|
||||
macros: Vec::new(),
|
||||
in_root: true,
|
||||
handler,
|
||||
source_map: sess.source_map(),
|
||||
is_proc_macro_crate,
|
||||
is_test_crate,
|
||||
};
|
||||
@ -195,7 +198,7 @@ impl<'a> CollectProcMacros<'a> {
|
||||
} else {
|
||||
"functions tagged with `#[proc_macro_derive]` must be `pub`"
|
||||
};
|
||||
self.handler.span_err(item.span, msg);
|
||||
self.handler.span_err(self.source_map.def_span(item.span), msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +217,7 @@ impl<'a> CollectProcMacros<'a> {
|
||||
} else {
|
||||
"functions tagged with `#[proc_macro_attribute]` must be `pub`"
|
||||
};
|
||||
self.handler.span_err(item.span, msg);
|
||||
self.handler.span_err(self.source_map.def_span(item.span), msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,7 +236,7 @@ impl<'a> CollectProcMacros<'a> {
|
||||
} else {
|
||||
"functions tagged with `#[proc_macro]` must be `pub`"
|
||||
};
|
||||
self.handler.span_err(item.span, msg);
|
||||
self.handler.span_err(self.source_map.def_span(item.span), msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,7 +247,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
||||
if self.is_proc_macro_crate && attr::contains_name(&item.attrs, sym::macro_export) {
|
||||
let msg =
|
||||
"cannot export macro_rules! macros from a `proc-macro` crate type currently";
|
||||
self.handler.span_err(item.span, msg);
|
||||
self.handler.span_err(self.source_map.def_span(item.span), msg);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +298,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
|
||||
|
||||
let attr = match found_attr {
|
||||
None => {
|
||||
self.check_not_pub_in_root(&item.vis, item.span);
|
||||
self.check_not_pub_in_root(&item.vis, self.source_map.def_span(item.span));
|
||||
let prev_in_root = mem::replace(&mut self.in_root, false);
|
||||
visit::walk_item(self, item);
|
||||
self.in_root = prev_in_root;
|
||||
|
@ -1,10 +1,8 @@
|
||||
error: cannot export macro_rules! macros from a `proc-macro` crate type currently
|
||||
--> $DIR/export-macro.rs:9:1
|
||||
|
|
||||
LL | / macro_rules! foo {
|
||||
LL | | ($e:expr) => ($e)
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | macro_rules! foo {
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -2,7 +2,7 @@ error: `proc-macro` crate types currently cannot export any items other than fun
|
||||
--> $DIR/exports.rs:7:1
|
||||
|
|
||||
LL | pub fn a() {}
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
|
||||
--> $DIR/exports.rs:8:1
|
||||
@ -14,13 +14,13 @@ error: `proc-macro` crate types currently cannot export any items other than fun
|
||||
--> $DIR/exports.rs:9:1
|
||||
|
|
||||
LL | pub enum C {}
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
|
||||
--> $DIR/exports.rs:10:1
|
||||
|
|
||||
LL | pub mod d {}
|
||||
| ^^^^^^^^^^^^
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
@ -2,7 +2,7 @@ error: functions tagged with `#[proc_macro]` must currently reside in the root o
|
||||
--> $DIR/non-root.rs:11:5
|
||||
|
|
||||
LL | pub fn foo(arg: TokenStream) -> TokenStream { arg }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,32 +1,20 @@
|
||||
error: `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
|
||||
--> $DIR/pub-at-crate-root.rs:8:1
|
||||
|
|
||||
LL | / pub mod a {
|
||||
LL | | use proc_macro::TokenStream;
|
||||
LL | |
|
||||
LL | | #[proc_macro_derive(B)]
|
||||
... |
|
||||
LL | | }
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | pub mod a {
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: functions tagged with `#[proc_macro_derive]` must currently reside in the root of the crate
|
||||
--> $DIR/pub-at-crate-root.rs:12:5
|
||||
|
|
||||
LL | / pub fn bar(a: TokenStream) -> TokenStream {
|
||||
LL | |
|
||||
LL | | a
|
||||
LL | | }
|
||||
| |_____^
|
||||
LL | pub fn bar(a: TokenStream) -> TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: functions tagged with `#[proc_macro_derive]` must be `pub`
|
||||
--> $DIR/pub-at-crate-root.rs:19:1
|
||||
|
|
||||
LL | / fn bar(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
LL | |
|
||||
LL | | a
|
||||
LL | | }
|
||||
| |_^
|
||||
LL | fn bar(a: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user