-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-freeze`#![feature(freeze)]``#![feature(freeze)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I tried this code:
#![feature(freeze)]
use std::{cell::Cell, marker::Freeze};
unsafe trait IntoFreeze {
type Frozen: Freeze;
}
unsafe impl<T: Freeze> IntoFreeze for T {
type Frozen = T;
}
unsafe impl<T: IntoFreeze> IntoFreeze for Cell<T> {
type Frozen = T::Frozen;
}
I expected to see this happen: Code should compile since Freeze will never be implemented for Cell
and UnsafeCell
.
Instead, this happened:
error[E0119]: conflicting implementations of trait `IntoFreeze` for type `Cell<_>`
--> src/lib.rs:12:1
|
8 | unsafe impl<T: Freeze> IntoFreeze for T {
| --------------------------------------- first implementation here
...
12 | unsafe impl<T: IntoFreeze> IntoFreeze for Cell<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Cell<_>`
|
= note: upstream crates may add a new impl of trait `std::marker::Freeze` for type `std::cell::Cell<_>` in future versions
For more information about this error, try `rustc --explain E0119`.
Meta
rustc --version --verbose
:
1.85.0-nightly (2024-11-30 7442931d49b199ad0a1c)
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.F-freeze`#![feature(freeze)]``#![feature(freeze)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
jieyouxu commentedon Dec 2, 2024
I think this is intentional, but cc @oli-obk just in case.
oli-obk commentedon Dec 2, 2024
We explicitly
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
which I assumed should allow at least "overlapping" impls forUnsafeCell
, but that may not be true for auto traits? Or does reasoning about negative impls require another feature and only work on nightly?zachs18 commentedon Dec 2, 2024
Note that with
#![feature(with_negative_coherence)]
, theUnsafeCell
impl is allowed (due to the explicitimpl !Freeze for UnsafeCell<_>
), but theCell
impl is still disallowed (IIUC since it gets its "!Freeze
-ness" via auto trait impl instead of an explicit negative impl): playground link.I'm not sure if the original code not being allowed is related to
Freeze
being an auto trait, and don't know of any non-auto traits with negative impls to compare to off the top of my head.Maybe theI misremembered, that is unrelated to negative impls;impl !Fn for &str
? ButFn
is#[fundamental]
which may also affect things.Fn
being#[fundamental]
is why there doesn't need to be animpl !Fn for &str
sourceHmm, though that would indicate that
Freeze
being#[fundamental]
would allow the impls in the OP? but would also make adding or removing interior mutability from a type be a semver-breaking change, but IIRC thas already somewhat of an issue due toconst
s?