diff options
Diffstat (limited to 'compiler/rustc_span/src/hygiene.rs')
| -rw-r--r-- | compiler/rustc_span/src/hygiene.rs | 52 |
1 files changed, 48 insertions, 4 deletions
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 0f82db1d05a..1fb5642912f 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -622,6 +622,10 @@ impl SyntaxContext { pub fn dollar_crate_name(self) -> Symbol { HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name) } + + pub fn edition(self) -> Edition { + self.outer_expn_data().edition + } } impl fmt::Debug for SyntaxContext { @@ -650,6 +654,20 @@ impl Span { self.with_ctxt(data.apply_mark(SyntaxContext::root(), expn_id, transparency)) }) } + + /// Reuses the span but adds information like the kind of the desugaring and features that are + /// allowed inside this span. + pub fn mark_with_reason( + self, + allow_internal_unstable: Option<Lrc<[Symbol]>>, + reason: DesugaringKind, + edition: Edition, + ) -> Span { + self.fresh_expansion(ExpnData { + allow_internal_unstable, + ..ExpnData::default(ExpnKind::Desugaring(reason), self, edition, None) + }) + } } /// A subset of properties from both macro definition and macro call available through global data. @@ -699,7 +717,7 @@ pub struct ExpnData { /// created locally - when our serialized metadata is decoded, /// foreign `ExpnId`s will have their `ExpnData` looked up /// from the crate specified by `Crate - pub krate: CrateNum, + krate: CrateNum, /// The raw that this `ExpnData` had in its original crate. /// An `ExpnData` can be created before being assigned an `ExpnId`, /// so this might be `None` until `set_expn_data` is called @@ -707,13 +725,39 @@ pub struct ExpnData { // two `ExpnData`s that differ only in their `orig_id` should // be considered equivalent. #[stable_hasher(ignore)] - pub orig_id: Option<u32>, + orig_id: Option<u32>, } // This would require special handling of `orig_id` and `parent` impl !PartialEq for ExpnData {} impl ExpnData { + pub fn new( + kind: ExpnKind, + parent: ExpnId, + call_site: Span, + def_site: Span, + allow_internal_unstable: Option<Lrc<[Symbol]>>, + allow_internal_unsafe: bool, + local_inner_macros: bool, + edition: Edition, + macro_def_id: Option<DefId>, + ) -> ExpnData { + ExpnData { + kind, + parent, + call_site, + def_site, + allow_internal_unstable, + allow_internal_unsafe, + local_inner_macros, + edition, + macro_def_id, + krate: LOCAL_CRATE, + orig_id: None, + } + } + /// Constructs expansion data with default properties. pub fn default( kind: ExpnKind, @@ -1065,7 +1109,7 @@ pub fn decode_syntax_context< parent: SyntaxContext::root(), opaque: SyntaxContext::root(), opaque_and_semitransparent: SyntaxContext::root(), - dollar_crate_name: kw::Invalid, + dollar_crate_name: kw::Empty, }); let mut ctxts = outer_ctxts.lock(); let new_len = raw_id as usize + 1; @@ -1092,7 +1136,7 @@ pub fn decode_syntax_context< ctxt_data, ); // Make sure nothing weird happening while `decode_data` was running - assert_eq!(dummy.dollar_crate_name, kw::Invalid); + assert_eq!(dummy.dollar_crate_name, kw::Empty); }); Ok(new_ctxt) |
