Skip to content

const_err does not trigger on associated constants #71282

Open
@Nemo157

Description

@Nemo157

I tried this code:

pub struct Foo;

pub const FOO: Foo = Foo::new(1);

impl Foo {
    pub const FOO: Self = Self::new(1);

    pub const fn new(i: usize) -> Foo {
        [][i] = 5;
        Foo
    }
}

I expected to see this happen: Both FOO and Foo::FOO should trigger const_err errors.

Instead, this happened: Only FOO was marked with const_err

Meta

Checked on current stable (1.42) and nightly (2020-04-17) on the playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions