Skip to content

fix: only ref match non-unknown value items#22367

Merged
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:ref-match-only-value
May 17, 2026
Merged

fix: only ref match non-unknown value items#22367
ChayimFriedman2 merged 1 commit into
rust-lang:masterfrom
A4-Tacks:ref-match-only-value

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented May 15, 2026

Copy link
Copy Markdown
Member

Fixes #22324

Example

struct S<T>(T);
impl<T> core::ops::Deref for S<T> {
    type Target = T;
}
fn foo<T>(s: &u32) {}
fn main() {
    let ssss = S();
    foo($0);
}

Before this PR

lc ssss S<{unknown}> [local]
lc &ssss [type+local]
st S S<{unknown}> []
st &S [type]
...

After this PR

lc ssss S<{unknown}> [local]
st S S<{unknown}> []
...

Example
---
```rust
struct S<T>(T);
impl<T> core::ops::Deref for S<T> {
    type Target = T;
}
fn foo<T>(s: &u32) {}
fn main() {
    let ssss = S();
    foo($0);
}
```

**Before this PR**

```text
lc ssss S<{unknown}> [local]
lc &ssss [type+local]
st S S<{unknown}> []
st &S [type]
...
```

**After this PR**

```text
lc ssss S<{unknown}> [local]
st S S<{unknown}> []
...
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 15, 2026
@A4-Tacks A4-Tacks requested a review from ChayimFriedman2 May 17, 2026 06:05
@A4-Tacks

Copy link
Copy Markdown
Member Author

r? @ChayimFriedman2 This needs to be fixed as soon as possible, otherwise any Deref to generic will be auto imported

Example

fn foo(_: &u32) {}
fn main() {
    foo(M$0);
}

Completes

&MutexGuard~(use std::sync::MutexGuard)
&MutexGuard~(use std::sync::nonpoison::MutexGuard)
&ManuallyDrop~(use std::mem::ManuallyDrop)
&MappedMutexGuard~(use std::sync::MappedMutexGuard)
&MappedMutexGuard~(use std::sync::nonpoison::MappedMutexGuard)
&MappedRwLockReadGuard~(use std::sync::MappedRwLockReadGuard)
&MappedRwLockReadGuard~(use std::sync::nonpoison::MappedRwLockReadGuard)
&MappedRwLockWriteGuard~(use std::sync::MappedRwLockWriteGuard)
&MappedRwLockWriteGuard~(use std::sync::nonpoison::MappedRwLockWriteGuard)

match resolution {
ScopeDef::Local(_)
| ScopeDef::ModuleDef(ModuleDef::Const(_) | ModuleDef::Static(_)) => {
path_ref_match(completion, path_ctx, &ty, &mut item)

@ChayimFriedman2 ChayimFriedman2 May 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you know filter to only consts/statics/locals?

View changes since the review

@A4-Tacks A4-Tacks May 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For struct paths, etc., the assoc fn may not necessarily return Self, and it is suggest to reference noise

And if its method is still ref match, it can be done when completing the method e.g f(Foo::ne) -> f(&Foo::new())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But this will also prevent struct literals from adding a ref, e.g. Foo { ... } or Foo(...).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, this is not. The test was not broken, and it was rendered by literal instead of path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Which test?

st WorldSnapshot {…} WorldSnapshot { _f: () } []
st &WorldSnapshot {…} [type]
st WorldSnapshot WorldSnapshot []
st &WorldSnapshot [type]

@A4-Tacks A4-Tacks May 17, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue May 17, 2026
Merged via the queue into rust-lang:master with commit 5a5a4b5 May 17, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 17, 2026
@A4-Tacks A4-Tacks deleted the ref-match-only-value branch May 17, 2026 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strangly refmatch type

3 participants