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

Add needless_late_init lint #7995

Merged
merged 2 commits into from Nov 27, 2021
Merged

Conversation

Alexendoo
Copy link
Member

examples:

let a;
a = 1;
// to
let a = 1;
let b;
match 3 {
    0 => b = "zero",
    1 => b = "one",
    _ => b = "many",
}
// to
let b = match 3 {
    0 => "zero",
    1 => "one",
    _ => "many",
};
let c;
if true {
    c = 1;
} else {
    c = -1;
}
// to
let c = if true {
    1
} else {
    -1
};

changelog: Add [needless_late_init]

@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 Nov 18, 2021
|
LL | };
| +

Copy link
Member Author

Choose a reason for hiding this comment

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

This overlaps a little with useless_let_if_seq, needless_late_init doesn't do as many clever transformations as useless_let_if_seq however, hopefully meaning it has less false positives

I wasn't sure what to choose here, I could remove the matching of ifs from needless_late_init

Copy link
Contributor

Choose a reason for hiding this comment

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

This overlaps a little with useless_let_if_seq, needless_late_init doesn't do as many clever transformations as useless_let_if_seq however, hopefully meaning it has less false positives

Yes, it looks good.

I wasn't sure what to choose here, I could remove the matching of ifs from needless_late_init

IMO it looks good as it is.

|
LL ~ 1 => "one",
LL | _ => {
LL ~ "two"
Copy link
Member Author

Choose a reason for hiding this comment

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

Another problem I had was with mutlispan_suggest, the suggestions are a little bare and using _verbose doesn't seem to change it. As well as running into rust-lang/rustfix#141

Is there a way to have a regular suggestion appear just without the help label repeated?

@bors
Copy link
Collaborator

bors commented Nov 19, 2021

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

@bors
Copy link
Collaborator

bors commented Nov 22, 2021

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

clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@giraffate giraffate left a comment

Choose a reason for hiding this comment

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

Overall looks good, thanks! I made some small comments.

clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
clippy_lints/src/needless_late_init.rs Outdated Show resolved Hide resolved
tests/ui/let_if_seq.stderr Outdated Show resolved Hide resolved
tests/ui/needless_late_init_fixable.rs Show resolved Hide resolved
@Alexendoo
Copy link
Member Author

Thanks, made the changes

@giraffate
Copy link
Contributor

@bors r+

Thanks!

@bors
Copy link
Collaborator

bors commented Nov 27, 2021

📌 Commit d346ec9 has been approved by giraffate

@bors
Copy link
Collaborator

bors commented Nov 27, 2021

⌛ Testing commit d346ec9 with merge 3720735...

@bors
Copy link
Collaborator

bors commented Nov 27, 2021

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

@bors bors merged commit 3720735 into rust-lang:master Nov 27, 2021
@Alexendoo Alexendoo deleted the needless_late_init branch November 27, 2021 17:47
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.

None yet

5 participants