mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 02:52:11 +00:00
refactor: Remove unnecessary extension trait
This commit is contained in:
parent
d11dbf648f
commit
4cc6ee3f01
6 changed files with 59 additions and 68 deletions
|
|
@ -308,7 +308,7 @@ impl SyntaxContext {
|
|||
}
|
||||
|
||||
#[cfg(feature = "salsa")]
|
||||
impl SyntaxContext {
|
||||
impl<'db> SyntaxContext {
|
||||
const MAX_ID: u32 = salsa::Id::MAX_U32 - 1;
|
||||
|
||||
#[inline]
|
||||
|
|
@ -340,6 +340,60 @@ impl SyntaxContext {
|
|||
// SAFETY: This comes from a Salsa ID.
|
||||
unsafe { Self::from_u32(id.as_u32()) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn outer_mark(
|
||||
self,
|
||||
db: &'db dyn salsa::Database,
|
||||
) -> (Option<crate::MacroCallId>, Transparency) {
|
||||
(self.outer_expn(db), self.outer_transparency(db))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn normalize_to_macros_2_0(self, db: &'db dyn salsa::Database) -> SyntaxContext {
|
||||
self.opaque(db)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn normalize_to_macro_rules(self, db: &'db dyn salsa::Database) -> SyntaxContext {
|
||||
self.opaque_and_semitransparent(db)
|
||||
}
|
||||
|
||||
pub fn is_opaque(self, db: &'db dyn salsa::Database) -> bool {
|
||||
!self.is_root() && self.outer_transparency(db).is_opaque()
|
||||
}
|
||||
|
||||
pub fn remove_mark(
|
||||
&mut self,
|
||||
db: &'db dyn salsa::Database,
|
||||
) -> (Option<crate::MacroCallId>, Transparency) {
|
||||
let data = *self;
|
||||
*self = data.parent(db);
|
||||
(data.outer_expn(db), data.outer_transparency(db))
|
||||
}
|
||||
|
||||
pub fn marks(
|
||||
self,
|
||||
db: &'db dyn salsa::Database,
|
||||
) -> impl Iterator<Item = (crate::MacroCallId, Transparency)> {
|
||||
let mut marks = self.marks_rev(db).collect::<Vec<_>>();
|
||||
marks.reverse();
|
||||
marks.into_iter()
|
||||
}
|
||||
|
||||
pub fn marks_rev(
|
||||
self,
|
||||
db: &'db dyn salsa::Database,
|
||||
) -> impl Iterator<Item = (crate::MacroCallId, Transparency)> {
|
||||
std::iter::successors(Some(self), move |&mark| Some(mark.parent(db)))
|
||||
.take_while(|&it| !it.is_root())
|
||||
.map(|ctx| {
|
||||
let mark = ctx.outer_mark(db);
|
||||
// We stop before taking the root expansion, as such we cannot encounter a `None` outer
|
||||
// expansion, as only the ROOT has it.
|
||||
(mark.0.unwrap(), mark.1)
|
||||
})
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "salsa"))]
|
||||
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue