Skip to content

cast_lossless on const item #2267

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

Closed
letheed opened this issue Dec 11, 2017 · 7 comments
Closed

cast_lossless on const item #2267

letheed opened this issue Dec 11, 2017 · 7 comments
Labels
C-bug Category: Clippy is not doing the correct thing E-needs-test Call for participation: writing tests good-first-issue These issues are a good way to get started with Clippy

Comments

@letheed
Copy link

letheed commented Dec 11, 2017

const FOO: i32 = 42;
const FOO_I64: i64 = 42 as i64;

Triggers the suggestion try: i64::from(FOO) which isn't possible (yet?).

@oli-obk
Copy link
Contributor

oli-obk commented Dec 11, 2017

I cannot reproduce on the playpen. Are you sure you're running the latest clippy?

@letheed
Copy link
Author

letheed commented Dec 11, 2017

My mistake I meant:

const FOO: i32 = 42;
const FOO_I64: i64 = FOO as i64;

@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy C-bug Category: Clippy is not doing the correct thing labels Dec 11, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Dec 11, 2017

We should not be doing this suggestion inside constants until From/Into are usable in constants

@oli-obk
Copy link
Contributor

oli-obk commented Dec 17, 2017

Just needs a regression test

@oli-obk oli-obk reopened this Dec 17, 2017
@oli-obk oli-obk added E-needs-test Call for participation: writing tests and removed C-bug Category: Clippy is not doing the correct thing labels Dec 17, 2017
@cipriancraciun
Copy link

cipriancraciun commented Jul 2, 2018

I just got this suggestion when I use value as u64 (where value is u32), but when used in a const fn.

I assume this is a regression?

(I'm using latest clippy (0.0.211) and rust-nightly.)

    pub const fn for_builtin (handle : u32) -> (Handle) {
        return Handle ( handle as u64 );
    }
error: casting u32 to u64 may become silently lossy if types change
   --> sources/runtime.rs:211:19
    |
211 |         return Handle ( handle as u64 );
    |                         ^^^^^^^^^^^^^ help: try: `u64::from(handle)`

@oli-obk
Copy link
Contributor

oli-obk commented Jul 2, 2018

not a regression, just a bug ;) Const fn and constants have mostly the same rules, so we shouldn't suggest non-const stuff

@oli-obk oli-obk added the C-bug Category: Clippy is not doing the correct thing label Jul 2, 2018
@phansch
Copy link
Member

phansch commented Jan 25, 2019

New issue for this is #3656

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-needs-test Call for participation: writing tests good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

No branches or pull requests

4 participants