From 28ca37175572403edeb92324d251fbceb4c2487f Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 25 May 2021 16:08:18 +0200 Subject: Consider trait to be in scope for trait-impl --- crates/hir_ty/src/infer.rs | 2 ++ crates/hir_ty/src/tests/traits.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index edb65622f..164e85050 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -578,10 +578,12 @@ impl<'a> InferenceContext<'a> { } fn resolve_ops_try_ok(&self) -> Option { + // FIXME resolve via lang_item once try v2 is stable let path = path![core::ops::Try]; let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?; let trait_data = self.db.trait_data(trait_); trait_data + // FIXME remove once try v2 is stable .associated_type_by_name(&name![Ok]) .or_else(|| trait_data.associated_type_by_name(&name![Output])) } diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 6cd8786ea..6ad96bfe3 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -3630,3 +3630,33 @@ fn test(f: F) { "#]], ); } + +#[test] +fn trait_in_scope_of_trait_impl() { + check_infer( + r#" +mod foo { + pub trait Foo { + fn foo(self); + fn bar(self) -> usize { 0 } + } +} +impl foo::Foo for u32 { + fn foo(self) { + let _x = self.bar(); + } +} + "#, + expect![[r#" + 45..49 'self': Self + 67..71 'self': Self + 82..87 '{ 0 }': usize + 84..85 '0': usize + 131..135 'self': u32 + 137..173 '{ ... }': () + 151..153 '_x': usize + 156..160 'self': u32 + 156..166 'self.bar()': usize + "#]], + ); +} -- cgit v1.2.3