mirror of
				https://github.com/rust-lang/rust-analyzer.git
				synced 2025-10-31 12:04:43 +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
				
			
		|  | @ -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, | ||||
|  |  | |||
|  | @ -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) | ||||
|         }) | ||||
| } | ||||
|  |  | |||
|  | @ -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() { | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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
	
	 Lukas Wirth
						Lukas Wirth