about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2025-04-29 13:09:19 +0200
committerLukas Wirth <lukastw97@gmail.com>2025-04-29 13:53:57 +0200
commit21e7003a025419af87bb315dc394beee0ba391e5 (patch)
tree7de01a36c6c18575d306bf112aba900693a88123
parent97f0f68769f424b9149fc52225eb6fecaefe7808 (diff)
downloadrust-21e7003a025419af87bb315dc394beee0ba391e5.tar.gz
rust-21e7003a025419af87bb315dc394beee0ba391e5.zip
refactor: Remove unnecessary extension trait
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/db.rs5
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs60
-rw-r--r--src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs4
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/lib.rs1
-rw-r--r--src/tools/rust-analyzer/crates/hir/src/semantics.rs1
-rw-r--r--src/tools/rust-analyzer/crates/span/src/hygiene.rs56
6 files changed, 59 insertions, 68 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/db.rs b/src/tools/rust-analyzer/crates/hir-expand/src/db.rs
index 2219a55a84b..67391dbd955 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/db.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/db.rs
@@ -18,10 +18,7 @@ use crate::{
     cfg_process,
     declarative::DeclarativeMacroExpander,
     fixup::{self, SyntaxFixupUndoInfo},
-    hygiene::{
-        SyntaxContextExt as _, span_with_call_site_ctxt, span_with_def_site_ctxt,
-        span_with_mixed_site_ctxt,
-    },
+    hygiene::{span_with_call_site_ctxt, span_with_def_site_ctxt, span_with_mixed_site_ctxt},
     proc_macro::{CrateProcMacros, CustomProcMacroExpander, ProcMacros},
     span_map::{ExpansionSpanMap, RealSpanMap, SpanMap, SpanMapRef},
     tt,
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs b/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs
index e7856920bc4..28800c6fabd 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/hygiene.rs
@@ -22,7 +22,7 @@
 // FIXME: Move this into the span crate? Not quite possible today as that depends on `MacroCallLoc`
 // which contains a bunch of unrelated things
 
-use std::{convert::identity, iter};
+use std::convert::identity;
 
 use span::{Edition, MacroCallId, Span, SyntaxContext};
 
@@ -141,61 +141,3 @@ fn apply_mark_internal(
         |_| opaque_and_semitransparent,
     )
 }
-
-pub trait SyntaxContextExt {
-    fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
-    fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
-    fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext;
-    fn remove_mark(&mut self, db: &dyn ExpandDatabase)
-    -> (Option<span::MacroCallId>, Transparency);
-    fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency);
-    fn marks(self, db: &dyn ExpandDatabase) -> Vec<(span::MacroCallId, Transparency)>;
-    fn is_opaque(self, db: &dyn ExpandDatabase) -> bool;
-}
-
-impl SyntaxContextExt for SyntaxContext {
-    fn normalize_to_macro_rules(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
-        self.opaque_and_semitransparent(db)
-    }
-    fn normalize_to_macros_2_0(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
-        self.opaque(db)
-    }
-    fn parent_ctxt(self, db: &dyn ExpandDatabase) -> span::SyntaxContext {
-        self.parent(db)
-    }
-    fn outer_mark(self, db: &dyn ExpandDatabase) -> (Option<span::MacroCallId>, Transparency) {
-        let data = self;
-        (data.outer_expn(db), data.outer_transparency(db))
-    }
-    fn remove_mark(
-        &mut self,
-        db: &dyn ExpandDatabase,
-    ) -> (Option<span::MacroCallId>, Transparency) {
-        let data = *self;
-        *self = data.parent(db);
-        (data.outer_expn(db), data.outer_transparency(db))
-    }
-    fn marks(self, db: &dyn ExpandDatabase) -> Vec<(span::MacroCallId, Transparency)> {
-        let mut marks = marks_rev(self, db).collect::<Vec<_>>();
-        marks.reverse();
-        marks
-    }
-    fn is_opaque(self, db: &dyn ExpandDatabase) -> bool {
-        !self.is_root() && self.outer_transparency(db).is_opaque()
-    }
-}
-
-// FIXME: Make this a SyntaxContextExt method once we have RPIT
-pub fn marks_rev(
-    ctxt: SyntaxContext,
-    db: &dyn ExpandDatabase,
-) -> impl Iterator<Item = (span::MacroCallId, Transparency)> + '_ {
-    iter::successors(Some(ctxt), move |&mark| Some(mark.parent_ctxt(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)
-        })
-}
diff --git a/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs b/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs
index 72a5627636b..9f1e3879e1e 100644
--- a/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs
+++ b/src/tools/rust-analyzer/crates/hir-expand/src/mod_path.rs
@@ -7,7 +7,7 @@ use std::{
 
 use crate::{
     db::ExpandDatabase,
-    hygiene::{SyntaxContextExt, Transparency, marks_rev},
+    hygiene::Transparency,
     name::{AsName, Name},
     tt,
 };
@@ -340,7 +340,7 @@ pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContext) -> O
     // definitions actually produced by `macro` and `macro` definitions produced by
     // `macro_rules!`, but at least such configurations are not stable yet.
     ctxt = ctxt.normalize_to_macro_rules(db);
-    let mut iter = marks_rev(ctxt, db).peekable();
+    let mut iter = ctxt.marks_rev(db).peekable();
     let mut result_mark = None;
     // Find the last opaque mark from the end if it exists.
     while let Some(&(mark, Transparency::Opaque)) = iter.peek() {
diff --git a/src/tools/rust-analyzer/crates/hir/src/lib.rs b/src/tools/rust-analyzer/crates/hir/src/lib.rs
index c62e4cf4497..d7754bf2e23 100644
--- a/src/tools/rust-analyzer/crates/hir/src/lib.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/lib.rs
@@ -136,7 +136,6 @@ pub use {
             HirFileRange, InFile, InFileWrapper, InMacroFile, InRealFile, MacroFilePosition,
             MacroFileRange,
         },
-        hygiene::{SyntaxContextExt, marks_rev},
         inert_attr_macro::AttributeTemplate,
         mod_path::{ModPath, PathKind, tool_path},
         name::Name,
diff --git a/src/tools/rust-analyzer/crates/hir/src/semantics.rs b/src/tools/rust-analyzer/crates/hir/src/semantics.rs
index f708f2e1667..2e693559e29 100644
--- a/src/tools/rust-analyzer/crates/hir/src/semantics.rs
+++ b/src/tools/rust-analyzer/crates/hir/src/semantics.rs
@@ -25,7 +25,6 @@ use hir_expand::{
     builtin::{BuiltinFnLikeExpander, EagerExpander},
     db::ExpandDatabase,
     files::{FileRangeWrapper, InRealFile},
-    hygiene::SyntaxContextExt as _,
     inert_attr_macro::find_builtin_attr_idx,
     mod_path::{ModPath, PathKind},
     name::AsName,
diff --git a/src/tools/rust-analyzer/crates/span/src/hygiene.rs b/src/tools/rust-analyzer/crates/span/src/hygiene.rs
index b21102f2db7..d1e75d97d7a 100644
--- a/src/tools/rust-analyzer/crates/span/src/hygiene.rs
+++ b/src/tools/rust-analyzer/crates/span/src/hygiene.rs
@@ -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)]