Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessary references lint #138230

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

obeis
Copy link
Contributor

@obeis obeis commented Mar 8, 2025

Close #127724

@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2025

r? @Noratrieb

rustbot has assigned @Noratrieb.
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 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 Mar 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 8, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

This lint seems really specific to a single kind of expression, and there are plenty of other cases where unnecessary references are created when the user is trying to create a raw pointer. Unless this can be greatly generalized, it doesn't really seem worth adding this.

@compiler-errors
Copy link
Member

r? RalfJung

@rustbot rustbot assigned RalfJung and unassigned Noratrieb Mar 8, 2025
@obeis
Copy link
Contributor Author

obeis commented Mar 8, 2025

I agree, and my intention is to generalize this lint to cover all unnecessarily created references. Could you please list other cases that you think should be included? I can update this PR to cover them or create an issue to track these cases and mention that they should be added to the unnecessary_refs lint.

@RalfJung
Copy link
Member

RalfJung commented Mar 9, 2025 via email

@rustbot rustbot assigned SparrowLii and unassigned RalfJung Mar 9, 2025
@traviscross traviscross added T-lang Relevant to the language team, which will review and decide on the PR/issue. needs-fcp This change is insta-stable, so needs a completed FCP to proceed. labels Mar 9, 2025
Copy link
Member

@SparrowLii SparrowLii left a comment

Choose a reason for hiding this comment

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

I know little about lints' impls so r? compiler

@rustbot rustbot assigned Nadrieril and unassigned SparrowLii Mar 10, 2025
@RalfJung
Copy link
Member

Do we have some people who are our "linting experts"?

@RalfJung
Copy link
Member

This lint seems really specific to a single kind of expression, and there are plenty of other cases where unnecessary references are created when the user is trying to create a raw pointer. Unless this can be greatly generalized, it doesn't really seem worth adding this.

Which examples did you have in mind?

A starting point might be to uplift https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr from cliippy to rustc, as you mention. It is not clear to me what the difference is between that lint and this one.

@traviscross
Copy link
Contributor

Do we have some people who are our "linting experts"?

cc @Urgau

@Urgau
Copy link
Member

Urgau commented Mar 10, 2025

Happy to take over the review. If @Nadrieril doesn't want to review it of course.

As for the lint it-self, I join @RalfJung that this is lint is currently clippy::borrow_as_ptr, which will need to be dropped from clippy. Look at 1fee1a4 for the changes needed.

As a drive-by, rustc_hir_pretty should not be necessary, a multi-part suggestion should be used instead, with some span manipulation to get the correct spans.

@Nadrieril
Copy link
Member

Much appreciated :) r? @Urgau

@rustbot rustbot assigned Urgau and unassigned Nadrieril Mar 11, 2025
@Urgau Urgau 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 Mar 12, 2025
@obeis obeis force-pushed the lint-unnecessary-reference branch from 1e686f1 to e113827 Compare March 18, 2025 18:26
@obeis obeis requested a review from Urgau March 18, 2025 18:27
@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 (such as code changes or more information) from the author. labels Mar 18, 2025
@obeis obeis force-pushed the lint-unnecessary-reference branch from e113827 to faf0620 Compare March 18, 2025 18:49
@rust-log-analyzer

This comment has been minimized.

@Urgau Urgau 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 Mar 18, 2025
@obeis obeis force-pushed the lint-unnecessary-reference branch from faf0620 to 976c0a8 Compare March 24, 2025 20:10
@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2025

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@obeis obeis force-pushed the lint-unnecessary-reference branch from 976c0a8 to 64132e5 Compare March 24, 2025 20:19
@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) O-windows Operating system: Windows labels Mar 24, 2025
@rust-log-analyzer

This comment has been minimized.

@obeis
Copy link
Contributor Author

obeis commented Mar 24, 2025

I ran x test on my machine, and everything passed. Why is it failing here, and how can I reproduce those errors locally?

@RalfJung
Copy link
Member

RalfJung commented Mar 24, 2025 via email

@obeis obeis force-pushed the lint-unnecessary-reference branch from 64132e5 to b0d836f Compare March 24, 2025 22:35
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) needs-fcp This change is insta-stable, so needs a completed FCP to proceed. O-windows Operating system: Windows S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lint against expressions that unnecessarily create references
10 participants