Skip to content

Commit 188bd82

Browse files
committed
refactor: Remove unnecessary extension trait
1 parent d11dbf6 commit 188bd82

File tree

6 files changed

+61
-70
lines changed

6 files changed

+61
-70
lines changed

crates/hir-expand/src/db.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ use crate::{
1818
cfg_process,
1919
declarative::DeclarativeMacroExpander,
2020
fixup::{self, SyntaxFixupUndoInfo},
21-
hygiene::{
22-
SyntaxContextExt as _, span_with_call_site_ctxt, span_with_def_site_ctxt,
23-
span_with_mixed_site_ctxt,
24-
},
21+
hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt},
2522
proc_macro::{CrateProcMacros, CustomProcMacroExpander, ProcMacros},
2623
span_map::{ExpansionSpanMap, RealSpanMap, SpanMap, SpanMapRef},
2724
tt,

crates/hir-expand/src/hygiene.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// FIXME: Move this into the span crate? Not quite possible today as that depends on `MacroCallLoc`
2323
// which contains a bunch of unrelated things
2424

25-
use std::{convert::identity, iter};
25+
use std::convert::identity;
2626

2727
use span::{Edition, MacroCallId, Span, SyntaxContext};
2828

@@ -141,61 +141,3 @@ fn apply_mark_internal(
141141
|_| opaque_and_semitransparent,
142142
)
143143
}
144-
145-
pub trait SyntaxContextExt {
146-
fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
147-
fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
148-
fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
149-
fn remove_mark(&mut self, db: &dyn ExpandDatabase)
150-
-> (Option<span::MacroCallId>, Transparency);
151-
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency);
152-
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(span::MacroCallId, Transparency)>;
153-
fn is_opaque(self, db: &dyn ExpandDatabase) -> bool;
154-
}
155-
156-
impl SyntaxContextExt for SyntaxContext {
157-
fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
158-
self.opaque_and_semitransparent(db)
159-
}
160-
fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
161-
self.opaque(db)
162-
}
163-
fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
164-
self.parent(db)
165-
}
166-
fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency) {
167-
let data = self;
168-
(data.outer_expn(db), data.outer_transparency(db))
169-
}
170-
fn remove_mark(
171-
&mut self,
172-
db: &dyn ExpandDatabase,
173-
) -> (Option<span::MacroCallId>, Transparency) {
174-
let data = *self;
175-
*self = data.parent(db);
176-
(data.outer_expn(db), data.outer_transparency(db))
177-
}
178-
fn marks(self, db: &dyn ExpandDatabase) -> Vec<(span::MacroCallId, Transparency)> {
179-
let mut marks = marks_rev(self, db).collect::<Vec<_>>();
180-
marks.reverse();
181-
marks
182-
}
183-
fn is_opaque(self, db: &dyn ExpandDatabase) -> bool {
184-
!self.is_root() && self.outer_transparency(db).is_opaque()
185-
}
186-
}
187-
188-
// FIXME: Make this a SyntaxContextExt method once we have RPIT
189-
pub fn marks_rev(
190-
ctxt: SyntaxContext,
191-
db: &dyn ExpandDatabase,
192-
) -> impl Iterator<Item = (span::MacroCallId, Transparency)> + '_ {
193-
iter::successors(Some(ctxt), move |&mark| Some(mark.parent_ctxt(db)))
194-
.take_while(|&it| !it.is_root())
195-
.map(|ctx| {
196-
let mark = ctx.outer_mark(db);
197-
// We stop before taking the root expansion, as such we cannot encounter a `None` outer
198-
// expansion, as only the ROOT has it.
199-
(mark.0.unwrap(), mark.1)
200-
})
201-
}

crates/hir-expand/src/mod_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77

88
use crate::{
99
db::ExpandDatabase,
10-
hygiene::{SyntaxContextExt, Transparency, marks_rev},
10+
hygiene::Transparency,
1111
name::{AsName, Name},
1212
tt,
1313
};
@@ -340,7 +340,7 @@ pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContext) -> O
340340
// definitions actually produced by `macro` and `macro` definitions produced by
341341
// `macro_rules!`, but at least such configurations are not stable yet.
342342
ctxt = ctxt.normalize_to_macro_rules(db);
343-
let mut iter = marks_rev(ctxt, db).peekable();
343+
let mut iter = ctxt.marks_rev(db).peekable();
344344
let mut result_mark = None;
345345
// Find the last opaque mark from the end if it exists.
346346
while let Some(&(mark, Transparency::Opaque)) = iter.peek() {

crates/hir/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub use {
136136
HirFileRange, InFile, InFileWrapper, InMacroFile, InRealFile, MacroFilePosition,
137137
MacroFileRange,
138138
},
139-
hygiene::{SyntaxContextExt, marks_rev},
140139
inert_attr_macro::AttributeTemplate,
141140
mod_path::{ModPath, PathKind, tool_path},
142141
name::Name,

crates/hir/src/semantics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use hir_expand::{
2525
builtin::{BuiltinFnLikeExpander, EagerExpander},
2626
db::ExpandDatabase,
2727
files::{FileRangeWrapper, InRealFile},
28-
hygiene::SyntaxContextExt as _,
2928
inert_attr_macro::find_builtin_attr_idx,
3029
mod_path::{ModPath, PathKind},
3130
name::AsName,

crates/span/src/hygiene.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//! # The Call-site Hierarchy
2020
//!
2121
//! `ExpnData::call_site` in rustc, [`MacroCallLoc::call_site`] in rust-analyzer.
22-
use std::fmt;
22+
use std::{fmt, iter};
2323

2424
use crate::Edition;
2525

@@ -284,7 +284,7 @@ const _: () = {
284284
}
285285
};
286286

287-
impl SyntaxContext {
287+
impl<'db> SyntaxContext {
288288
#[inline]
289289
pub fn is_root(self) -> bool {
290290
(SyntaxContext::MAX_ID - Edition::LATEST as u32) <= self.into_u32()
@@ -308,7 +308,7 @@ impl SyntaxContext {
308308
}
309309

310310
#[cfg(feature = "salsa")]
311-
impl SyntaxContext {
311+
impl<'db> SyntaxContext {
312312
const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
313313

314314
#[inline]
@@ -340,6 +340,60 @@ impl SyntaxContext {
340340
// SAFETY: This comes from a Salsa ID.
341341
unsafe { Self::from_u32(id.as_u32()) }
342342
}
343+
344+
#[inline]
345+
pub fn outer_mark(
346+
self,
347+
db: &'db dyn salsa::Database,
348+
) -> (Option<crate::MacroCallId>, Transparency) {
349+
(self.outer_expn(db), self.outer_transparency(db))
350+
}
351+
352+
#[inline]
353+
pub fn normalize_to_macros_2_0(self, db: &'db dyn salsa::Database) -> SyntaxContext {
354+
self.opaque(db)
355+
}
356+
357+
#[inline]
358+
pub fn normalize_to_macro_rules(self, db: &'db dyn salsa::Database) -> SyntaxContext {
359+
self.opaque_and_semitransparent(db)
360+
}
361+
362+
pub fn is_opaque(self, db: &'db dyn salsa::Database) -> bool {
363+
!self.is_root() && self.outer_transparency(db).is_opaque()
364+
}
365+
366+
pub fn remove_mark(
367+
&mut self,
368+
db: &'db dyn salsa::Database,
369+
) -> (Option<crate::MacroCallId>, Transparency) {
370+
let data = *self;
371+
*self = data.parent(db);
372+
(data.outer_expn(db), data.outer_transparency(db))
373+
}
374+
375+
pub fn marks(
376+
self,
377+
db: &'db dyn salsa::Database,
378+
) -> impl Iterator<Item = (crate::MacroCallId, Transparency)> {
379+
let mut marks = self.marks_rev(db).collect::<Vec<_>>();
380+
marks.reverse();
381+
marks.into_iter()
382+
}
383+
384+
pub fn marks_rev(
385+
self,
386+
db: &'db dyn salsa::Database,
387+
) -> impl Iterator<Item = (crate::MacroCallId, Transparency)> {
388+
iter::successors(Some(self), move |&mark| Some(mark.parent(db)))
389+
.take_while(|&it| !it.is_root())
390+
.map(|ctx| {
391+
let mark = ctx.outer_mark(db);
392+
// We stop before taking the root expansion, as such we cannot encounter a `None` outer
393+
// expansion, as only the ROOT has it.
394+
(mark.0.unwrap(), mark.1)
395+
})
396+
}
343397
}
344398
#[cfg(not(feature = "salsa"))]
345399
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]

0 commit comments

Comments
 (0)