From de9670fe456d89f97e8044d4e0919d2c16d1087f Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sun, 15 Sep 2019 19:48:24 +0800 Subject: Move store TypeRef of type based path in PathKind --- crates/ra_assists/src/auto_import.rs | 2 +- crates/ra_hir/src/nameres.rs | 9 +++------ crates/ra_hir/src/path.rs | 19 ++++++------------- crates/ra_hir/src/resolve.rs | 2 +- 4 files changed, 11 insertions(+), 21 deletions(-) (limited to 'crates') diff --git a/crates/ra_assists/src/auto_import.rs b/crates/ra_assists/src/auto_import.rs index 5ecda1ff5..5aae98546 100644 --- a/crates/ra_assists/src/auto_import.rs +++ b/crates/ra_assists/src/auto_import.rs @@ -512,7 +512,7 @@ pub fn collect_hir_path_segments(path: &hir::Path) -> Option> { hir::PathKind::Plain => {} hir::PathKind::Self_ => ps.push("self".into()), hir::PathKind::Super => ps.push("super".into()), - hir::PathKind::Type => return None, + hir::PathKind::Type(_) => return None, } for s in path.segments.iter() { ps.push(s.name.to_string().into()); diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index be1cc76b6..b808a0c36 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -382,7 +382,7 @@ impl CrateDefMap { return ResolvePathResult::empty(ReachedFixedPoint::No); // extern crate declarations can add to the extern prelude } } - PathKind::Type => { + PathKind::Type(_) => { // This is handled in `infer::infer_path_expr` // The result returned here does not matter return ResolvePathResult::empty(ReachedFixedPoint::Yes); @@ -406,11 +406,8 @@ impl CrateDefMap { curr_per_ns = match curr { ModuleDef::Module(module) => { if module.krate != self.krate { - let path = Path { - segments: path.segments[i..].to_vec(), - kind: PathKind::Self_, - type_ref: None, - }; + let path = + Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ }; log::debug!("resolving {:?} in other crate", path); let defp_map = db.crate_def_map(module.krate); let (def, s) = defp_map.resolve_path(db, module.module_id, &path); diff --git a/crates/ra_hir/src/path.rs b/crates/ra_hir/src/path.rs index 7c19fda14..9e449f6cc 100644 --- a/crates/ra_hir/src/path.rs +++ b/crates/ra_hir/src/path.rs @@ -10,7 +10,6 @@ use crate::{name, type_ref::TypeRef, AsName, Name}; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Path { pub kind: PathKind, - pub type_ref: Option>, pub segments: Vec, } @@ -43,7 +42,7 @@ pub enum GenericArg { // or lifetime... } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum PathKind { Plain, Self_, @@ -52,7 +51,7 @@ pub enum PathKind { // Absolute path Abs, // Type based path like `::foo` - Type, + Type(Box), } impl Path { @@ -69,7 +68,6 @@ impl Path { pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator) -> Path { Path { kind, - type_ref: None, segments: segments .into_iter() .map(|name| PathSegment { name, args_and_bindings: None }) @@ -81,7 +79,6 @@ impl Path { pub fn from_ast(mut path: ast::Path) -> Option { let mut kind = PathKind::Plain; let mut segments = Vec::new(); - let mut path_type_ref = None; loop { let segment = path.segment()?; @@ -112,8 +109,7 @@ impl Path { match trait_ref { // ::foo None => { - kind = PathKind::Type; - path_type_ref = Some(Box::new(self_type)); + kind = PathKind::Type(Box::new(self_type)); } // >::Foo desugars to Trait::Foo Some(trait_ref) => { @@ -154,7 +150,7 @@ impl Path { }; } segments.reverse(); - return Some(Path { kind, type_ref: path_type_ref, segments }); + return Some(Path { kind, segments }); fn qualifier(path: &ast::Path) -> Option { if let Some(q) = path.qualifier() { @@ -309,11 +305,8 @@ fn convert_path(prefix: Option, path: ast::Path) -> Option { let res = match segment.kind()? { ast::PathSegmentKind::Name(name) => { // no type args in use - let mut res = prefix.unwrap_or_else(|| Path { - kind: PathKind::Plain, - type_ref: None, - segments: Vec::with_capacity(1), - }); + let mut res = prefix + .unwrap_or_else(|| Path { kind: PathKind::Plain, segments: Vec::with_capacity(1) }); res.segments.push(PathSegment { name: name.as_name(), args_and_bindings: None, // no type args in use diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index e357c74e3..bb6915901 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -190,7 +190,7 @@ impl Resolver { db: &impl HirDatabase, path: &'p Path, ) -> Option> { - if let Some(type_ref) = &path.type_ref { + if let PathKind::Type(type_ref) = &path.kind { return Some(ResolveValueResult::TypeRef(type_ref)); } -- cgit v1.2.3