Closed Bug 1488003 Opened 6 years ago Closed 5 years ago

webdriver: Cast i32 to i64 using "::from" instead of "as"

Categories

(Testing :: geckodriver, enhancement, P2)

enhancement

Tracking

(Not tracked)

RESOLVED INCOMPLETE

People

(Reporter: ato, Assigned: ato)

Details

Attachments

(1 file)

To ensure we don’t perform a lossy cast from i32 to i64, we should use 

> i64::from(x)

rather than

> x as i64
Assignee: nobody → ato
Status: NEW → ASSIGNED
Attachment #9005829 - Flags: review?(hskupin)
Comment on attachment 9005829 [details] [diff] [review]
webdriver: fix lossy i64 cast

Review of attachment 9005829 [details] [diff] [review]:
-----------------------------------------------------------------

::: testing/webdriver/src/command.rs
@@ +578,3 @@
>      let value = match opt {
>          Some(n) => {
> +            if n < i64::from(i32::min_value()) || n > i64::from(i32::max_value()) {

Mind to explain me when this can be lossy? I can agree with i64->i32, but what's broken for i32->i64?
Attachment #9005829 - Flags: review?(hskupin)
The warning from clippy is this:

> warning: casting i32 to i64 may become silently lossy if types change
>    --> testing/webdriver/src/command.rs:576:20
>     |
> 576 |             if n < i32::min_value() as i64 || n > i32::max_value() as i64 {
>     |                    ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `i64::from(i32::min_value())`
>     |
>     = note: #[warn(clippy::cast_lossless)] on by default
>     = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#clippy::cast_lossless

I think my commit message is overstating what it’s fixing: it’s in
fact not fixing a lossy cast, but a potential future accident if
the type itself were to change.

Functionally speaking, I think the patch is equivalent.
Priority: -- → P2
Status: ASSIGNED → NEW
I think we should probably have one bug to resolve all the outstanding
clippy lint violations for geckodriver and its in-tree dependencies.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INCOMPLETE
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: