hygiene: Merge NameAndSpan
into ExpnInfo
This commit is contained in:
parent
117cb040f1
commit
20ce91076a
15 changed files with 116 additions and 154 deletions
|
@ -612,13 +612,11 @@ impl<'a> LoweringContext<'a> {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(codemap::ExpnInfo {
|
mark.set_expn_info(codemap::ExpnInfo {
|
||||||
call_site: span,
|
call_site: span,
|
||||||
callee: codemap::NameAndSpan {
|
def_site: Some(span),
|
||||||
format: codemap::CompilerDesugaring(reason),
|
format: codemap::CompilerDesugaring(reason),
|
||||||
span: Some(span),
|
allow_internal_unstable: true,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: codemap::hygiene::default_edition(),
|
||||||
edition: codemap::hygiene::default_edition(),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
span.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,15 +391,11 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind {
|
||||||
|
|
||||||
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnInfo {
|
||||||
call_site,
|
call_site,
|
||||||
callee
|
def_site,
|
||||||
});
|
|
||||||
|
|
||||||
impl_stable_hash_for!(struct ::syntax_pos::hygiene::NameAndSpan {
|
|
||||||
format,
|
format,
|
||||||
allow_internal_unstable,
|
allow_internal_unstable,
|
||||||
allow_internal_unsafe,
|
allow_internal_unsafe,
|
||||||
edition,
|
edition
|
||||||
span
|
|
||||||
});
|
});
|
||||||
|
|
||||||
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
|
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnFormat {
|
||||||
|
|
|
@ -366,9 +366,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
|
if let Some(k) = obligation.cause.span.compiler_desugaring_kind() {
|
||||||
let desugaring = k.as_symbol().as_str();
|
|
||||||
flags.push(("from_desugaring".to_string(), None));
|
flags.push(("from_desugaring".to_string(), None));
|
||||||
flags.push(("from_desugaring".to_string(), Some(desugaring.to_string())));
|
flags.push(("from_desugaring".to_string(), Some(k.name().to_string())));
|
||||||
}
|
}
|
||||||
let generics = self.tcx.generics_of(def_id);
|
let generics = self.tcx.generics_of(def_id);
|
||||||
let self_ty = trait_ref.self_ty();
|
let self_ty = trait_ref.self_ty();
|
||||||
|
|
|
@ -15,7 +15,7 @@ use syntax::ast::{Arg, FnHeader, Generics, Mac, Mutability, Ty, Unsafety};
|
||||||
use syntax::ast::{self, Expr, Ident, Item, ItemKind, TyKind, VisibilityKind};
|
use syntax::ast::{self, Expr, Ident, Item, ItemKind, TyKind, VisibilityKind};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::codemap::respan;
|
use syntax::codemap::respan;
|
||||||
use syntax::codemap::{ExpnInfo, MacroAttribute, NameAndSpan};
|
use syntax::codemap::{ExpnInfo, MacroAttribute};
|
||||||
use syntax::ext::base::ExtCtxt;
|
use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::ext::base::Resolver;
|
use syntax::ext::base::Resolver;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
|
@ -80,13 +80,11 @@ impl<'a> Folder for ExpandAllocatorDirectives<'a> {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo {
|
mark.set_expn_info(ExpnInfo {
|
||||||
call_site: DUMMY_SP,
|
call_site: DUMMY_SP,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: MacroAttribute(Symbol::intern(name)),
|
format: MacroAttribute(Symbol::intern(name)),
|
||||||
span: None,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: hygiene::default_edition(),
|
||||||
edition: hygiene::default_edition(),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
let span = item.span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
||||||
let ecfg = ExpansionConfig::default(name.to_string());
|
let ecfg = ExpansionConfig::default(name.to_string());
|
||||||
|
|
|
@ -844,7 +844,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||||
let callsite = span.source_callsite();
|
let callsite = span.source_callsite();
|
||||||
let callsite_span = self.span_from_span(callsite);
|
let callsite_span = self.span_from_span(callsite);
|
||||||
let callee = span.source_callee()?;
|
let callee = span.source_callee()?;
|
||||||
let callee_span = callee.span?;
|
let callee_span = callee.def_site?;
|
||||||
|
|
||||||
// Ignore attribute macros, their spans are usually mangled
|
// Ignore attribute macros, their spans are usually mangled
|
||||||
if let MacroAttribute(_) = callee.format {
|
if let MacroAttribute(_) = callee.format {
|
||||||
|
@ -872,7 +872,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
|
||||||
let callee_span = self.span_from_span(callee_span);
|
let callee_span = self.span_from_span(callee_span);
|
||||||
Some(MacroRef {
|
Some(MacroRef {
|
||||||
span: callsite_span,
|
span: callsite_span,
|
||||||
qualname: callee.name().to_string(), // FIXME: generate the real qualname
|
qualname: callee.format.name().to_string(), // FIXME: generate the real qualname
|
||||||
callee_span,
|
callee_span,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
|
|
||||||
pub use syntax_pos::*;
|
pub use syntax_pos::*;
|
||||||
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo, NameAndSpan};
|
pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo};
|
||||||
pub use self::ExpnFormat::*;
|
pub use self::ExpnFormat::*;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
|
|
@ -834,7 +834,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
let mut last_macro = None;
|
let mut last_macro = None;
|
||||||
loop {
|
loop {
|
||||||
if ctxt.outer().expn_info().map_or(None, |info| {
|
if ctxt.outer().expn_info().map_or(None, |info| {
|
||||||
if info.callee.name() == "include" {
|
if info.format.name() == "include" {
|
||||||
// Stop going up the backtrace once include! is encountered
|
// Stop going up the backtrace once include! is encountered
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use attr::HasAttrs;
|
use attr::HasAttrs;
|
||||||
use ast;
|
use ast;
|
||||||
use codemap::{hygiene, ExpnInfo, NameAndSpan, ExpnFormat};
|
use codemap::{hygiene, ExpnInfo, ExpnFormat};
|
||||||
use ext::base::ExtCtxt;
|
use ext::base::ExtCtxt;
|
||||||
use ext::build::AstBuilder;
|
use ext::build::AstBuilder;
|
||||||
use parse::parser::PathStyle;
|
use parse::parser::PathStyle;
|
||||||
|
@ -60,13 +60,11 @@ pub fn add_derived_markers<T>(cx: &mut ExtCtxt, span: Span, traits: &[ast::Path]
|
||||||
|
|
||||||
cx.current_expansion.mark.set_expn_info(ExpnInfo {
|
cx.current_expansion.mark.set_expn_info(ExpnInfo {
|
||||||
call_site: span,
|
call_site: span,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
|
format: ExpnFormat::MacroAttribute(Symbol::intern(&pretty_name)),
|
||||||
span: None,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: hygiene::default_edition(),
|
||||||
edition: hygiene::default_edition(),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let span = span.with_ctxt(cx.backtrace());
|
let span = span.with_ctxt(cx.backtrace());
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
use ast::{self, Block, Ident, NodeId, PatKind, Path};
|
use ast::{self, Block, Ident, NodeId, PatKind, Path};
|
||||||
use ast::{MacStmtStyle, StmtKind, ItemKind};
|
use ast::{MacStmtStyle, StmtKind, ItemKind};
|
||||||
use attr::{self, HasAttrs};
|
use attr::{self, HasAttrs};
|
||||||
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute, dummy_spanned, respan};
|
use codemap::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan};
|
||||||
use config::{is_test_or_bench, StripUnconfigured};
|
use config::{is_test_or_bench, StripUnconfigured};
|
||||||
use errors::{Applicability, FatalError};
|
use errors::{Applicability, FatalError};
|
||||||
use ext::base::*;
|
use ext::base::*;
|
||||||
|
@ -514,7 +514,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
|
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
|
||||||
let mut err = self.cx.struct_span_err(info.call_site,
|
let mut err = self.cx.struct_span_err(info.call_site,
|
||||||
&format!("recursion limit reached while expanding the macro `{}`",
|
&format!("recursion limit reached while expanding the macro `{}`",
|
||||||
info.callee.name()));
|
info.format.name()));
|
||||||
err.help(&format!(
|
err.help(&format!(
|
||||||
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
|
"consider adding a `#![recursion_limit=\"{}\"]` attribute to your crate",
|
||||||
suggested_limit));
|
suggested_limit));
|
||||||
|
@ -538,13 +538,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
attr::mark_used(&attr);
|
attr::mark_used(&attr);
|
||||||
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
|
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
|
||||||
call_site: attr.span,
|
call_site: attr.span,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: MacroAttribute(Symbol::intern(&format!("{}", attr.path))),
|
format: MacroAttribute(Symbol::intern(&format!("{}", attr.path))),
|
||||||
span: None,
|
allow_internal_unstable: false,
|
||||||
allow_internal_unstable: false,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: ext.edition(),
|
||||||
edition: ext.edition(),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
match *ext {
|
match *ext {
|
||||||
|
@ -727,13 +725,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
}
|
}
|
||||||
mark.set_expn_info(ExpnInfo {
|
mark.set_expn_info(ExpnInfo {
|
||||||
call_site: span,
|
call_site: span,
|
||||||
callee: NameAndSpan {
|
def_site: def_site_span,
|
||||||
format: macro_bang_format(path),
|
format: macro_bang_format(path),
|
||||||
span: def_site_span,
|
allow_internal_unstable,
|
||||||
allow_internal_unstable,
|
allow_internal_unsafe,
|
||||||
allow_internal_unsafe,
|
edition,
|
||||||
edition,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
@ -777,13 +773,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
} else {
|
} else {
|
||||||
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
|
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
|
||||||
call_site: span,
|
call_site: span,
|
||||||
callee: NameAndSpan {
|
def_site: tt_span,
|
||||||
format: macro_bang_format(path),
|
format: macro_bang_format(path),
|
||||||
span: tt_span,
|
allow_internal_unstable,
|
||||||
allow_internal_unstable,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: hygiene::default_edition(),
|
||||||
edition: hygiene::default_edition(),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let input: Vec<_> = mac.node.stream().into_trees().collect();
|
let input: Vec<_> = mac.node.stream().into_trees().collect();
|
||||||
|
@ -815,16 +809,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
self.gate_proc_macro_expansion_kind(span, kind);
|
self.gate_proc_macro_expansion_kind(span, kind);
|
||||||
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
|
invoc.expansion_data.mark.set_expn_info(ExpnInfo {
|
||||||
call_site: span,
|
call_site: span,
|
||||||
callee: NameAndSpan {
|
// FIXME procedural macros do not have proper span info
|
||||||
format: macro_bang_format(path),
|
// yet, when they do, we should use it here.
|
||||||
// FIXME procedural macros do not have proper span info
|
def_site: None,
|
||||||
// yet, when they do, we should use it here.
|
format: macro_bang_format(path),
|
||||||
span: None,
|
// FIXME probably want to follow macro_rules macros here.
|
||||||
// FIXME probably want to follow macro_rules macros here.
|
allow_internal_unstable,
|
||||||
allow_internal_unstable,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition,
|
||||||
edition,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let tok_result = expandfun.expand(self.cx, span, mac.node.stream());
|
let tok_result = expandfun.expand(self.cx, span, mac.node.stream());
|
||||||
|
@ -894,13 +886,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
|
|
||||||
let mut expn_info = ExpnInfo {
|
let mut expn_info = ExpnInfo {
|
||||||
call_site: span,
|
call_site: span,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: MacroAttribute(pretty_name),
|
format: MacroAttribute(pretty_name),
|
||||||
span: None,
|
allow_internal_unstable: false,
|
||||||
allow_internal_unstable: false,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: ext.edition(),
|
||||||
edition: ext.edition(),
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match *ext {
|
match *ext {
|
||||||
|
@ -916,7 +906,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||||
Some(invoc.fragment_kind.expect_from_annotatables(items))
|
Some(invoc.fragment_kind.expect_from_annotatables(items))
|
||||||
}
|
}
|
||||||
BuiltinDerive(func) => {
|
BuiltinDerive(func) => {
|
||||||
expn_info.callee.allow_internal_unstable = true;
|
expn_info.allow_internal_unstable = true;
|
||||||
invoc.expansion_data.mark.set_expn_info(expn_info);
|
invoc.expansion_data.mark.set_expn_info(expn_info);
|
||||||
let span = span.with_ctxt(self.cx.backtrace());
|
let span = span.with_ctxt(self.cx.backtrace());
|
||||||
let mut items = Vec::new();
|
let mut items = Vec::new();
|
||||||
|
|
|
@ -14,7 +14,7 @@ use std::cell::Cell;
|
||||||
use ext::hygiene::{Mark, SyntaxContext};
|
use ext::hygiene::{Mark, SyntaxContext};
|
||||||
use symbol::{Symbol, keywords};
|
use symbol::{Symbol, keywords};
|
||||||
use syntax_pos::{DUMMY_SP, Span};
|
use syntax_pos::{DUMMY_SP, Span};
|
||||||
use codemap::{ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned, hygiene, respan};
|
use codemap::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan};
|
||||||
use ptr::P;
|
use ptr::P;
|
||||||
use tokenstream::TokenStream;
|
use tokenstream::TokenStream;
|
||||||
|
|
||||||
|
@ -25,13 +25,11 @@ fn ignored_span(sp: Span) -> Span {
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo {
|
mark.set_expn_info(ExpnInfo {
|
||||||
call_site: DUMMY_SP,
|
call_site: DUMMY_SP,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: MacroAttribute(Symbol::intern("std_inject")),
|
format: MacroAttribute(Symbol::intern("std_inject")),
|
||||||
span: None,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: hygiene::default_edition(),
|
||||||
edition: hygiene::default_edition(),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
sp.with_ctxt(SyntaxContext::empty().apply_mark(mark))
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ use std::vec;
|
||||||
use attr::{self, HasAttrs};
|
use attr::{self, HasAttrs};
|
||||||
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
|
use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos};
|
||||||
|
|
||||||
use codemap::{self, CodeMap, ExpnInfo, NameAndSpan, MacroAttribute, dummy_spanned};
|
use codemap::{self, CodeMap, ExpnInfo, MacroAttribute, dummy_spanned};
|
||||||
use errors;
|
use errors;
|
||||||
use config;
|
use config;
|
||||||
use entry::{self, EntryPointType};
|
use entry::{self, EntryPointType};
|
||||||
|
@ -307,13 +307,11 @@ fn generate_test_harness(sess: &ParseSess,
|
||||||
|
|
||||||
mark.set_expn_info(ExpnInfo {
|
mark.set_expn_info(ExpnInfo {
|
||||||
call_site: DUMMY_SP,
|
call_site: DUMMY_SP,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: MacroAttribute(Symbol::intern("test")),
|
format: MacroAttribute(Symbol::intern("test")),
|
||||||
span: None,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: hygiene::default_edition(),
|
||||||
edition: hygiene::default_edition(),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
TestHarnessGenerator {
|
TestHarnessGenerator {
|
||||||
|
|
|
@ -157,11 +157,11 @@ fn call_intrinsic(cx: &ExtCtxt,
|
||||||
intrinsic: &str,
|
intrinsic: &str,
|
||||||
args: Vec<P<ast::Expr>>)
|
args: Vec<P<ast::Expr>>)
|
||||||
-> P<ast::Expr> {
|
-> P<ast::Expr> {
|
||||||
if cx.current_expansion.mark.expn_info().unwrap().callee.allow_internal_unstable {
|
if cx.current_expansion.mark.expn_info().unwrap().allow_internal_unstable {
|
||||||
span = span.with_ctxt(cx.backtrace());
|
span = span.with_ctxt(cx.backtrace());
|
||||||
} else { // Avoid instability errors with user defined curstom derives, cc #36316
|
} else { // Avoid instability errors with user defined curstom derives, cc #36316
|
||||||
let mut info = cx.current_expansion.mark.expn_info().unwrap();
|
let mut info = cx.current_expansion.mark.expn_info().unwrap();
|
||||||
info.callee.allow_internal_unstable = true;
|
info.allow_internal_unstable = true;
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(info);
|
mark.set_expn_info(info);
|
||||||
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
|
||||||
|
|
|
@ -14,7 +14,7 @@ use errors;
|
||||||
|
|
||||||
use syntax::ast::{self, Ident, NodeId};
|
use syntax::ast::{self, Ident, NodeId};
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::codemap::{ExpnInfo, NameAndSpan, MacroAttribute, hygiene, respan};
|
use syntax::codemap::{ExpnInfo, MacroAttribute, hygiene, respan};
|
||||||
use syntax::ext::base::ExtCtxt;
|
use syntax::ext::base::ExtCtxt;
|
||||||
use syntax::ext::build::AstBuilder;
|
use syntax::ext::build::AstBuilder;
|
||||||
use syntax::ext::expand::ExpansionConfig;
|
use syntax::ext::expand::ExpansionConfig;
|
||||||
|
@ -364,13 +364,11 @@ fn mk_registrar(cx: &mut ExtCtxt,
|
||||||
let mark = Mark::fresh(Mark::root());
|
let mark = Mark::fresh(Mark::root());
|
||||||
mark.set_expn_info(ExpnInfo {
|
mark.set_expn_info(ExpnInfo {
|
||||||
call_site: DUMMY_SP,
|
call_site: DUMMY_SP,
|
||||||
callee: NameAndSpan {
|
def_site: None,
|
||||||
format: MacroAttribute(Symbol::intern("proc_macro")),
|
format: MacroAttribute(Symbol::intern("proc_macro")),
|
||||||
span: None,
|
allow_internal_unstable: true,
|
||||||
allow_internal_unstable: true,
|
allow_internal_unsafe: false,
|
||||||
allow_internal_unsafe: false,
|
edition: hygiene::default_edition(),
|
||||||
edition: hygiene::default_edition(),
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
let span = DUMMY_SP.apply_mark(mark);
|
let span = DUMMY_SP.apply_mark(mark);
|
||||||
|
|
||||||
|
|
|
@ -482,12 +482,11 @@ pub struct ExpnInfo {
|
||||||
/// call_site span would have its own ExpnInfo, with the call_site
|
/// call_site span would have its own ExpnInfo, with the call_site
|
||||||
/// pointing to the `foo!` invocation.
|
/// pointing to the `foo!` invocation.
|
||||||
pub call_site: Span,
|
pub call_site: Span,
|
||||||
/// Information about the expansion.
|
/// The span of the macro definition itself. The macro may not
|
||||||
pub callee: NameAndSpan
|
/// have a sensible definition span (e.g. something defined
|
||||||
}
|
/// completely inside libsyntax) in which case this is None.
|
||||||
|
/// This span serves only informational purpose and is not used for resolution.
|
||||||
#[derive(Clone, Hash, Debug, RustcEncodable, RustcDecodable)]
|
pub def_site: Option<Span>,
|
||||||
pub struct NameAndSpan {
|
|
||||||
/// The format with which the macro was invoked.
|
/// The format with which the macro was invoked.
|
||||||
pub format: ExpnFormat,
|
pub format: ExpnFormat,
|
||||||
/// Whether the macro is allowed to use #[unstable]/feature-gated
|
/// Whether the macro is allowed to use #[unstable]/feature-gated
|
||||||
|
@ -499,20 +498,6 @@ pub struct NameAndSpan {
|
||||||
pub allow_internal_unsafe: bool,
|
pub allow_internal_unsafe: bool,
|
||||||
/// Edition of the crate in which the macro is defined.
|
/// Edition of the crate in which the macro is defined.
|
||||||
pub edition: Edition,
|
pub edition: Edition,
|
||||||
/// The span of the macro definition itself. The macro may not
|
|
||||||
/// have a sensible definition span (e.g. something defined
|
|
||||||
/// completely inside libsyntax) in which case this is None.
|
|
||||||
pub span: Option<Span>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NameAndSpan {
|
|
||||||
pub fn name(&self) -> Symbol {
|
|
||||||
match self.format {
|
|
||||||
ExpnFormat::MacroAttribute(s) |
|
|
||||||
ExpnFormat::MacroBang(s) => s,
|
|
||||||
ExpnFormat::CompilerDesugaring(ref kind) => kind.as_symbol(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The source of expansion.
|
/// The source of expansion.
|
||||||
|
@ -526,8 +511,17 @@ pub enum ExpnFormat {
|
||||||
CompilerDesugaring(CompilerDesugaringKind)
|
CompilerDesugaring(CompilerDesugaringKind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ExpnFormat {
|
||||||
|
pub fn name(&self) -> Symbol {
|
||||||
|
match *self {
|
||||||
|
ExpnFormat::MacroBang(name) | ExpnFormat::MacroAttribute(name) => name,
|
||||||
|
ExpnFormat::CompilerDesugaring(kind) => kind.name(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The kind of compiler desugaring.
|
/// The kind of compiler desugaring.
|
||||||
#[derive(Clone, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
|
#[derive(Clone, Copy, Hash, Debug, PartialEq, Eq, RustcEncodable, RustcDecodable)]
|
||||||
pub enum CompilerDesugaringKind {
|
pub enum CompilerDesugaringKind {
|
||||||
DotFill,
|
DotFill,
|
||||||
QuestionMark,
|
QuestionMark,
|
||||||
|
@ -540,16 +534,14 @@ pub enum CompilerDesugaringKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CompilerDesugaringKind {
|
impl CompilerDesugaringKind {
|
||||||
pub fn as_symbol(&self) -> Symbol {
|
pub fn name(self) -> Symbol {
|
||||||
use CompilerDesugaringKind::*;
|
Symbol::intern(match self {
|
||||||
let s = match *self {
|
CompilerDesugaringKind::Async => "async",
|
||||||
Async => "async",
|
CompilerDesugaringKind::DotFill => "...",
|
||||||
DotFill => "...",
|
CompilerDesugaringKind::QuestionMark => "?",
|
||||||
QuestionMark => "?",
|
CompilerDesugaringKind::Catch => "do catch",
|
||||||
Catch => "do catch",
|
CompilerDesugaringKind::ExistentialReturnType => "existental type",
|
||||||
ExistentialReturnType => "existental type",
|
})
|
||||||
};
|
|
||||||
Symbol::intern(s)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ extern crate unicode_width;
|
||||||
|
|
||||||
pub mod edition;
|
pub mod edition;
|
||||||
pub mod hygiene;
|
pub mod hygiene;
|
||||||
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, NameAndSpan, CompilerDesugaringKind};
|
pub use hygiene::{Mark, SyntaxContext, ExpnInfo, ExpnFormat, CompilerDesugaringKind};
|
||||||
|
|
||||||
mod span_encoding;
|
mod span_encoding;
|
||||||
pub use span_encoding::{Span, DUMMY_SP};
|
pub use span_encoding::{Span, DUMMY_SP};
|
||||||
|
@ -303,19 +303,19 @@ impl Span {
|
||||||
/// Edition of the crate from which this span came.
|
/// Edition of the crate from which this span came.
|
||||||
pub fn edition(self) -> edition::Edition {
|
pub fn edition(self) -> edition::Edition {
|
||||||
self.ctxt().outer().expn_info().map_or_else(|| hygiene::default_edition(),
|
self.ctxt().outer().expn_info().map_or_else(|| hygiene::default_edition(),
|
||||||
|einfo| einfo.callee.edition)
|
|einfo| einfo.edition)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the source callee.
|
/// Return the source callee.
|
||||||
///
|
///
|
||||||
/// Returns None if the supplied span has no expansion trace,
|
/// Returns `None` if the supplied span has no expansion trace,
|
||||||
/// else returns the NameAndSpan for the macro definition
|
/// else returns the `ExpnInfo` for the macro definition
|
||||||
/// corresponding to the source callsite.
|
/// corresponding to the source callsite.
|
||||||
pub fn source_callee(self) -> Option<NameAndSpan> {
|
pub fn source_callee(self) -> Option<ExpnInfo> {
|
||||||
fn source_callee(info: ExpnInfo) -> NameAndSpan {
|
fn source_callee(info: ExpnInfo) -> ExpnInfo {
|
||||||
match info.call_site.ctxt().outer().expn_info() {
|
match info.call_site.ctxt().outer().expn_info() {
|
||||||
Some(info) => source_callee(info),
|
Some(info) => source_callee(info),
|
||||||
None => info.callee,
|
None => info,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.ctxt().outer().expn_info().map(source_callee)
|
self.ctxt().outer().expn_info().map(source_callee)
|
||||||
|
@ -326,7 +326,7 @@ impl Span {
|
||||||
/// `#[allow_internal_unstable]`).
|
/// `#[allow_internal_unstable]`).
|
||||||
pub fn allows_unstable(&self) -> bool {
|
pub fn allows_unstable(&self) -> bool {
|
||||||
match self.ctxt().outer().expn_info() {
|
match self.ctxt().outer().expn_info() {
|
||||||
Some(info) => info.callee.allow_internal_unstable,
|
Some(info) => info.allow_internal_unstable,
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ impl Span {
|
||||||
/// Check if this span arises from a compiler desugaring of kind `kind`.
|
/// Check if this span arises from a compiler desugaring of kind `kind`.
|
||||||
pub fn is_compiler_desugaring(&self, kind: CompilerDesugaringKind) -> bool {
|
pub fn is_compiler_desugaring(&self, kind: CompilerDesugaringKind) -> bool {
|
||||||
match self.ctxt().outer().expn_info() {
|
match self.ctxt().outer().expn_info() {
|
||||||
Some(info) => match info.callee.format {
|
Some(info) => match info.format {
|
||||||
ExpnFormat::CompilerDesugaring(k) => k == kind,
|
ExpnFormat::CompilerDesugaring(k) => k == kind,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
|
@ -346,7 +346,7 @@ impl Span {
|
||||||
/// if this span is not from a desugaring.
|
/// if this span is not from a desugaring.
|
||||||
pub fn compiler_desugaring_kind(&self) -> Option<CompilerDesugaringKind> {
|
pub fn compiler_desugaring_kind(&self) -> Option<CompilerDesugaringKind> {
|
||||||
match self.ctxt().outer().expn_info() {
|
match self.ctxt().outer().expn_info() {
|
||||||
Some(info) => match info.callee.format {
|
Some(info) => match info.format {
|
||||||
ExpnFormat::CompilerDesugaring(k) => Some(k),
|
ExpnFormat::CompilerDesugaring(k) => Some(k),
|
||||||
_ => None
|
_ => None
|
||||||
},
|
},
|
||||||
|
@ -359,7 +359,7 @@ impl Span {
|
||||||
// (that is, a macro marked with `#[allow_internal_unsafe]`).
|
// (that is, a macro marked with `#[allow_internal_unsafe]`).
|
||||||
pub fn allows_unsafe(&self) -> bool {
|
pub fn allows_unsafe(&self) -> bool {
|
||||||
match self.ctxt().outer().expn_info() {
|
match self.ctxt().outer().expn_info() {
|
||||||
Some(info) => info.callee.allow_internal_unsafe,
|
Some(info) => info.allow_internal_unsafe,
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,20 +368,17 @@ impl Span {
|
||||||
let mut prev_span = DUMMY_SP;
|
let mut prev_span = DUMMY_SP;
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
while let Some(info) = self.ctxt().outer().expn_info() {
|
while let Some(info) = self.ctxt().outer().expn_info() {
|
||||||
let (pre, post) = match info.callee.format {
|
|
||||||
ExpnFormat::MacroAttribute(..) => ("#[", "]"),
|
|
||||||
ExpnFormat::MacroBang(..) => ("", "!"),
|
|
||||||
ExpnFormat::CompilerDesugaring(..) => ("desugaring of `", "`"),
|
|
||||||
};
|
|
||||||
let macro_decl_name = format!("{}{}{}", pre, info.callee.name(), post);
|
|
||||||
let def_site_span = info.callee.span;
|
|
||||||
|
|
||||||
// Don't print recursive invocations
|
// Don't print recursive invocations
|
||||||
if !info.call_site.source_equal(&prev_span) {
|
if !info.call_site.source_equal(&prev_span) {
|
||||||
|
let (pre, post) = match info.format {
|
||||||
|
ExpnFormat::MacroAttribute(..) => ("#[", "]"),
|
||||||
|
ExpnFormat::MacroBang(..) => ("", "!"),
|
||||||
|
ExpnFormat::CompilerDesugaring(..) => ("desugaring of `", "`"),
|
||||||
|
};
|
||||||
result.push(MacroBacktrace {
|
result.push(MacroBacktrace {
|
||||||
call_site: info.call_site,
|
call_site: info.call_site,
|
||||||
macro_decl_name,
|
macro_decl_name: format!("{}{}{}", pre, info.format.name(), post),
|
||||||
def_site_span,
|
def_site_span: info.def_site,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue