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

Suggest to change numeric literal instead of casting #54273

Merged
merged 6 commits into from
Sep 18, 2018

Conversation

csmoe
Copy link
Member

@csmoe csmoe commented Sep 16, 2018

Closes #54160
r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 16, 2018
@rust-highfive

This comment has been minimized.

{
// 42u8
// ^^
let lit_offset = src.len() - checked_ty.to_string().len();
Copy link
Member Author

Choose a reason for hiding this comment

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

oops, brute sub should be optimized.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

Love it!

A couple of nitpicks left. After addressing r=me.

expected_ty,
),
suffix_suggestion,
Applicability::MaybeIncorrect,
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel these might count as MachineApplicable...

),
suffix_suggestion,
Applicability::MaybeIncorrect,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel there's a bit of duplication on these, would it make sense to have is_suffixed (with a more accurate name) take mut err, checked_ty and expected_ty, and if it would return true now it would also apply the suggestion, and here you just call it as if !is_sufficed(expr) { with the following block (as each one of these has slightly different wording).

fn foo(_: u16) {}
fn main() {
foo(8u8);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test for floats too?

@estebank estebank 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 Sep 16, 2018
expr: &hir::Expr,
expected_ty: Ty<'tcx>,
checked_ty: Ty<'tcx>,
note: Option<&str>| {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's the first time I've seen a closure that needed multiple arguments and I'm surprised rustfmt suggests exactly this :)

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, expr and *_ty aren't needed actually, I'll remove them.

@estebank
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 17, 2018

📌 Commit c3b6e3f2ac2c8ef64168db4336645399380c5fdd has been approved by estebank

@bors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 17, 2018
@rust-lang rust-lang deleted a comment from bors Sep 17, 2018
@rust-lang rust-lang deleted a comment from bors Sep 17, 2018
@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 17, 2018
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 17, 2018

📌 Commit 2fb6585 has been approved by estebank

@bors 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 17, 2018
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 18, 2018
Suggest to change numeric literal instead of casting

Closes rust-lang#54160
r? @estebank
bors added a commit that referenced this pull request Sep 18, 2018
Rollup of 9 pull requests

Successful merges:

 - #53522 (Add doc for impl From for Addr)
 - #54097 (rustdoc: Remove namespace for keywords)
 - #54205 (Add treat-err-as-bug flag in rustdoc)
 - #54225 (Regression test for #53675.)
 - #54232 (add `-Z dont-buffer-diagnostics`)
 - #54273 (Suggest to change numeric literal instead of casting)
 - #54299 (Issue 54246)
 - #54311 (Remove README with now-out-of-date docs about docs.)
 - #54313 (OsStr: Document that it's not NUL terminated)

Failed merges:

r? @ghost
@bors bors merged commit 2fb6585 into rust-lang:master Sep 18, 2018
@csmoe csmoe deleted the lint_ty_lit branch September 18, 2018 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants