Skip to content

Compile error due to the wrong literal data type #68951

@Disasm

Description

@Disasm

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. 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions