-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)P-mediumMedium priorityMedium priorityT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.relnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.
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
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)P-mediumMedium priorityMedium priorityT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.relnotesMarks issues that should be documented in the release notes of the next release.Marks issues that should be documented in the release notes of the next release.