Skip to content

needless_late_init: ignore if let, let mut and significant drops #8617

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

Merged
merged 1 commit into from
Apr 27, 2022

Conversation

Alexendoo
Copy link
Member

No longer lints if let, personal taste on this one is pretty split, so it probably shouldn't be warning by default. Fixes #8613

let x = if let Some(n) = y {
    n
} else {
    1
}

No longer lints let mut, things like the following are not uncommon and look fine as they are

https://github.com/shepmaster/twox-hash/blob/b169c16d86eb8ea4a296b0acb9d00ca7e3c3005f/src/sixty_four.rs#L88-L93

Avoids changing the drop order in an observable way, where the type of x has a drop with side effects and something between x and the first use also does, e.g.

https://github.com/denoland/rusty_v8/blob/48cc6cb791cac57d22fab1a2feaa92da8ddc9a68/tests/test_api.rs#L159-L167

The implementation of type_needs_ordered_drop_inner was changed a bit, it now uses Ty::has_significant_drop and reordered the ifs to check diagnostic name before checking the implicit drop impl

changelog: [needless_late_init]: No longer lints if let statements, let mut bindings and no longer significantly changes drop order

@rust-highfive
Copy link

r? @giraffate

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 1, 2022
@bors
Copy link
Contributor

bors commented Apr 15, 2022

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

@Alexendoo Alexendoo force-pushed the relax-needless-late-init branch from bb2a79e to 491d4d5 Compare April 15, 2022 20:22
@bors
Copy link
Contributor

bors commented Apr 15, 2022

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

@Alexendoo Alexendoo force-pushed the relax-needless-late-init branch from 491d4d5 to 1be706a Compare April 15, 2022 22:13
@giraffate
Copy link
Contributor

Sorry for the late reviewing. I should be able to start the review by next week.

@@ -73,6 +77,31 @@ fn contains_assign_expr<'tcx>(cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'tcx>) ->
seen
}

fn contains_let(cond: &Expr<'_>) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to replace this with higher::IfLet::hir?

Copy link
Member Author

Choose a reason for hiding this comment

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

It wouldn't be for let chains

Comment on lines 80 to 81

println!();
Copy link
Contributor

Choose a reason for hiding this comment

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

nits

Suggested change
println!();

Comment on lines 233 to 234

println!();
Copy link
Contributor

Choose a reason for hiding this comment

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

nits

Suggested change
println!();

h = format!("{}", e);

println!("{}", a);
println!();
Copy link
Contributor

Choose a reason for hiding this comment

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

nits

Suggested change
println!();

@Alexendoo Alexendoo force-pushed the relax-needless-late-init branch from 1be706a to 1d1fecf Compare April 26, 2022 12:17
@giraffate
Copy link
Contributor

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Apr 27, 2022

📌 Commit 1d1fecf has been approved by giraffate

@bors
Copy link
Contributor

bors commented Apr 27, 2022

⌛ Testing commit 1d1fecf with merge 95396f6...

@bors
Copy link
Contributor

bors commented Apr 27, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: giraffate
Pushing 95396f6 to master...

@bors bors merged commit 95396f6 into rust-lang:master Apr 27, 2022
@Alexendoo Alexendoo deleted the relax-needless-late-init branch April 27, 2022 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suppress needless_late_init on if-let and long if/match expr
4 participants