Skip to content
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

Spurious error[E0492]: constants cannot refer to interior mutable data when an undeclared type is found #134796

Open
kpreid opened this issue Dec 26, 2024 · 1 comment · May be fixed by #134798
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kpreid
Copy link
Contributor

kpreid commented Dec 26, 2024

Code

struct MyStruct {
    foo: Option<UndefinedType>,
}
impl MyStruct {
    pub const EMPTY_REF: &'static Self = &Self::EMPTY;
    pub const EMPTY: Self = Self {
        foo: None,
    };
}

Current output

error[E0412]: cannot find type `UndefinedType` in this scope
 --> src/lib.rs:2:17
  |
2 |     foo: Option<UndefinedType>,
  |                 ^^^^^^^^^^^^^ not found in this scope
  |
help: you might be missing a type parameter
  |
1 | struct MyStruct<UndefinedType> {
  |                +++++++++++++++

error[E0492]: constants cannot refer to interior mutable data
 --> src/lib.rs:5:42
  |
5 |     pub const EMPTY_REF: &'static Self = &Self::EMPTY;
  |                                          ^^^^^^^^^^^^ this borrow of an interior mutable value may end up in the final value

Desired output

The E0492 interior mutability error is spurious and should not be emitted.

Rust Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1
@kpreid kpreid added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 26, 2024
@kpreid
Copy link
Contributor Author

kpreid commented Dec 26, 2024

@rustbot label +A-const-eval

@rustbot rustbot added the A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) label Dec 26, 2024
@compiler-errors compiler-errors self-assigned this Dec 26, 2024
@compiler-errors compiler-errors linked a pull request Dec 26, 2024 that will close this issue
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, ...) A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants