Skip to content

Commit cbd4e3e

Browse files
committed
Minimize pub usage in hygiene.rs.
And remove dead functions revealed by this.
1 parent f4acf27 commit cbd4e3e

File tree

2 files changed

+15
-42
lines changed

2 files changed

+15
-42
lines changed

compiler/rustc_span/src/hygiene.rs

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,6 @@ impl ExpnHash {
125125
StableCrateId(self.0.split().0)
126126
}
127127

128-
/// Returns the crate-local part of the [ExpnHash].
129-
///
130-
/// Used for tests.
131-
#[inline]
132-
pub fn local_hash(self) -> Hash64 {
133-
self.0.split().1
134-
}
135-
136128
#[inline]
137129
pub fn is_root(self) -> bool {
138130
self.0 == Fingerprint::ZERO
@@ -170,7 +162,7 @@ impl LocalExpnId {
170162
pub const ROOT: LocalExpnId = LocalExpnId::from_u32(0);
171163

172164
#[inline]
173-
pub fn from_raw(idx: ExpnIndex) -> LocalExpnId {
165+
fn from_raw(idx: ExpnIndex) -> LocalExpnId {
174166
LocalExpnId::from_u32(idx.as_u32())
175167
}
176168

@@ -201,11 +193,6 @@ impl LocalExpnId {
201193
})
202194
}
203195

204-
#[inline]
205-
pub fn expn_hash(self) -> ExpnHash {
206-
HygieneData::with(|data| data.local_expn_hash(self))
207-
}
208-
209196
#[inline]
210197
pub fn expn_data(self) -> ExpnData {
211198
HygieneData::with(|data| data.local_expn_data(self).clone())
@@ -236,26 +223,13 @@ impl LocalExpnId {
236223
self.to_expn_id().is_descendant_of(ancestor.to_expn_id())
237224
}
238225

239-
/// `expn_id.outer_expn_is_descendant_of(ctxt)` is equivalent to but faster than
240-
/// `expn_id.is_descendant_of(ctxt.outer_expn())`.
241-
#[inline]
242-
pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool {
243-
self.to_expn_id().outer_expn_is_descendant_of(ctxt)
244-
}
245-
246226
/// Returns span for the macro which originally caused this expansion to happen.
247227
///
248228
/// Stops backtracing at include! boundary.
249229
#[inline]
250230
pub fn expansion_cause(self) -> Option<Span> {
251231
self.to_expn_id().expansion_cause()
252232
}
253-
254-
#[inline]
255-
#[track_caller]
256-
pub fn parent(self) -> LocalExpnId {
257-
self.expn_data().parent.as_local().unwrap()
258-
}
259233
}
260234

261235
impl ExpnId {
@@ -330,7 +304,7 @@ impl ExpnId {
330304
}
331305

332306
#[derive(Debug)]
333-
pub struct HygieneData {
307+
pub(crate) struct HygieneData {
334308
/// Each expansion should have an associated expansion data, but sometimes there's a delay
335309
/// between creation of an expansion ID and obtaining its data (e.g. macros are collected
336310
/// first and then resolved later), so we use an `Option` here.
@@ -381,15 +355,10 @@ impl HygieneData {
381355
}
382356
}
383357

384-
pub fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
358+
fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
385359
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
386360
}
387361

388-
#[inline]
389-
fn local_expn_hash(&self, expn_id: LocalExpnId) -> ExpnHash {
390-
self.local_expn_hashes[expn_id]
391-
}
392-
393362
#[inline]
394363
fn expn_hash(&self, expn_id: ExpnId) -> ExpnHash {
395364
match expn_id.as_local() {
@@ -743,7 +712,7 @@ impl SyntaxContext {
743712
}
744713

745714
/// Like `SyntaxContext::adjust`, but also normalizes `self` to macros 2.0.
746-
pub fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
715+
pub(crate) fn normalize_to_macros_2_0_and_adjust(&mut self, expn_id: ExpnId) -> Option<ExpnId> {
747716
HygieneData::with(|data| {
748717
*self = data.normalize_to_macros_2_0(*self);
749718
data.adjust(self, expn_id)
@@ -776,7 +745,11 @@ impl SyntaxContext {
776745
/// ```
777746
/// This returns `None` if the context cannot be glob-adjusted.
778747
/// Otherwise, it returns the scope to use when privacy checking (see `adjust` for details).
779-
pub fn glob_adjust(&mut self, expn_id: ExpnId, glob_span: Span) -> Option<Option<ExpnId>> {
748+
pub(crate) fn glob_adjust(
749+
&mut self,
750+
expn_id: ExpnId,
751+
glob_span: Span,
752+
) -> Option<Option<ExpnId>> {
780753
HygieneData::with(|data| {
781754
let mut scope = None;
782755
let mut glob_ctxt = data.normalize_to_macros_2_0(glob_span.ctxt());
@@ -800,7 +773,7 @@ impl SyntaxContext {
800773
/// assert!(self.glob_adjust(expansion, glob_ctxt) == Some(privacy_checking_scope));
801774
/// }
802775
/// ```
803-
pub fn reverse_glob_adjust(
776+
pub(crate) fn reverse_glob_adjust(
804777
&mut self,
805778
expn_id: ExpnId,
806779
glob_span: Span,
@@ -855,11 +828,11 @@ impl SyntaxContext {
855828
}
856829

857830
#[inline]
858-
pub fn outer_mark(self) -> (ExpnId, Transparency) {
831+
fn outer_mark(self) -> (ExpnId, Transparency) {
859832
HygieneData::with(|data| data.outer_mark(self))
860833
}
861834

862-
pub fn dollar_crate_name(self) -> Symbol {
835+
pub(crate) fn dollar_crate_name(self) -> Symbol {
863836
HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name)
864837
}
865838

@@ -958,12 +931,12 @@ pub struct ExpnData {
958931
/// The normal module (`mod`) in which the expanded macro was defined.
959932
pub parent_module: Option<DefId>,
960933
/// Suppresses the `unsafe_code` lint for code produced by this macro.
961-
pub allow_internal_unsafe: bool,
934+
pub(crate) allow_internal_unsafe: bool,
962935
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
963936
pub local_inner_macros: bool,
964937
/// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
965938
/// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
966-
pub collapse_debuginfo: bool,
939+
pub(crate) collapse_debuginfo: bool,
967940
}
968941

969942
impl !PartialEq for ExpnData {}

compiler/rustc_span/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ impl Span {
954954
/// Produces a span with the same location as `self` and context produced by a macro with the
955955
/// given ID and transparency, assuming that macro was defined directly and not produced by
956956
/// some other macro (which is the case for built-in and procedural macros).
957-
pub fn with_ctxt_from_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
957+
fn with_ctxt_from_mark(self, expn_id: ExpnId, transparency: Transparency) -> Span {
958958
self.with_ctxt(SyntaxContext::root().apply_mark(expn_id, transparency))
959959
}
960960

0 commit comments

Comments
 (0)