mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Auto merge of #80648 - Aaron1011:expn-data-private, r=petrochenkov
Make `ExpnData` fields `krate` and `orig_id` private These fields are only used by hygiene serialized, and should not be accessed by anything outside of `rustc_span`.
This commit is contained in:
commit
bf5f30684a
@ -57,7 +57,7 @@ use rustc_session::lint::{builtin::BARE_TRAIT_OBJECTS, BuiltinLintDiagnostics, L
|
||||
use rustc_session::parse::ParseSess;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::ExpnId;
|
||||
use rustc_span::source_map::{respan, DesugaringKind, ExpnData, ExpnKind};
|
||||
use rustc_span::source_map::{respan, DesugaringKind};
|
||||
use rustc_span::symbol::{kw, sym, Ident, Symbol};
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -743,10 +743,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
||||
span: Span,
|
||||
allow_internal_unstable: Option<Lrc<[Symbol]>>,
|
||||
) -> Span {
|
||||
span.fresh_expansion(ExpnData {
|
||||
allow_internal_unstable,
|
||||
..ExpnData::default(ExpnKind::Desugaring(reason), span, self.sess.edition(), None)
|
||||
})
|
||||
span.mark_with_reason(allow_internal_unstable, reason, self.sess.edition())
|
||||
}
|
||||
|
||||
fn with_anonymous_lifetime_mode<R>(
|
||||
|
@ -12,7 +12,7 @@ use rustc_data_structures::sync::{self, Lrc};
|
||||
use rustc_errors::{DiagnosticBuilder, ErrorReported};
|
||||
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
|
||||
use rustc_session::{parse::ParseSess, Limit, Session};
|
||||
use rustc_span::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::hygiene::{AstPass, ExpnData, ExpnId, ExpnKind};
|
||||
use rustc_span::source_map::SourceMap;
|
||||
@ -842,19 +842,17 @@ impl SyntaxExtension {
|
||||
descr: Symbol,
|
||||
macro_def_id: Option<DefId>,
|
||||
) -> ExpnData {
|
||||
ExpnData {
|
||||
kind: ExpnKind::Macro(self.macro_kind(), descr),
|
||||
ExpnData::new(
|
||||
ExpnKind::Macro(self.macro_kind(), descr),
|
||||
parent,
|
||||
call_site,
|
||||
def_site: self.span,
|
||||
allow_internal_unstable: self.allow_internal_unstable.clone(),
|
||||
allow_internal_unsafe: self.allow_internal_unsafe,
|
||||
local_inner_macros: self.local_inner_macros,
|
||||
edition: self.edition,
|
||||
self.span,
|
||||
self.allow_internal_unstable.clone(),
|
||||
self.allow_internal_unsafe,
|
||||
self.local_inner_macros,
|
||||
self.edition,
|
||||
macro_def_id,
|
||||
krate: LOCAL_CRATE,
|
||||
orig_id: None,
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1020,15 +1020,16 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||
// with exception of the derive container case which is not resolved and can get
|
||||
// its expansion data immediately.
|
||||
let expn_data = match &kind {
|
||||
InvocationKind::DeriveContainer { item, .. } => Some(ExpnData {
|
||||
parent: self.cx.current_expansion.id,
|
||||
..ExpnData::default(
|
||||
InvocationKind::DeriveContainer { item, .. } => {
|
||||
let mut expn_data = ExpnData::default(
|
||||
ExpnKind::Macro(MacroKind::Attr, sym::derive),
|
||||
item.span(),
|
||||
self.cx.sess.parse_sess.edition,
|
||||
None,
|
||||
)
|
||||
}),
|
||||
);
|
||||
expn_data.parent = self.cx.current_expansion.id;
|
||||
Some(expn_data)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let expn_id = ExpnId::fresh(expn_data);
|
||||
|
@ -742,11 +742,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_span(&mut self, span: &mut Span) {
|
||||
let mut expn_data =
|
||||
ExpnData::default(ExpnKind::Inlined, *span, self.tcx.sess.edition(), None);
|
||||
expn_data.def_site = self.body_span;
|
||||
// Make sure that all spans track the fact that they were inlined.
|
||||
*span = self.callsite_span.fresh_expansion(ExpnData {
|
||||
def_site: self.body_span,
|
||||
..ExpnData::default(ExpnKind::Inlined, *span, self.tcx.sess.edition(), None)
|
||||
});
|
||||
*span = self.callsite_span.fresh_expansion(expn_data);
|
||||
}
|
||||
|
||||
fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) {
|
||||
|
@ -650,6 +650,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 +713,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 +721,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,
|
||||
|
Loading…
Reference in New Issue
Block a user