Skip to content

Commit 536ed7c

Browse files
bors[bot]xffxff
andauthored
Merge #11004
11004: Fix: Infer associated method in local scope r=flodiebold a=XFFXFF fixes #10936 Co-authored-by: zhoufan <[email protected]>
2 parents 791722b + c3ad945 commit 536ed7c

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

crates/hir_ty/src/infer/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a> InferenceContext<'a> {
227227
self.table.trait_env.clone(),
228228
krate,
229229
&traits_in_scope,
230-
None,
230+
self.resolver.module(),
231231
Some(name),
232232
method_resolution::LookupMode::Path,
233233
move |_ty, item| {

crates/hir_ty/src/tests/method_resolution.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,37 @@ fn infer_associated_method_struct() {
8484
);
8585
}
8686

87+
#[test]
88+
fn infer_associated_method_struct_in_local_scope() {
89+
check_infer(
90+
r#"
91+
fn mismatch() {
92+
struct A;
93+
94+
impl A {
95+
fn from(_: i32, _: i32) -> Self {
96+
A
97+
}
98+
}
99+
100+
let _a = A::from(1, 2);
101+
}
102+
"#,
103+
expect![[r#"
104+
14..146 '{ ... 2); }': ()
105+
125..127 '_a': A
106+
130..137 'A::from': fn from(i32, i32) -> A
107+
130..143 'A::from(1, 2)': A
108+
138..139 '1': i32
109+
141..142 '2': i32
110+
60..61 '_': i32
111+
68..69 '_': i32
112+
84..109 '{ ... }': A
113+
98..99 'A': A
114+
"#]],
115+
);
116+
}
117+
87118
#[test]
88119
fn infer_associated_method_enum() {
89120
check_infer(
@@ -277,7 +308,7 @@ fn test() {
277308
pub mod foo {
278309
pub struct S;
279310
impl S {
280-
fn thing() -> i128 { 0 }
311+
pub fn thing() -> i128 { 0 }
281312
}
282313
}
283314
"#,

crates/ide/src/hover/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,10 @@ fn test_hover_infer_associated_method_exact() {
823823
check(
824824
r#"
825825
mod wrapper {
826-
struct Thing { x: u32 }
826+
pub struct Thing { x: u32 }
827827
828828
impl Thing {
829-
fn new() -> Thing { Thing { x: 0 } }
829+
pub fn new() -> Thing { Thing { x: 0 } }
830830
}
831831
}
832832
@@ -840,9 +840,9 @@ fn main() { let foo_test = wrapper::Thing::new$0(); }
840840
```
841841
842842
```rust
843-
fn new() -> Thing
843+
pub fn new() -> Thing
844844
```
845-
"#]],
845+
"#]],
846846
)
847847
}
848848

0 commit comments

Comments
 (0)