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

explicit_reinitialization: Cutoff reinit #11687

Closed
wants to merge 7 commits into from

Conversation

lengyijun
Copy link
Contributor

@lengyijun lengyijun commented Oct 20, 2023

changelog: [explicit_reinitialization]: new lint: introduce fresh variable instead of reinitialization

@rustbot
Copy link
Collaborator

rustbot commented Oct 20, 2023

r? @Alexendoo

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

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 20, 2023
@lengyijun lengyijun changed the title Cutoff reinit explicit_reinitialization: Cutoff reinit Oct 20, 2023
@Alexendoo Alexendoo linked an issue Oct 20, 2023 that may be closed by this pull request
@lengyijun
Copy link
Contributor Author

lengyijun commented Oct 23, 2023

Algorithm summary:

  1. in hir, filter suspious assignment
  2. locate the related mir (by span)
  3. in mir cfg, check the assignment dominate all reachable usages

Tips

  1. ignore macos. Macros generate strange spans

@Alexendoo
Copy link
Member

I'm not sure about this, it can change the behaviour of code with regards to drop order for example

let mut x = some_vec();
x = some_other_vec(); // x is dropped here
// ...
let x = some_vec();
let x = some_other_vec(); // x is no longer dropped here, but at the end of the scope
// ...

For a Vec this could increase the peak memory usage, with similar issues for other kinds of resources

I also don't think we should be suggesting to shadow one mut binding with another, that makes things more confusing I would say

@bors
Copy link
Contributor

bors commented Oct 23, 2023

☔ The latest upstream changes (presumably #11460) made this pull request unmergeable. Please resolve the merge conflicts.

@lengyijun lengyijun force-pushed the cutoff_reinit branch 3 times, most recently from a748b06 to bebd568 Compare October 28, 2023 06:04
@lengyijun
Copy link
Contributor Author

lengyijun commented Oct 29, 2023

Q&A

  1. why use mir / why not analysis purely in hir ?
    No dominance tree in hir

  2. How to search hir by mir / search mir by hir
    By span
    No one-to-one relation
    Try to find the closest span instead

@bors
Copy link
Contributor

bors commented Nov 14, 2023

☔ The latest upstream changes (presumably #11791) made this pull request unmergeable. Please resolve the merge conflicts.

@xFrednet
Copy link
Member

xFrednet commented Apr 1, 2024

Hey, this is a ping from triage, since there hasn't been any activity in some time. Are you still planning to continue this implementation?

I'm guessing this PR stalled in part due to the usage of MIR. I currently use MIR for a different project and am not sure if it's the right choice for Clippy. As you say there is no one-to-one relation between MIR and HIR stuff which makes linting hard. There is also the problem that most of the Clippy team are not too familiar with MIR.

If you're planning to continue this, I would suggest adding the I-nominate label, to nominate the discussion if we want to use MIR for lints for the next Clippy meeting.

@rustbot author

@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 Apr 1, 2024
@lengyijun
Copy link
Contributor Author

@rustbot label +I-nominate

@y21 y21 added the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Apr 1, 2024
@flip1995 flip1995 removed the I-nominated Issue: Nominated to be discussed at the next Clippy meeting label Apr 16, 2024
@flip1995
Copy link
Member

As this lint is close to the shadow lints (just the reverse) it probably should go into a allow-by-default group as I feel like this is pretty opinionated. For MIR lints we have a "should be worth the complexity" rule (discussed in the last meeting). For an allow-by-default lint, I don't think this is worth the complexity. For this reason and because there was no response by the author, I'm closing this PR, without a S-inactive-closed label.

@flip1995 flip1995 closed this Apr 16, 2024
@lengyijun
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reinitialization with let
7 participants