Closed
Description
This code works on stable, but not latest nightly
#[derive(Copy, Clone)]
pub struct S<T>(T);
#[doc(hidden)]
pub trait DynTrait {
type VTable: Copy + 'static;
const VTABLE: &'static Self::VTable;
}
impl<T: DynTrait> DynTrait for S<T> {
type VTable = T::VTable;
const VTABLE: &'static Self::VTable = &{ *T::VTABLE };
}
Error:
error[E0492]: constants cannot refer to interior mutable data
--> src/lib.rs:12:43
|
12 | const VTABLE: &'static Self::VTable = &{ *T::VTABLE };
| ^^^^^^^^^^^^^^^ this borrow of an interior mutable value may end up in the final value
rustc --version --verbose
:
rustc 1.78.0-nightly (6672c16af 2024-02-17)
binary: rustc
commit-hash: 6672c16afcd4db8acdf08a6984fd4107bf07632c
commit-date: 2024-02-17
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Medium priorityRelevant to the language team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.Performance or correctness regression from stable to nightly.Marks issues that should be documented in the release notes of the next release.