Skip to content

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

Closed
@kpreid

Description

@kpreid
Contributor

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

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Dec 26, 2024
kpreid

kpreid commented on Dec 26, 2024

@kpreid
ContributorAuthor

@rustbot label +A-const-eval

added
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)
on Dec 26, 2024
added a commit that references this issue on Dec 27, 2024

Rollup merge of rust-lang#134798 - compiler-errors:err-auto, r=jackh726

26fb78a
added a commit that references this issue on Dec 27, 2024
ee657f8
added a commit that references this issue on Dec 28, 2024

Rollup merge of rust-lang#134798 - compiler-errors:err-auto, r=jackh726

d8435f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsT-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

    Participants

    @kpreid@compiler-errors@rustbot

    Issue actions

      Spurious error[E0492]: constants cannot refer to interior mutable data when an undeclared type is found · Issue #134796 · rust-lang/rust