Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions clippy_lints/src/casts/unnecessary_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ pub(super) fn check<'tcx>(
lint_unnecessary_cast(cx, expr, literal_str, cast_from, cast_to);
return false;
},
LitKind::Int(_, LitIntType::Unsuffixed) | LitKind::Float(_, LitFloatType::Unsuffixed) => {
return false;
},
Comment on lines -62 to -64
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these removed? It looks like that the fix for clippy_utils/src/numeric_literal.rs is sufficient to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was dead code in the first place

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be exact not dead but if the branching is not taken, it will still result to the function returning false and since the code triggered afterward is cheap it’s not worth the extra complexity of an early return

LitKind::Int(_, LitIntType::Signed(_) | LitIntType::Unsigned(_))
| LitKind::Float(_, LitFloatType::Suffixed(_))
if cast_from.kind() == cast_to.kind() =>
Expand Down
7 changes: 4 additions & 3 deletions clippy_utils/src/numeric_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ impl<'a> NumericLiteral<'a> {

#[must_use]
pub fn new(lit: &'a str, suffix: Option<&'a str>, float: bool) -> Self {
let unsigned_lit = lit.trim_start_matches('-');
// Determine delimiter for radix prefix, if present, and radix.
let radix = if lit.starts_with("0x") {
let radix = if unsigned_lit.starts_with("0x") {
Radix::Hexadecimal
} else if lit.starts_with("0b") {
} else if unsigned_lit.starts_with("0b") {
Radix::Binary
} else if lit.starts_with("0o") {
} else if unsigned_lit.starts_with("0o") {
Radix::Octal
} else {
Radix::Decimal
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/unnecessary_cast.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ mod fixable {

let _num = foo();
}

fn issue_9603() {
let _: f32 = -0x400 as f32;
}
}
4 changes: 4 additions & 0 deletions tests/ui/unnecessary_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ mod fixable {

let _num = foo() as f32;
}

fn issue_9603() {
let _: f32 = -0x400 as f32;
}
}