Merge pull request #21699 from Albab-Hasan/fix/ptr-cast-add-auto-trait-not-detected

fix: Detect E0804 when casting raw ptr-to-dyn adds auto traits
This commit is contained in:
Shoyu Vanilla (Flint)
2026-02-27 02:11:49 +00:00
committed by GitHub
2 changed files with 3 additions and 5 deletions
@@ -328,11 +328,7 @@ fn check_ptr_ptr_cast(
//
// Note that trait upcasting goes through a different mechanism (`coerce_unsized`)
// and is unaffected by this check.
(Some(src_principal), Some(dst_principal)) => {
if src_principal == dst_principal {
return Ok(());
}
(Some(src_principal), Some(_)) => {
// We need to reconstruct trait object types.
// `m_src` and `m_dst` won't work for us here because they will potentially
// contain wrappers, which we do not care about.
@@ -517,11 +517,13 @@ trait Trait<'a> {}
fn add_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send) {
x as _
//^^^^^^ error: cannot add auto trait to dyn bound via pointer cast
}
// (to test diagnostic list formatting)
fn add_multiple_auto<'a>(x: *mut dyn Trait<'a>) -> *mut (dyn Trait<'a> + Send + Sync + Unpin) {
x as _
//^^^^^^ error: cannot add auto trait to dyn bound via pointer cast
}
"#,
);