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

Strange non-primitive cast error near erroneous code #43825

Closed
0x7CFE opened this issue Aug 12, 2017 · 2 comments
Closed

Strange non-primitive cast error near erroneous code #43825

0x7CFE opened this issue Aug 12, 2017 · 2 comments
Labels
A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@0x7CFE
Copy link

0x7CFE commented Aug 12, 2017

tl;dr; If you comment out the let error line, all will compile, obviously.

fn main() {
    let error = error; // Comment me
    for value in (1..10).map(|a| a as f32) {
        
    }
}

However, in presence of it, compiler complains

error[E0605]: non-primitive cast: `{integer}` as `f32`
 --> src/main.rs:3:34
  |
3 |     for value in (1..10).map(|a| a as f32) {
  |                                  ^^^^^^^^
  |
  = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait

…which is strange and may mislead user in more complex situation. Looks like broken code affects type inference somehow. By the way, error will also appear, if you put erroneous line after the loop.

rustc 1.21.0-nightly (13d94d5fa 2017-08-10)
binary: rustc
commit-hash: 13d94d5fa8129a34f5c77a1bcd76983f5aed2434
commit-date: 2017-08-10
host: x86_64-unknown-linux-gnu
release: 1.21.0-nightly
LLVM version: 4.0
@Mark-Simulacrum
Copy link
Member

#33690 is likely the same/similar.

@Mark-Simulacrum Mark-Simulacrum added A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 13, 2017
@chyvonomys
Copy link

I also got this error on similar code:

let chars = (0..200).map(|i| {
    let pos = (
        CW * ((i % 50) as f32 + 0.5f32),
        500f32 - CH * ((i / 50) as f32 + 0.5f32),
    )
    //...
}).collect();

Compiler complains about (i % 50) as f32 and (i / 50) as f32.
In my case real error is after this code.

rustc 1.20.0 (f3d6973f4 2017-08-27)
binary: rustc
commit-hash: f3d6973f41a7d1fb83029c9c0ceaf0f5d4fd7208
commit-date: 2017-08-27
host: x86_64-apple-darwin
release: 1.20.0
LLVM version: 4.0

@bors bors closed this as completed in 6aca330 Dec 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants