From 93aa166748eef9560df2435391dc3f3b53f8262d Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 24 Jan 2020 19:35:09 +0100 Subject: wip lower impl trait to type args --- crates/ra_hir_ty/src/infer/expr.rs | 4 ++-- crates/ra_hir_ty/src/lib.rs | 2 +- crates/ra_hir_ty/src/lower.rs | 1 + crates/ra_hir_ty/src/utils.rs | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 31259a01d..97cb20cea 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -10,7 +10,7 @@ use hir_def::{ resolver::resolver_for_expr, AdtId, AssocContainerId, Lookup, StructFieldId, }; -use hir_expand::name::{name, Name}; +use hir_expand::name::Name; use ra_syntax::ast::RangeOp; use crate::{ @@ -654,7 +654,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // Parent arguments are unknown, except for the receiver type if let Some(parent_generics) = def_generics.as_ref().map(|p| p.iter_parent()) { for (_id, param) in parent_generics { - if param.name == name![Self] { + if param.provenance == hir_def::generics::TypeParamProvenance::TraitSelf { substs.push(receiver_ty.clone()); } else { substs.push(Ty::Unknown); diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index c64b81f98..cb7a60352 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -368,7 +368,7 @@ impl Substs { /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). pub(crate) fn identity(generic_params: &Generics) -> Substs { Substs( - generic_params.iter().map(|(idx, p)| Ty::Param { idx, name: p.name.clone() }).collect(), + generic_params.iter().map(|(idx, p)| Ty::Param { idx, name: p.name.clone().unwrap_or_else(Name::missing) }).collect(), ) } diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index 39406d8ce..6f7681475 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -341,6 +341,7 @@ pub(super) fn substs_from_path_segment( // Self type as an implicit first type parameter, but it can't be // actually provided in the type arguments // (well, actually sometimes it can, in the form of type-relative paths: `::default()`) + // TODO handle this using type param provenance substs.push(Ty::Unknown); } if let Some(generic_args) = &segment.args_and_bindings { diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index 0b1806a84..314a3241f 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs @@ -127,7 +127,8 @@ impl Generics { self.find_param(param).0 } pub(crate) fn param_name(&self, param: TypeParamId) -> Name { - self.find_param(param).1.name.clone() + // FIXME make this return Option + self.find_param(param).1.name.clone().unwrap_or_else(Name::missing) } fn find_param(&self, param: TypeParamId) -> (u32, &TypeParamData) { if param.parent == self.def { -- cgit v1.2.3