mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-30 14:52:56 +03:00
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:
@@ -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
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user