From 39d992ef559c9cd67551819a9d63ef52ef7b725f Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 1 Apr 2021 20:35:21 +0200 Subject: Intern Attr, MacroCall and Path components --- crates/hir_def/src/path.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/hir_def/src/path.rs') diff --git a/crates/hir_def/src/path.rs b/crates/hir_def/src/path.rs index 8c923bb7b..a3e83e2cf 100644 --- a/crates/hir_def/src/path.rs +++ b/crates/hir_def/src/path.rs @@ -7,7 +7,7 @@ use std::{ sync::Arc, }; -use crate::{body::LowerCtx, type_ref::LifetimeRef}; +use crate::{body::LowerCtx, intern::Interned, type_ref::LifetimeRef}; use base_db::CrateId; use hir_expand::{ hygiene::Hygiene, @@ -48,7 +48,7 @@ pub enum ImportAlias { impl ModPath { pub fn from_src(path: ast::Path, hygiene: &Hygiene) -> Option { - lower::lower_path(path, hygiene).map(|it| it.mod_path) + lower::lower_path(path, hygiene).map(|it| (*it.mod_path).clone()) } pub fn from_segments(kind: PathKind, segments: impl IntoIterator) -> ModPath { @@ -123,7 +123,7 @@ pub struct Path { /// Type based path like `::foo`. /// Note that paths like `::foo` are desugard to `Trait::::foo`. type_anchor: Option>, - mod_path: ModPath, + mod_path: Interned, /// Invariant: the same len as `self.mod_path.segments` generic_args: Vec>>, } @@ -176,7 +176,7 @@ impl Path { path: ModPath, generic_args: Vec>>, ) -> Path { - Path { type_anchor: None, mod_path: path, generic_args } + Path { type_anchor: None, mod_path: Interned::new(path), generic_args } } pub fn kind(&self) -> &PathKind { @@ -204,10 +204,10 @@ impl Path { } let res = Path { type_anchor: self.type_anchor.clone(), - mod_path: ModPath::from_segments( + mod_path: Interned::new(ModPath::from_segments( self.mod_path.kind.clone(), self.mod_path.segments[..self.mod_path.segments.len() - 1].iter().cloned(), - ), + )), generic_args: self.generic_args[..self.generic_args.len() - 1].to_vec(), }; Some(res) @@ -283,7 +283,7 @@ impl From for Path { fn from(name: Name) -> Path { Path { type_anchor: None, - mod_path: ModPath::from_segments(PathKind::Plain, iter::once(name)), + mod_path: Interned::new(ModPath::from_segments(PathKind::Plain, iter::once(name))), generic_args: vec![None], } } -- cgit v1.2.3