Make DerefPure dyn-incompatible

Fixes https://github.com/rust-lang/rust/issues/154619.

If `DerefPure` were dyn-compatible, a trait object of a subtrait of
`DerefPure` could be created by unsize-coercing an existing type that
implements `DerefPure`. But then the trait object could have its own
non-pure impl of `Deref`/`DerefMut`, which is unsound, since the trait
object would implement `DerefPure`. Thus, we make `DerefPure`
dyn-incompatible.
This commit is contained in:
Tim (Theemathas) Chirananthavat
2026-03-31 11:29:40 +07:00
parent cf7da0b727
commit c775de4bee
+1
View File
@@ -293,6 +293,7 @@ fn deref_mut(&mut self) -> &mut T {
/// unchanged.
#[unstable(feature = "deref_pure_trait", issue = "87121")]
#[lang = "deref_pure"]
#[rustc_dyn_incompatible_trait]
pub unsafe trait DerefPure: PointeeSized {}
#[unstable(feature = "deref_pure_trait", issue = "87121")]