Skip to content

"error: target type not found for const cast" triggered by the position of a mod item or by adding #[deriving(Show)] #18128

Closed
@japaric

Description

@japaric

STR

// main.rs
extern crate libc;

#[cfg(error)]
mod trigger;

const CSTOPB_: u32 = 64;
const CREAD_: u32 = 128;

const CSTOPB: u32 = CSTOPB_;
// This cast to `c_uint` is necessary
const CREAD: u32 = CREAD_ as ::libc::c_uint;

#[cfg(not(error))]
mod trigger;

fn main() {}
// trigger.rs
#[repr(u32)]
enum Bit {
    CSTOPB = super::CSTOPB,
    CREAD = super::CREAD,
}

Output

rustc --cfg error main.rs generates the following compiler error:

main.rs:12:30: 12:44 error: target type not found for const cast
main.rs:12 const CREAD: u32 = CREAD_ as ::libc::c_uint;

rustc main.rs compiles successfully.

Version

rustc 0.13.0-dev (93e589c87 2014-10-17 09:22:14 +0000)

I can trace this behavior back to 0.11


I thought that the position of the items in a crate (except for use imports and extern crates which must go at the beginning) didn't affect the compiler output. That makes me think this is a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions