Move store TypeRef of type based path in PathKind

This commit is contained in:
uHOOCCOOHu 2019-09-15 19:48:24 +08:00
parent 4926bed426
commit de9670fe45
No known key found for this signature in database
GPG Key ID: CED392DE0C483D00
4 changed files with 11 additions and 21 deletions
crates

@ -512,7 +512,7 @@ pub fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> {
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());

@ -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);

@ -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<Box<TypeRef>>,
pub segments: Vec<PathSegment>,
}
@ -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 `<T>::foo`
Type,
Type(Box<TypeRef>),
}
impl Path {
@ -69,7 +68,6 @@ impl Path {
pub fn from_simple_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> 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<Path> {
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 {
// <T>::foo
None => {
kind = PathKind::Type;
path_type_ref = Some(Box::new(self_type));
kind = PathKind::Type(Box::new(self_type));
}
// <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::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<ast::Path> {
if let Some(q) = path.qualifier() {
@ -309,11 +305,8 @@ fn convert_path(prefix: Option<Path>, path: ast::Path) -> Option<Path> {
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

@ -190,7 +190,7 @@ impl Resolver {
db: &impl HirDatabase,
path: &'p Path,
) -> Option<ResolveValueResult<'p>> {
if let Some(type_ref) = &path.type_ref {
if let PathKind::Type(type_ref) = &path.kind {
return Some(ResolveValueResult::TypeRef(type_ref));
}