Skip to content

Fix conflicting deref move suggestion for LazyLock patterns#154843

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
nataliakokoromyti:fix-154826-deref-help
Apr 18, 2026
Merged

Fix conflicting deref move suggestion for LazyLock patterns#154843
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
nataliakokoromyti:fix-154826-deref-help

Conversation

@nataliakokoromyti
Copy link
Copy Markdown
Contributor

@nataliakokoromyti nataliakokoromyti commented Apr 5, 2026

fixes #154826.

Rust was suggesting *V -> V for let (v,) = *V, which then triggered a follow-up error suggesting the opposite. This patch makes that case suggest borrowing (&V) instead. Also handles destructuring assignment separately so we don’t emit a misleading &... fix-it there.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 5, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 5, 2026

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 11 candidates

@rust-log-analyzer

This comment has been minimized.

Comment on lines +828 to +846
if !is_raw_ptr && (!is_destructuring_pattern_move || is_ref) {
err.span_suggestion_verbose(
span.with_hi(span.lo() + BytePos(1)),
"consider removing the dereference here",
String::new(),
Applicability::MaybeIncorrect,
);
} else if !is_raw_ptr && !is_destructuring_assignment && !is_nested_deref {
err.span_suggestion_verbose(
span.shrink_to_lo(),
"consider borrowing here",
'&',
Applicability::MaybeIncorrect,
);
} else if !is_raw_ptr {
err.span_help(
span,
"destructuring assignment cannot borrow from this expression; consider using a `let` binding instead",
);
Copy link
Copy Markdown
Member

@mati865 mati865 Apr 12, 2026

Choose a reason for hiding this comment

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

View changes since the review

I think repeating the same condition all over the place isn't great. How about adding an early exit like:

if is_raw_ptr {
  return;
}

or nesting them inside if !is_raw_ptr { ... } block?

@mati865 mati865 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2026
Copy link
Copy Markdown
Member

@mati865 mati865 left a comment

Choose a reason for hiding this comment

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

Could you squash the refactor commit into previous ones?

View changes since this review

@mati865
Copy link
Copy Markdown
Member

mati865 commented Apr 18, 2026

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 18, 2026

📌 Commit 7d68017 has been approved by mati865

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 18, 2026
rust-bors Bot pushed a commit that referenced this pull request Apr 18, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #155308 (Make `OnDuplicate::Error` the default for attributes)
 - #154432 (Set up API to make it possible to pass closures instead of `AttributeLint`)
 - #154843 (  Fix conflicting deref move suggestion for LazyLock patterns)
 - #155262 (bootstrap.py: fix duplicated "the")
 - #155478 (Fixed broken documentation link for method lookup in rustc_hir_typeck…)
@rust-bors rust-bors Bot merged commit 0e54c26 into rust-lang:main Apr 18, 2026
11 checks passed
@rustbot rustbot added this to the 1.97.0 milestone Apr 18, 2026
rust-timer added a commit that referenced this pull request Apr 18, 2026
Rollup merge of #154843 - nataliakokoromyti:fix-154826-deref-help, r=mati865

  Fix conflicting deref move suggestion for LazyLock patterns

fixes #154826.

Rust was suggesting *V -> V for let (v,) = *V, which then triggered a follow-up error suggesting the opposite. This patch makes that case suggest borrowing (&*V) instead. Also handles destructuring assignment separately so we don’t emit a misleading &*... fix-it there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conflicting help messages for dereferencing and moving non-Copy values

4 participants