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

Compile error due to the wrong literal data type #68951

Closed
Disasm opened this issue Feb 8, 2020 · 1 comment · Fixed by #77388
Closed

Compile error due to the wrong literal data type #68951

Disasm opened this issue Feb 8, 2020 · 1 comment · Fixed by #77388
Labels
A-inference Area: Type inference C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Disasm
Copy link
Contributor

Disasm commented Feb 8, 2020

I tried this code:

fn main() {
    let array = [0x42u8; 10];
    for b in &array {
        let lo = b & 0xf;
        let hi = (b >> 4) & 0xf;
    }
}

Playground

I expected to see this happen: it should be compiled

Instead, this happened:

error[E0277]: no implementation for `u8 & i32`
 --> src/main.rs:5:27
  |
5 |         let hi = (b >> 4) & 0xf;
  |                           ^ no implementation for `u8 & i32`
  |
  = help: the trait `std::ops::BitAnd<i32>` is not implemented for `u8`

Meta

rustc --version --verbose:

rustc 1.41.0 (5e1a79984 2020-01-27)
binary: rustc
commit-hash: 5e1a799842ba6ed4a57e91f7ab9435947482f7d8
commit-date: 2020-01-27
host: x86_64-unknown-linux-gnu
release: 1.41.0
LLVM version: 9.0

The same happens on beta and nightly.

Backtrace

Compiling playground v0.0.1 (/playground)
error[E0277]: no implementation for `u8 & i32`
 --> src/main.rs:5:27
  |
5 |         let hi = (b >> 4) & 0xf;
  |                           ^ no implementation for `u8 & i32`
  |
  = help: the trait `std::ops::BitAnd<i32>` is not implemented for `u8`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

@Disasm Disasm added the C-bug Category: This is a bug. label Feb 8, 2020
@jonas-schievink jonas-schievink added A-inference Area: Type inference T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 8, 2020
@pragmatrix
Copy link

Looks like this bug has been fixed in one of the recent Rust updates. Rust stable 1.45.2 compiles the code above without errors.

@jonas-schievink jonas-schievink added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 26, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 3, 2020
Add some regression tests

Closes rust-lang#66501
Closes rust-lang#68951
Closes rust-lang#72565
Closes rust-lang#74244
Closes rust-lang#75299

The first issue is fixed in 1.43.0, other issues are fixed in the recent nightly.
@bors bors closed this as completed in f09c962 Oct 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants