From d4350004cde30caf12fc78559f4d7fbbec0fcbe6 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Sun, 17 May 2026 15:31:29 +0300 Subject: [PATCH] Do not autoref in method probe in path mode --- crates/hir-ty/src/method_resolution/probe.rs | 9 +++++++++ crates/hir-ty/src/tests/method_resolution.rs | 4 ++-- crates/hir-ty/src/tests/traits.rs | 10 +++++----- crates/ide-completion/src/tests/expression.rs | 15 +++++++++++++++ 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 60344490d550..84edb510237d 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 4291c9ba18dc..2084c01853a1 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() { 95..103 'u32::foo': fn foo() -> u8 109..115 'S::foo': fn foo() -> u8 121..127 'T::foo': fn foo() -> u8 - 133..139 'U::foo': fn foo() -> 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 ea978cde58c1..4eab1d631428 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() { 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 b5465ee87a6c..4a4b09c6585a 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(test: H) { + H::$0 +} + "#, + expect![""], + ); +}