diff options
Diffstat (limited to 'crates/ra_hir_ty/src')
-rw-r--r-- | crates/ra_hir_ty/src/db.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/infer/expr.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 63 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/macros.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/method_resolution.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 28 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/builtin.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 8 |
10 files changed, 139 insertions, 38 deletions
diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index e9bfcfa17..85d85182f 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs | |||
@@ -11,7 +11,7 @@ use ra_db::{impl_intern_key, salsa, CrateId}; | |||
11 | use ra_prof::profile; | 11 | use ra_prof::profile; |
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | method_resolution::CrateImplBlocks, | 14 | method_resolution::CrateImplDefs, |
15 | traits::{chalk, AssocTyValue, Impl}, | 15 | traits::{chalk, AssocTyValue, Impl}, |
16 | Binders, CallableDef, GenericPredicate, InferenceResult, PolyFnSig, Substs, TraitRef, Ty, | 16 | Binders, CallableDef, GenericPredicate, InferenceResult, PolyFnSig, Substs, TraitRef, Ty, |
17 | TyDefId, TypeCtor, ValueTyDefId, | 17 | TyDefId, TypeCtor, ValueTyDefId, |
@@ -59,8 +59,8 @@ pub trait HirDatabase: DefDatabase { | |||
59 | #[salsa::invoke(crate::lower::generic_defaults_query)] | 59 | #[salsa::invoke(crate::lower::generic_defaults_query)] |
60 | fn generic_defaults(&self, def: GenericDefId) -> Substs; | 60 | fn generic_defaults(&self, def: GenericDefId) -> Substs; |
61 | 61 | ||
62 | #[salsa::invoke(crate::method_resolution::CrateImplBlocks::impls_in_crate_query)] | 62 | #[salsa::invoke(crate::method_resolution::CrateImplDefs::impls_in_crate_query)] |
63 | fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplBlocks>; | 63 | fn impls_in_crate(&self, krate: CrateId) -> Arc<CrateImplDefs>; |
64 | 64 | ||
65 | #[salsa::invoke(crate::traits::impls_for_trait_query)] | 65 | #[salsa::invoke(crate::traits::impls_for_trait_query)] |
66 | fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>; | 66 | fn impls_for_trait(&self, krate: CrateId, trait_: TraitId) -> Arc<[ImplId]>; |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 569d46cc3..377f44fa7 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -28,7 +28,7 @@ use hir_def::{ | |||
28 | path::{path, Path}, | 28 | path::{path, Path}, |
29 | resolver::{HasResolver, Resolver, TypeNs}, | 29 | resolver::{HasResolver, Resolver, TypeNs}, |
30 | type_ref::{Mutability, TypeRef}, | 30 | type_ref::{Mutability, TypeRef}, |
31 | AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TypeAliasId, VariantId, | 31 | AdtId, AssocItemId, DefWithBodyId, FunctionId, StructFieldId, TraitId, TypeAliasId, VariantId, |
32 | }; | 32 | }; |
33 | use hir_expand::{diagnostics::DiagnosticSink, name::name}; | 33 | use hir_expand::{diagnostics::DiagnosticSink, name::name}; |
34 | use ra_arena::map::ArenaMap; | 34 | use ra_arena::map::ArenaMap; |
@@ -540,8 +540,12 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
540 | Some(struct_.into()) | 540 | Some(struct_.into()) |
541 | } | 541 | } |
542 | 542 | ||
543 | fn resolve_ops_index(&self) -> Option<TraitId> { | ||
544 | self.resolve_lang_item("index")?.as_trait() | ||
545 | } | ||
546 | |||
543 | fn resolve_ops_index_output(&self) -> Option<TypeAliasId> { | 547 | fn resolve_ops_index_output(&self) -> Option<TypeAliasId> { |
544 | let trait_ = self.resolve_lang_item("index")?.as_trait()?; | 548 | let trait_ = self.resolve_ops_index()?; |
545 | self.db.trait_data(trait_).associated_type_by_name(&name![Output]) | 549 | self.db.trait_data(trait_).associated_type_by_name(&name![Output]) |
546 | } | 550 | } |
547 | } | 551 | } |
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 3db5b2b51..e89cc7298 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -429,11 +429,27 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
429 | let base_ty = self.infer_expr_inner(*base, &Expectation::none()); | 429 | let base_ty = self.infer_expr_inner(*base, &Expectation::none()); |
430 | let index_ty = self.infer_expr(*index, &Expectation::none()); | 430 | let index_ty = self.infer_expr(*index, &Expectation::none()); |
431 | 431 | ||
432 | self.resolve_associated_type_with_params( | 432 | if let (Some(index_trait), Some(krate)) = |
433 | base_ty, | 433 | (self.resolve_ops_index(), self.resolver.krate()) |
434 | self.resolve_ops_index_output(), | 434 | { |
435 | &[index_ty], | 435 | let canonicalized = self.canonicalizer().canonicalize_ty(base_ty); |
436 | ) | 436 | let self_ty = method_resolution::resolve_indexing_op( |
437 | self.db, | ||
438 | &canonicalized.value, | ||
439 | self.trait_env.clone(), | ||
440 | krate, | ||
441 | index_trait, | ||
442 | ); | ||
443 | let self_ty = | ||
444 | self_ty.map_or(Ty::Unknown, |t| canonicalized.decanonicalize_ty(t.value)); | ||
445 | self.resolve_associated_type_with_params( | ||
446 | self_ty, | ||
447 | self.resolve_ops_index_output(), | ||
448 | &[index_ty], | ||
449 | ) | ||
450 | } else { | ||
451 | Ty::Unknown | ||
452 | } | ||
437 | } | 453 | } |
438 | Expr::Tuple { exprs } => { | 454 | Expr::Tuple { exprs } => { |
439 | let mut tys = match &expected.ty { | 455 | let mut tys = match &expected.ty { |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 988d83af5..74b908c2e 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -20,7 +20,7 @@ use crate::{ | |||
20 | db::HirDatabase, | 20 | db::HirDatabase, |
21 | primitive::{FloatBitness, Uncertain}, | 21 | primitive::{FloatBitness, Uncertain}, |
22 | utils::all_super_traits, | 22 | utils::all_super_traits, |
23 | Canonical, InEnvironment, TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk, | 23 | ApplicationTy, Canonical, InEnvironment, TraitEnvironment, TraitRef, Ty, TypeCtor, TypeWalk, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | /// This is used as a key for indexing impls. | 26 | /// This is used as a key for indexing impls. |
@@ -42,19 +42,19 @@ impl TyFingerprint { | |||
42 | } | 42 | } |
43 | 43 | ||
44 | #[derive(Debug, PartialEq, Eq)] | 44 | #[derive(Debug, PartialEq, Eq)] |
45 | pub struct CrateImplBlocks { | 45 | pub struct CrateImplDefs { |
46 | impls: FxHashMap<TyFingerprint, Vec<ImplId>>, | 46 | impls: FxHashMap<TyFingerprint, Vec<ImplId>>, |
47 | impls_by_trait: FxHashMap<TraitId, Vec<ImplId>>, | 47 | impls_by_trait: FxHashMap<TraitId, Vec<ImplId>>, |
48 | } | 48 | } |
49 | 49 | ||
50 | impl CrateImplBlocks { | 50 | impl CrateImplDefs { |
51 | pub(crate) fn impls_in_crate_query( | 51 | pub(crate) fn impls_in_crate_query( |
52 | db: &impl HirDatabase, | 52 | db: &impl HirDatabase, |
53 | krate: CrateId, | 53 | krate: CrateId, |
54 | ) -> Arc<CrateImplBlocks> { | 54 | ) -> Arc<CrateImplDefs> { |
55 | let _p = profile("impls_in_crate_query"); | 55 | let _p = profile("impls_in_crate_query"); |
56 | let mut res = | 56 | let mut res = |
57 | CrateImplBlocks { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; | 57 | CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; |
58 | 58 | ||
59 | let crate_def_map = db.crate_def_map(krate); | 59 | let crate_def_map = db.crate_def_map(krate); |
60 | for (_module_id, module_data) in crate_def_map.modules.iter() { | 60 | for (_module_id, module_data) in crate_def_map.modules.iter() { |
@@ -75,12 +75,12 @@ impl CrateImplBlocks { | |||
75 | 75 | ||
76 | Arc::new(res) | 76 | Arc::new(res) |
77 | } | 77 | } |
78 | pub fn lookup_impl_blocks(&self, ty: &Ty) -> impl Iterator<Item = ImplId> + '_ { | 78 | pub fn lookup_impl_defs(&self, ty: &Ty) -> impl Iterator<Item = ImplId> + '_ { |
79 | let fingerprint = TyFingerprint::for_impl(ty); | 79 | let fingerprint = TyFingerprint::for_impl(ty); |
80 | fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flatten().copied() | 80 | fingerprint.and_then(|f| self.impls.get(&f)).into_iter().flatten().copied() |
81 | } | 81 | } |
82 | 82 | ||
83 | pub fn lookup_impl_blocks_for_trait(&self, tr: TraitId) -> impl Iterator<Item = ImplId> + '_ { | 83 | pub fn lookup_impl_defs_for_trait(&self, tr: TraitId) -> impl Iterator<Item = ImplId> + '_ { |
84 | self.impls_by_trait.get(&tr).into_iter().flatten().copied() | 84 | self.impls_by_trait.get(&tr).into_iter().flatten().copied() |
85 | } | 85 | } |
86 | 86 | ||
@@ -131,7 +131,7 @@ impl Ty { | |||
131 | let res = lang_item_targets | 131 | let res = lang_item_targets |
132 | .into_iter() | 132 | .into_iter() |
133 | .filter_map(|it| match it { | 133 | .filter_map(|it| match it { |
134 | LangItemTarget::ImplBlockId(it) => Some(it), | 134 | LangItemTarget::ImplDefId(it) => Some(it), |
135 | _ => None, | 135 | _ => None, |
136 | }) | 136 | }) |
137 | .map(|it| it.lookup(db).container.module(db).krate) | 137 | .map(|it| it.lookup(db).container.module(db).krate) |
@@ -177,7 +177,7 @@ pub enum LookupMode { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | // This would be nicer if it just returned an iterator, but that runs into | 179 | // This would be nicer if it just returned an iterator, but that runs into |
180 | // lifetime problems, because we need to borrow temp `CrateImplBlocks`. | 180 | // lifetime problems, because we need to borrow temp `CrateImplDefs`. |
181 | // FIXME add a context type here? | 181 | // FIXME add a context type here? |
182 | pub fn iterate_method_candidates<T>( | 182 | pub fn iterate_method_candidates<T>( |
183 | ty: &Canonical<Ty>, | 183 | ty: &Canonical<Ty>, |
@@ -214,7 +214,7 @@ pub fn iterate_method_candidates<T>( | |||
214 | // the methods by autoderef order of *receiver types*, not *self | 214 | // the methods by autoderef order of *receiver types*, not *self |
215 | // types*. | 215 | // types*. |
216 | 216 | ||
217 | let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect(); | 217 | let deref_chain = autoderef_method_receiver(db, krate, ty); |
218 | for i in 0..deref_chain.len() { | 218 | for i in 0..deref_chain.len() { |
219 | if let Some(result) = iterate_method_candidates_with_autoref( | 219 | if let Some(result) = iterate_method_candidates_with_autoref( |
220 | &deref_chain[i..], | 220 | &deref_chain[i..], |
@@ -425,8 +425,8 @@ fn iterate_inherent_methods<T>( | |||
425 | for krate in self_ty.value.def_crates(db, krate)? { | 425 | for krate in self_ty.value.def_crates(db, krate)? { |
426 | let impls = db.impls_in_crate(krate); | 426 | let impls = db.impls_in_crate(krate); |
427 | 427 | ||
428 | for impl_block in impls.lookup_impl_blocks(&self_ty.value) { | 428 | for impl_def in impls.lookup_impl_defs(&self_ty.value) { |
429 | for &item in db.impl_data(impl_block).items.iter() { | 429 | for &item in db.impl_data(impl_def).items.iter() { |
430 | if !is_valid_candidate(db, name, receiver_ty, item, self_ty) { | 430 | if !is_valid_candidate(db, name, receiver_ty, item, self_ty) { |
431 | continue; | 431 | continue; |
432 | } | 432 | } |
@@ -434,8 +434,7 @@ fn iterate_inherent_methods<T>( | |||
434 | // that the impl is for. If we have a receiver type, this | 434 | // that the impl is for. If we have a receiver type, this |
435 | // already happens in `is_valid_candidate` above; if not, we | 435 | // already happens in `is_valid_candidate` above; if not, we |
436 | // check it here | 436 | // check it here |
437 | if receiver_ty.is_none() && inherent_impl_substs(db, impl_block, self_ty).is_none() | 437 | if receiver_ty.is_none() && inherent_impl_substs(db, impl_def, self_ty).is_none() { |
438 | { | ||
439 | test_utils::tested_by!(impl_self_type_match_without_receiver); | 438 | test_utils::tested_by!(impl_self_type_match_without_receiver); |
440 | continue; | 439 | continue; |
441 | } | 440 | } |
@@ -448,6 +447,25 @@ fn iterate_inherent_methods<T>( | |||
448 | None | 447 | None |
449 | } | 448 | } |
450 | 449 | ||
450 | /// Returns the self type for the index trait call. | ||
451 | pub fn resolve_indexing_op( | ||
452 | db: &impl HirDatabase, | ||
453 | ty: &Canonical<Ty>, | ||
454 | env: Arc<TraitEnvironment>, | ||
455 | krate: CrateId, | ||
456 | index_trait: TraitId, | ||
457 | ) -> Option<Canonical<Ty>> { | ||
458 | let ty = InEnvironment { value: ty.clone(), environment: env.clone() }; | ||
459 | let deref_chain = autoderef_method_receiver(db, krate, ty); | ||
460 | for ty in deref_chain { | ||
461 | let goal = generic_implements_goal(db, env.clone(), index_trait, ty.clone()); | ||
462 | if db.trait_solve(krate, goal).is_some() { | ||
463 | return Some(ty); | ||
464 | } | ||
465 | } | ||
466 | None | ||
467 | } | ||
468 | |||
451 | fn is_valid_candidate( | 469 | fn is_valid_candidate( |
452 | db: &impl HirDatabase, | 470 | db: &impl HirDatabase, |
453 | name: Option<&Name>, | 471 | name: Option<&Name>, |
@@ -549,3 +567,20 @@ fn generic_implements_goal( | |||
549 | let obligation = super::Obligation::Trait(trait_ref); | 567 | let obligation = super::Obligation::Trait(trait_ref); |
550 | Canonical { num_vars, value: InEnvironment::new(env, obligation) } | 568 | Canonical { num_vars, value: InEnvironment::new(env, obligation) } |
551 | } | 569 | } |
570 | |||
571 | fn autoderef_method_receiver( | ||
572 | db: &impl HirDatabase, | ||
573 | krate: CrateId, | ||
574 | ty: InEnvironment<Canonical<Ty>>, | ||
575 | ) -> Vec<Canonical<Ty>> { | ||
576 | let mut deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect(); | ||
577 | // As a last step, we can do array unsizing (that's the only unsizing that rustc does for method receivers!) | ||
578 | if let Some(Ty::Apply(ApplicationTy { ctor: TypeCtor::Array, parameters })) = | ||
579 | deref_chain.last().map(|ty| &ty.value) | ||
580 | { | ||
581 | let num_vars = deref_chain.last().unwrap().num_vars; | ||
582 | let unsized_ty = Ty::apply(TypeCtor::Slice, parameters.clone()); | ||
583 | deref_chain.push(Canonical { value: unsized_ty, num_vars }) | ||
584 | } | ||
585 | deref_chain | ||
586 | } | ||
diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 652420ea8..53cd81d46 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs | |||
@@ -4,7 +4,7 @@ use insta::assert_snapshot; | |||
4 | use ra_db::fixture::WithFixture; | 4 | use ra_db::fixture::WithFixture; |
5 | 5 | ||
6 | #[test] | 6 | #[test] |
7 | fn cfg_impl_block() { | 7 | fn cfg_impl_def() { |
8 | let (db, pos) = TestDB::with_position( | 8 | let (db, pos) = TestDB::with_position( |
9 | r#" | 9 | r#" |
10 | //- /main.rs crate:main deps:foo cfg:test | 10 | //- /main.rs crate:main deps:foo cfg:test |
@@ -347,17 +347,17 @@ mod m { | |||
347 | m::foo!(foo); | 347 | m::foo!(foo); |
348 | use foo as bar; | 348 | use foo as bar; |
349 | fn f() -> bar { 0 } | 349 | fn f() -> bar { 0 } |
350 | fn main() { | 350 | fn main() { |
351 | let _a = f(); | 351 | let _a = f(); |
352 | } | 352 | } |
353 | "#), | 353 | "#), |
354 | @r###" | 354 | @r###" |
355 | [159; 164) '{ 0 }': u64 | 355 | [159; 164) '{ 0 }': u64 |
356 | [161; 162) '0': u64 | 356 | [161; 162) '0': u64 |
357 | [175; 199) '{ ...f(); }': () | 357 | [175; 197) '{ ...f(); }': () |
358 | [187; 189) '_a': u64 | 358 | [185; 187) '_a': u64 |
359 | [193; 194) 'f': fn f() -> u64 | 359 | [191; 192) 'f': fn f() -> u64 |
360 | [193; 196) 'f()': u64 | 360 | [191; 194) 'f()': u64 |
361 | "### | 361 | "### |
362 | ); | 362 | ); |
363 | } | 363 | } |
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs index 644d59e17..f9b394f05 100644 --- a/crates/ra_hir_ty/src/tests/method_resolution.rs +++ b/crates/ra_hir_ty/src/tests/method_resolution.rs | |||
@@ -839,6 +839,24 @@ fn test() { (&S).foo()<|>; } | |||
839 | } | 839 | } |
840 | 840 | ||
841 | #[test] | 841 | #[test] |
842 | fn method_resolution_unsize_array() { | ||
843 | let t = type_at( | ||
844 | r#" | ||
845 | //- /main.rs | ||
846 | #[lang = "slice"] | ||
847 | impl<T> [T] { | ||
848 | fn len(&self) -> usize { loop {} } | ||
849 | } | ||
850 | fn test() { | ||
851 | let a = [1, 2, 3]; | ||
852 | a.len()<|>; | ||
853 | } | ||
854 | "#, | ||
855 | ); | ||
856 | assert_eq!(t, "usize"); | ||
857 | } | ||
858 | |||
859 | #[test] | ||
842 | fn method_resolution_trait_from_prelude() { | 860 | fn method_resolution_trait_from_prelude() { |
843 | let (db, pos) = TestDB::with_position( | 861 | let (db, pos) = TestDB::with_position( |
844 | r#" | 862 | r#" |
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs index 7d796d0b9..547010b35 100644 --- a/crates/ra_hir_ty/src/tests/traits.rs +++ b/crates/ra_hir_ty/src/tests/traits.rs | |||
@@ -568,6 +568,34 @@ mod ops { | |||
568 | } | 568 | } |
569 | 569 | ||
570 | #[test] | 570 | #[test] |
571 | fn infer_ops_index_autoderef() { | ||
572 | let (db, pos) = TestDB::with_position( | ||
573 | r#" | ||
574 | //- /main.rs crate:main deps:std | ||
575 | fn test() { | ||
576 | let a = &[1u32, 2, 3]; | ||
577 | let b = a[1]; | ||
578 | b<|>; | ||
579 | } | ||
580 | |||
581 | //- /std.rs crate:std | ||
582 | impl<T> ops::Index<u32> for [T] { | ||
583 | type Output = T; | ||
584 | } | ||
585 | |||
586 | #[prelude_import] use ops::*; | ||
587 | mod ops { | ||
588 | #[lang = "index"] | ||
589 | pub trait Index<Idx> { | ||
590 | type Output; | ||
591 | } | ||
592 | } | ||
593 | "#, | ||
594 | ); | ||
595 | assert_eq!("u32", type_at_pos(&db, pos)); | ||
596 | } | ||
597 | |||
598 | #[test] | ||
571 | fn deref_trait() { | 599 | fn deref_trait() { |
572 | let t = type_at( | 600 | let t = type_at( |
573 | r#" | 601 | r#" |
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 17aef9490..bc6ee2600 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -131,8 +131,8 @@ pub(crate) fn impls_for_trait_query( | |||
131 | for dep in db.crate_graph().dependencies(krate) { | 131 | for dep in db.crate_graph().dependencies(krate) { |
132 | impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); | 132 | impls.extend(db.impls_for_trait(dep.crate_id, trait_).iter()); |
133 | } | 133 | } |
134 | let crate_impl_blocks = db.impls_in_crate(krate); | 134 | let crate_impl_defs = db.impls_in_crate(krate); |
135 | impls.extend(crate_impl_blocks.lookup_impl_blocks_for_trait(trait_)); | 135 | impls.extend(crate_impl_defs.lookup_impl_defs_for_trait(trait_)); |
136 | impls.into_iter().collect() | 136 | impls.into_iter().collect() |
137 | } | 137 | } |
138 | 138 | ||
@@ -346,7 +346,7 @@ pub struct UnsizeToSuperTraitObjectData { | |||
346 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 346 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
347 | pub enum Impl { | 347 | pub enum Impl { |
348 | /// A normal impl from an impl block. | 348 | /// A normal impl from an impl block. |
349 | ImplBlock(ImplId), | 349 | ImplDef(ImplId), |
350 | /// Closure types implement the Fn traits synthetically. | 350 | /// Closure types implement the Fn traits synthetically. |
351 | ClosureFnTraitImpl(ClosureFnTraitImplData), | 351 | ClosureFnTraitImpl(ClosureFnTraitImplData), |
352 | /// [T; n]: Unsize<[T]> | 352 | /// [T; n]: Unsize<[T]> |
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index cc0f3eeb4..03f9b4e27 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs | |||
@@ -96,7 +96,7 @@ fn get_builtin_unsize_impls( | |||
96 | 96 | ||
97 | pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { | 97 | pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { |
98 | match impl_ { | 98 | match impl_ { |
99 | Impl::ImplBlock(_) => unreachable!(), | 99 | Impl::ImplDef(_) => unreachable!(), |
100 | Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data), | 100 | Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data), |
101 | Impl::UnsizeArray => array_unsize_impl_datum(db, krate), | 101 | Impl::UnsizeArray => array_unsize_impl_datum(db, krate), |
102 | Impl::UnsizeToTraitObject(trait_) => trait_object_unsize_impl_datum(db, krate, trait_), | 102 | Impl::UnsizeToTraitObject(trait_) => trait_object_unsize_impl_datum(db, krate, trait_), |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 5b6c1a62e..4001aa941 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -576,7 +576,7 @@ where | |||
576 | .impls_for_trait(self.krate, trait_) | 576 | .impls_for_trait(self.krate, trait_) |
577 | .iter() | 577 | .iter() |
578 | .copied() | 578 | .copied() |
579 | .map(Impl::ImplBlock) | 579 | .map(Impl::ImplDef) |
580 | .map(|impl_| impl_.to_chalk(self.db)) | 580 | .map(|impl_| impl_.to_chalk(self.db)) |
581 | .collect(); | 581 | .collect(); |
582 | 582 | ||
@@ -712,12 +712,12 @@ pub(crate) fn impl_datum_query( | |||
712 | debug!("impl_datum {:?}", impl_id); | 712 | debug!("impl_datum {:?}", impl_id); |
713 | let impl_: Impl = from_chalk(db, impl_id); | 713 | let impl_: Impl = from_chalk(db, impl_id); |
714 | match impl_ { | 714 | match impl_ { |
715 | Impl::ImplBlock(impl_block) => impl_block_datum(db, krate, impl_id, impl_block), | 715 | Impl::ImplDef(impl_def) => impl_def_datum(db, krate, impl_id, impl_def), |
716 | _ => Arc::new(builtin::impl_datum(db, krate, impl_).to_chalk(db)), | 716 | _ => Arc::new(builtin::impl_datum(db, krate, impl_).to_chalk(db)), |
717 | } | 717 | } |
718 | } | 718 | } |
719 | 719 | ||
720 | fn impl_block_datum( | 720 | fn impl_def_datum( |
721 | db: &impl HirDatabase, | 721 | db: &impl HirDatabase, |
722 | krate: CrateId, | 722 | krate: CrateId, |
723 | chalk_id: ImplId, | 723 | chalk_id: ImplId, |
@@ -815,7 +815,7 @@ fn type_alias_associated_ty_value( | |||
815 | let ty = db.ty(type_alias.into()); | 815 | let ty = db.ty(type_alias.into()); |
816 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; | 816 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; |
817 | let value = chalk_rust_ir::AssociatedTyValue { | 817 | let value = chalk_rust_ir::AssociatedTyValue { |
818 | impl_id: Impl::ImplBlock(impl_id).to_chalk(db), | 818 | impl_id: Impl::ImplDef(impl_id).to_chalk(db), |
819 | associated_ty_id: assoc_ty.to_chalk(db), | 819 | associated_ty_id: assoc_ty.to_chalk(db), |
820 | value: make_binders(value_bound, ty.num_binders), | 820 | value: make_binders(value_bound, ty.num_binders), |
821 | }; | 821 | }; |