Skip to content

Conversation

@vishruth-thimmaiah
Copy link
Contributor

Fixes: #14155

If an expression is borrowed/dereferenced, suggest using .as_ref() or .copied() respectively in the outer conditional statement.

changelog: [collapsible_match] suggests ref/dereferencing when needed.

@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2025

r? @llogiq

rustbot has assigned @llogiq.
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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 15, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 31, 2025
@nk9
Copy link

nk9 commented Apr 7, 2025

Checking in here. It looks to me like the state is wrong now. Aren't we actually waiting on review?

@samueltardieu
Copy link
Member

We are expecting both a review and a rebase. The bot settings have been changed a few days ago to let the PR in review state, so I'll reset it.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties and removed S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) labels Apr 8, 2025
@vishruth-thimmaiah vishruth-thimmaiah force-pushed the fix_collapsible_match_ref branch 2 times, most recently from bc85de9 to 0dc1cdc Compare April 9, 2025 17:17
Copy link
Member

@samueltardieu samueltardieu left a comment

Choose a reason for hiding this comment

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

It looks like you ignore the fact that the reference might be mutable. The following code will suggest using .as_ref():

    let mut arr = ["a", "b", "c"];
    if let Some(mut last) = arr.last_mut() {
        match &mut last {
            &mut &mut "a" | &mut &mut "b" => {
                unimplemented!()
            },
            _ => (),
        }
    }

The suggestion might also be incorrect in case of raw references, where the types may not match (untested):

    const NULL_PTR: *const &'static str = std::ptr::null();
    if let Some(last) = arr.last() {
        match &raw const *last {
            NULL_PTR => unimplemented!(),
            _ => (),
        }
    }

@vishruth-thimmaiah vishruth-thimmaiah force-pushed the fix_collapsible_match_ref branch from 0dc1cdc to 6116061 Compare April 12, 2025 18:10
@vishruth-thimmaiah
Copy link
Contributor Author

I couldn't figure out any way to handle &raw refs, so I just disabled the lint for &raw refs. If you have any suggestions on how to handle them, I'd appreciate it!

@vishruth-thimmaiah vishruth-thimmaiah force-pushed the fix_collapsible_match_ref branch from 6116061 to 3efde9f Compare April 12, 2025 18:19
@samueltardieu samueltardieu dismissed their stale review May 16, 2025 18:46

Code has been updated.

@llogiq
Copy link
Contributor

llogiq commented Aug 23, 2025

Sorry for the delay. Thanks for making clippy better! Can you open an issue for &raw handling? I don't think we should worry about the lint ignoring them, but someone may want to implement it anyway.

@llogiq llogiq added this pull request to the merge queue Aug 23, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 23, 2025
@samueltardieu
Copy link
Member

@vishruth-thimmaiah Rebasing and reblessing the test output should be enough to make it mergeable again.

@vishruth-thimmaiah vishruth-thimmaiah force-pushed the fix_collapsible_match_ref branch from 3efde9f to bd7b317 Compare August 27, 2025 20:18
@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rustbot

This comment has been minimized.

@vishruth-thimmaiah vishruth-thimmaiah force-pushed the fix_collapsible_match_ref branch from bd7b317 to d05fe15 Compare August 27, 2025 20:19
@vishruth-thimmaiah vishruth-thimmaiah force-pushed the fix_collapsible_match_ref branch from d05fe15 to 9910217 Compare August 27, 2025 20:23
@samueltardieu samueltardieu added this pull request to the merge queue Aug 27, 2025
Merged via the queue into rust-lang:master with commit 0afd6a6 Aug 27, 2025
11 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 27, 2025
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.

collapsible_match suggestion incomplete

5 participants