Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/mod_path.rs')
| -rw-r--r-- | crates/hir-expand/src/mod_path.rs | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs index 75b5861454..72a5627636 100644 --- a/crates/hir-expand/src/mod_path.rs +++ b/crates/hir-expand/src/mod_path.rs @@ -7,15 +7,15 @@ use std::{ use crate::{ db::ExpandDatabase, - hygiene::{marks_rev, SyntaxContextExt, Transparency}, + hygiene::{SyntaxContextExt, Transparency, marks_rev}, name::{AsName, Name}, tt, }; -use base_db::CrateId; +use base_db::Crate; use intern::sym; use smallvec::SmallVec; -use span::{Edition, SyntaxContextId}; -use syntax::{ast, AstNode}; +use span::{Edition, SyntaxContext}; +use syntax::{AstNode, ast}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ModPath { @@ -33,7 +33,7 @@ pub enum PathKind { Abs, // FIXME: Can we remove this somehow? /// `$crate` from macro expansion - DollarCrate(CrateId), + DollarCrate(Crate), } impl PathKind { @@ -44,7 +44,7 @@ impl ModPath { pub fn from_src( db: &dyn ExpandDatabase, path: ast::Path, - span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, + span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext, ) -> Option<ModPath> { convert_path(db, path, span_for_range) } @@ -111,8 +111,7 @@ impl ModPath { #[allow(non_snake_case)] pub fn is_Self(&self) -> bool { - self.kind == PathKind::Plain - && matches!(&*self.segments, [name] if *name == sym::Self_.clone()) + self.kind == PathKind::Plain && matches!(&*self.segments, [name] if *name == sym::Self_) } /// If this path is a single identifier, like `foo`, return its name. @@ -209,7 +208,7 @@ fn display_fmt_path( fn convert_path( db: &dyn ExpandDatabase, path: ast::Path, - span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContextId, + span_for_range: &mut dyn FnMut(::tt::TextRange) -> SyntaxContext, ) -> Option<ModPath> { let mut segments = path.segments(); @@ -251,7 +250,7 @@ fn convert_path( } } ast::PathSegmentKind::SelfTypeKw => { - ModPath::from_segments(PathKind::Plain, Some(Name::new_symbol_root(sym::Self_.clone()))) + ModPath::from_segments(PathKind::Plain, Some(Name::new_symbol_root(sym::Self_))) } ast::PathSegmentKind::CrateKw => ModPath::from_segments(PathKind::Crate, iter::empty()), ast::PathSegmentKind::SelfKw => handle_super_kw(0)?, @@ -277,8 +276,8 @@ fn convert_path( if mod_path.segments.len() == 1 && mod_path.kind == PathKind::Plain { if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) { let syn_ctx = span_for_range(segment.syntax().text_range()); - if let Some(macro_call_id) = db.lookup_intern_syntax_context(syn_ctx).outer_expn { - if db.lookup_intern_macro_call(macro_call_id).def.local_inner { + if let Some(macro_call_id) = syn_ctx.outer_expn(db) { + if db.lookup_intern_macro_call(macro_call_id.into()).def.local_inner { mod_path.kind = match resolve_crate_root(db, syn_ctx) { Some(crate_root) => PathKind::DollarCrate(crate_root), None => PathKind::Crate, @@ -333,10 +332,10 @@ fn convert_path_tt(db: &dyn ExpandDatabase, tt: tt::TokenTreesView<'_>) -> Optio Some(ModPath { kind, segments }) } -pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContextId) -> Option<CrateId> { +pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContext) -> Option<Crate> { // When resolving `$crate` from a `macro_rules!` invoked in a `macro`, // we don't want to pretend that the `macro_rules!` definition is in the `macro` - // as described in `SyntaxContext::apply_mark`, so we ignore prepended opaque marks. + // as described in `SyntaxContextId::apply_mark`, so we ignore prepended opaque marks. // FIXME: This is only a guess and it doesn't work correctly for `macro_rules!` // definitions actually produced by `macro` and `macro` definitions produced by // `macro_rules!`, but at least such configurations are not stable yet. @@ -353,7 +352,7 @@ pub fn resolve_crate_root(db: &dyn ExpandDatabase, mut ctxt: SyntaxContextId) -> result_mark = Some(mark); } - result_mark.map(|call| db.lookup_intern_macro_call(call).def.krate) + result_mark.map(|call| db.lookup_intern_macro_call(call.into()).def.krate) } pub use crate::name as __name; @@ -399,7 +398,7 @@ pub use crate::__path as path; macro_rules! __tool_path { ($start:ident $(:: $seg:ident)*) => ({ $crate::mod_path::ModPath::from_segments($crate::mod_path::PathKind::Plain, vec![ - $crate::name::Name::new_symbol_root($crate::intern::sym::rust_analyzer.clone()), $crate::name::Name::new_symbol_root($crate::intern::sym::$start.clone()), $($crate::name::Name::new_symbol_root($crate::intern::sym::$seg.clone()),)* + $crate::name::Name::new_symbol_root($crate::intern::sym::rust_analyzer), $crate::name::Name::new_symbol_root($crate::intern::sym::$start.clone()), $($crate::name::Name::new_symbol_root($crate::intern::sym::$seg.clone()),)* ]) }); } |