1
Fork 0

Rollup merge of #63761 - petrochenkov:procattrs, r=eddyb

Propagate spans and attributes from proc macro definitions

Thanks to https://github.com/rust-lang/rust/pull/63269 we now have spans and attributes from proc macro definitions available in metadata.

However, that PR didn't actually put them into use! This PR finishes that work.

Attributes `rustc_macro_transparency`, `allow_internal_unstable`, `allow_internal_unsafe`, `local_inner_macros`, `rustc_builtin_macro`, `stable`, `unstable`, `rustc_deprecated`, `deprecated` now have effect when applied to proc macro definition functions.
From those attributes only `deprecated` is both stable and supposed to be used in new code.
(`#![staged_api]` still cannot be used in proc macro crates for unrelated reasons though.)

`Span::def_site` from the proc macro API now returns the correct location of the proc macro definition.

Also, I made a mistake in https://github.com/rust-lang/rust/pull/63269#discussion_r312702919, loaded proc macros didn't actually use the resolver cache.
This PR fixes the caching issue, now proc macros go through the `Resolver::macro_map` cache as well.

(Also, the first commit turns `proc_macro::quote` into a regular built-in macro to reduce the number of places where `SyntaxExtension`s need to be manually created.)
This commit is contained in:
Mazdak Farrokhzad 2019-08-27 08:17:51 +02:00 committed by GitHub
commit 0da7098116
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 310 additions and 164 deletions

View file

@ -375,10 +375,11 @@ impl<'a> Parser<'a> {
if let Some(directory) = directory {
parser.directory = directory;
} else if !parser.token.span.is_dummy() {
if let FileName::Real(mut path) =
sess.source_map().span_to_unmapped_path(parser.token.span) {
path.pop();
parser.directory.path = Cow::from(path);
if let Some(FileName::Real(path)) =
&sess.source_map().lookup_char_pos(parser.token.span.lo()).file.unmapped_path {
if let Some(directory_path) = path.parent() {
parser.directory.path = Cow::from(directory_path.to_path_buf());
}
}
}