Skip to content

Constant evaluation error: attempted to read undefined bytes #51300

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
Thinkofname opened this issue Jun 2, 2018 · 0 comments · Fixed by #51307
Closed

Constant evaluation error: attempted to read undefined bytes #51300

Thinkofname opened this issue Jun 2, 2018 · 0 comments · Fixed by #51307
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@Thinkofname
Copy link

I saw that #51086 was closed when #51225 was merged so I thought it would fix the same error on my own code as well however as of nightly: rustc 1.28.0-nightly (aa094a43c 2018-06-01) it still happens.

Code:

#[derive(PartialEq, Eq, Clone, Copy)]
pub struct Stat {
    pub id: u8,
    pub index: usize,
}

impl Stat {
    pub const STUDENT_HAPPINESS: Stat = Stat{
        id: 0,
        index: 0,
    };
    pub const STUDENT_HUNGER: Stat = Stat{
        id: 0,
        index: Self::STUDENT_HAPPINESS.index + 1,
    };

}

pub fn from_index(id: u8, index: usize) -> Option<Stat> {
    let stat = Stat{id, index};
    match stat {
        Stat::STUDENT_HAPPINESS => Some(Stat::STUDENT_HAPPINESS),
        Stat::STUDENT_HUNGER => Some(Stat::STUDENT_HUNGER),
        _ => None,
    }
}

fn main() { }

Playground: http://play.rust-lang.org/?gist=cf51c77c20f06ca15f1dc2cc4fa779b0&version=nightly&mode=debug

From what I can tell its an alignment issue because changing id from a u8 to a u64 fixes the issue.

@oli-obk oli-obk self-assigned this Jun 2, 2018
@oli-obk oli-obk added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. labels Jun 2, 2018
bors added a commit that referenced this issue Jun 4, 2018
ScalarPairs are offset==0 field + other non-zst field

r? @eddyb

fixes #51300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants