Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/hir-ty/src/method_resolution/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,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,
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-ty/src/tests/method_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"#]],
);
}
Expand Down
10 changes: 5 additions & 5 deletions crates/hir-ty/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Copy link
Copy Markdown
Contributor Author

@ChayimFriedman2 ChayimFriedman2 May 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other test regressions are in path mode (where the trait doesn't hold) so expected. The ones in this file is in method call mode, so less expected. The reason for it is that if we fail to resolve with method call mode we retry with path mode.

rustc fails to resolve these methods as well.

View changes since the review

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
"#]],
Expand Down Expand Up @@ -3126,15 +3126,15 @@ 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)
135..152 '(1u8, ...test()': bool
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
Expand Down Expand Up @@ -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}
"#]],
);
}
Expand Down
15 changes: 15 additions & 0 deletions crates/ide-completion/src/tests/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3901,3 +3901,18 @@ fn tryme(param: impl SubTrait) {
"#]],
);
}

#[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![""],
);
}
Loading