3

Simplify some of the logic in the `invalid_reference_casting` lint by Urgau · Pu...

 11 months ago
source link: https://github.com/rust-lang/rust/pull/116199
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Contributor

This PR simplifies 2 areas of the logic for the invalid_reference_casting lint:

  • The init detection: we now use the newly added expr_or_init function instead of a manual detection
  • The ref-to-mut-ptr casting detection logic: I simplified this logic by caring less hardly about the order of the casting operations

Those two simplifications permits us to detect more cases, as can be seen in the test output changes.

Collaborator

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

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

Sep 27, 2023

This comment has been minimized.

Contributor

Author

I'm not so sure about the last commit, it fixes the ICEs in #116199 (comment) but at the cost a new scaled down function, just to avoid outside expr outside the current body.

Maybe we should check that the result of expr_or_init has same the owner as the expression passed in? (but then we are potentially doing more work than necessary)

tests/ui/lint/reference_casting.rs

Outdated Show resolved

/// dbg!(def);

/// // ^^^ input

/// ```

pub fn expr_or_init<'a>(&self, mut expr: &'a hir::Expr<'tcx>) -> &'a hir::Expr<'tcx> {

Contributor

Isn't it a bit dangerous to change the other method's name and reusing it for this one?

Contributor

Author

Yes, a bit, but the function was added very recently, has only one user (the utf8 lints) and it is now better matching the similar function from clippy: clippy_utils::expr_or_init.

arg

} else if had_at_least_one_cast {

Contributor

IIUC, this flag is an optimization to avoid calling node_type if we haven't seed any cast. Is this worth it? node_type is a simple hashmap lookup.
This deserves at least a comment.

Contributor

Author

Since we are now checking the end type at the start, I agree keeping this flag doesn't seems compelling enough. Removed.

Contributor

@bors r+

Contributor

📌 Commit 1b2c1a8 has been approved by cjgillot

It is now in the queue for this repository.

bors

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-review Status: Awaiting review from the assignee but also interested parties.

labels

Sep 28, 2023

Contributor

⌛ Testing commit 1b2c1a8 with merge 1393ef1...

Contributor

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 1393ef1 to master...

Collaborator

Finished benchmarking commit (1393ef1): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 631.024s -> 630.971s (-0.01%)
Artifact size: 317.33 MiB -> 317.33 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

cjgillot

cjgillot left review comments
Assignees

cjgillot

Labels
merged-by-bors This PR was explicitly merged by bors 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

Milestone

1.74.0

Development

Successfully merging this pull request may close these issues.

None yet

6 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK