mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 20:31:59 +00:00
fix: Yet another false positive invalid cast diagnostic
This commit is contained in:
parent
37acea8052
commit
9cfea3ec29
3 changed files with 134 additions and 26 deletions
|
|
@ -440,8 +440,9 @@ fn main() {
|
|||
q as *const [i32];
|
||||
//^^^^^^^^^^^^^^^^^ error: cannot cast thin pointer `*const i32` to fat pointer `*const [i32]`
|
||||
|
||||
// FIXME: This should emit diagnostics but disabled to prevent many false positives
|
||||
let t: *mut (dyn Trait + 'static) = 0 as *mut _;
|
||||
//^^^^^^^^^^^ error: cannot cast `usize` to a fat pointer `*mut _`
|
||||
|
||||
let mut fail: *const str = 0 as *const str;
|
||||
//^^^^^^^^^^^^^^^ error: cannot cast `usize` to a fat pointer `*const str`
|
||||
let mut fail2: *const str = 0isize as *const str;
|
||||
|
|
@ -1161,6 +1162,49 @@ struct ZerocopyKnownLayoutMaybeUninit(<<Flexible as Field>::Type as KnownLayout>
|
|||
fn test(ptr: *mut [u8]) -> *mut ZerocopyKnownLayoutMaybeUninit {
|
||||
ptr as *mut _
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn regression_19431() {
|
||||
check_diagnostics(
|
||||
r#"
|
||||
//- minicore: coerce_unsized
|
||||
struct Dst([u8]);
|
||||
|
||||
struct Struct {
|
||||
body: Dst,
|
||||
}
|
||||
|
||||
trait Field {
|
||||
type Type: ?Sized;
|
||||
}
|
||||
|
||||
impl Field for Struct {
|
||||
type Type = Dst;
|
||||
}
|
||||
|
||||
trait KnownLayout {
|
||||
type MaybeUninit: ?Sized;
|
||||
type PointerMetadata;
|
||||
}
|
||||
|
||||
impl<T> KnownLayout for [T] {
|
||||
type MaybeUninit = [T];
|
||||
type PointerMetadata = usize;
|
||||
}
|
||||
|
||||
impl KnownLayout for Dst {
|
||||
type MaybeUninit = Dst;
|
||||
type PointerMetadata = <[u8] as KnownLayout>::PointerMetadata;
|
||||
}
|
||||
|
||||
struct ZerocopyKnownLayoutMaybeUninit(<<Struct as Field>::Type as KnownLayout>::MaybeUninit);
|
||||
|
||||
fn test(ptr: *mut ZerocopyKnownLayoutMaybeUninit) -> *mut <<Struct as Field>::Type as KnownLayout>::MaybeUninit {
|
||||
ptr as *mut _
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue