proc_macro: Update Span::def_site to use the proc macro definition location

Which is no longer dummy and is available from metadata now.
This commit is contained in:
Vadim Petrochenkov
2019-08-20 23:35:03 +03:00
parent 2065ee9acc
commit c476b55e52
6 changed files with 143 additions and 41 deletions

View File

@@ -360,12 +360,11 @@ pub(crate) struct Rustc<'a> {
impl<'a> Rustc<'a> {
pub fn new(cx: &'a ExtCtxt<'_>) -> Self {
// No way to determine def location for a proc macro right now, so use call location.
let location = cx.current_expansion.id.expn_data().call_site;
let expn_data = cx.current_expansion.id.expn_data();
Rustc {
sess: cx.parse_sess,
def_site: cx.with_def_site_ctxt(location),
call_site: cx.with_call_site_ctxt(location),
def_site: cx.with_def_site_ctxt(expn_data.def_site),
call_site: cx.with_call_site_ctxt(expn_data.call_site),
}
}

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());
}
}
}