Unnamed repository; edit this file 'description' to name the repository.
Do not autoref in method probe in path mode
Chayim Refael Friedman 2 weeks ago
parent b5df936 · commit d435000
-rw-r--r--crates/hir-ty/src/method_resolution/probe.rs9
-rw-r--r--crates/hir-ty/src/tests/method_resolution.rs4
-rw-r--r--crates/hir-ty/src/tests/traits.rs10
-rw-r--r--crates/ide-completion/src/tests/expression.rs15
4 files changed, 31 insertions, 7 deletions
diff --git a/crates/hir-ty/src/method_resolution/probe.rs b/crates/hir-ty/src/method_resolution/probe.rs
index 60344490d5..84edb51023 100644
--- a/crates/hir-ty/src/method_resolution/probe.rs
+++ b/crates/hir-ty/src/method_resolution/probe.rs
@@ -1295,6 +1295,15 @@ impl<'a, 'db, Choice: ProbeChoice<'db>> ProbeContext<'a, 'db, Choice> {
return ControlFlow::Break(by_value_pick);
}
+ if self.mode == Mode::Path {
+ // Don't autoref in path mode.
+ // rustc doesn't do that and it's not a big deal as non-autorefd methods take priority
+ // and if an autorefd one is selected, we'll register the `NonAutorefdT: Trait` obligation
+ // (which will fail) anyway. But it does have an impact when probing for all methods,
+ // which is something we need to stay accurate.
+ return ControlFlow::Continue(());
+ }
+
let autoref_pick = self.pick_autorefd_method(
step,
self_ty,
diff --git a/crates/hir-ty/src/tests/method_resolution.rs b/crates/hir-ty/src/tests/method_resolution.rs
index 4291c9ba18..2084c01853 100644
--- a/crates/hir-ty/src/tests/method_resolution.rs
+++ b/crates/hir-ty/src/tests/method_resolution.rs
@@ -1715,8 +1715,8 @@ fn f<S: Sized, T, U: ?Sized>() {
95..103 'u32::foo': fn foo<u32>() -> u8
109..115 'S::foo': fn foo<S>() -> u8
121..127 'T::foo': fn foo<T>() -> u8
- 133..139 'U::foo': fn foo<U>() -> u8
- 145..157 '<[u32]>::foo': fn foo<[u32]>() -> u8
+ 133..139 'U::foo': {unknown}
+ 145..157 '<[u32]>::foo': {unknown}
"#]],
);
}
diff --git a/crates/hir-ty/src/tests/traits.rs b/crates/hir-ty/src/tests/traits.rs
index ea978cde58..4eab1d6314 100644
--- a/crates/hir-ty/src/tests/traits.rs
+++ b/crates/hir-ty/src/tests/traits.rs
@@ -3027,13 +3027,13 @@ fn test() {
140..146 'IsCopy': IsCopy
140..153 'IsCopy.test()': bool
159..166 'NotCopy': NotCopy
- 159..173 'NotCopy.test()': bool
+ 159..173 'NotCopy.test()': {unknown}
179..195 '(IsCop...sCopy)': (IsCopy, IsCopy)
179..202 '(IsCop...test()': bool
180..186 'IsCopy': IsCopy
188..194 'IsCopy': IsCopy
208..225 '(IsCop...tCopy)': (IsCopy, NotCopy)
- 208..232 '(IsCop...test()': bool
+ 208..232 '(IsCop...test()': {unknown}
209..215 'IsCopy': IsCopy
217..224 'NotCopy': NotCopy
"#]],
@@ -3126,7 +3126,7 @@ fn test() {
79..194 '{ ...ized }': ()
85..88 '1u8': u8
85..95 '1u8.test()': bool
- 101..116 '(*"foo").test()': bool
+ 101..116 '(*"foo").test()': {unknown}
102..108 '*"foo"': str
103..108 '"foo"': &'static str
135..145 '(1u8, 1u8)': (u8, u8)
@@ -3134,7 +3134,7 @@ fn test() {
136..139 '1u8': u8
141..144 '1u8': u8
158..171 '(1u8, *"foo")': (u8, str)
- 158..178 '(1u8, ...test()': bool
+ 158..178 '(1u8, ...test()': {unknown}
159..162 '1u8': u8
164..170 '*"foo"': str
165..170 '"foo"': &'static str
@@ -4069,7 +4069,7 @@ fn f<F: Foo>() {
212..295 '{ ...ZED; }': ()
218..239 'F::Exp..._SIZED': Yes
245..266 'F::Imp..._SIZED': Yes
- 272..292 'F::Rel..._SIZED': Yes
+ 272..292 'F::Rel..._SIZED': {unknown}
"#]],
);
}
diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs
index b5465ee87a..4a4b09c658 100644
--- a/crates/ide-completion/src/tests/expression.rs
+++ b/crates/ide-completion/src/tests/expression.rs
@@ -3962,3 +3962,18 @@ fn main() {
"#]],
);
}
+
+#[test]
+fn no_completion_for_autorefd_traits_in_path_mode() {
+ check(
+ r#"
+//- minicore: clone
+trait Test1 {}
+
+fn test<H: Test1>(test: H) {
+ H::$0
+}
+ "#,
+ expect![""],
+ );
+}