Fix conflicting deref move suggestion for LazyLock patterns#154843
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Apr 18, 2026
Merged
Fix conflicting deref move suggestion for LazyLock patterns#154843rust-bors[bot] merged 1 commit intorust-lang:mainfrom
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
mati865
reviewed
Apr 12, 2026
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", | ||
| ); |
Member
There was a problem hiding this comment.
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
approved these changes
Apr 13, 2026
71d6ef8 to
9409bb8
Compare
9409bb8 to
7d68017
Compare
Member
|
@bors r+ rollup |
Contributor
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-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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.