Skip to content

std::marker::Freeze disallows blanket impl since it "could be implemented on Cell and UnsafeCell in the future" #133714

Open
@ds84182

Description

@ds84182

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

No one assigned

    Labels

    C-bugCategory: This is a bug.F-freeze`#![feature(freeze)]`T-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

    No branches or pull requests

    Issue actions