Skip to content

illegal moves permitted in statics and constants #38520

Closed
@nikomatsakis

Description

@nikomatsakis

This code compiles on nightly today but it should not, because Foo is not Copy:

#![feature(const_fn)]

struct Foo(usize);

const fn get(x: Foo) -> usize {
    x.0
}

const X: Foo = Foo(22);
static Y: usize = get(*&X); // also a problem for `const Y`

fn main() {
}

Note that the get(*&X) in a function body properly results in an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityT-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