about summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide-diagnostics
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-10-14 11:24:08 +0000
committerbors <bors@rust-lang.org>2024-10-14 11:24:08 +0000
commit0b99f29198d2bbab28ad8b9dd8944ce9be5e5cfe (patch)
treef9db3f74ea93d4b1fb9ce8734954adb4bbadbf9a /src/tools/rust-analyzer/crates/ide-diagnostics
parent540891b93426eeebe5f592c5a05e7bee28397af5 (diff)
parent8115a1843e4ab020695ba67968e7921ecaaf524b (diff)
downloadrust-0b99f29198d2bbab28ad8b9dd8944ce9be5e5cfe.tar.gz
rust-0b99f29198d2bbab28ad8b9dd8944ce9be5e5cfe.zip
Auto merge of #18217 - ChayimFriedman2:cast-unknown-ptr, r=Veykril
fix: Comment out cast checks for unknown ptr kind

Just like we don't check for types containing unknown.

Fixes #18214.

See also https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Another.20case.20of.20.2318064.3F.
Diffstat (limited to 'src/tools/rust-analyzer/crates/ide-diagnostics')
-rw-r--r--src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs54
1 files changed, 36 insertions, 18 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs
index ad4baf5e3a4..4bd29b8c79b 100644
--- a/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs
+++ b/src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/invalid_cast.rs
@@ -95,10 +95,10 @@ pub(crate) fn invalid_cast(ctx: &DiagnosticsContext<'_>, d: &hir::InvalidCast) -
             DiagnosticCode::RustcHardError("E0605"),
             format_ty!(ctx, "non-primitive cast: `{}` as `{}`", d.expr_ty, d.cast_ty),
         ),
-        CastError::UnknownCastPtrKind | CastError::UnknownExprPtrKind => (
-            DiagnosticCode::RustcHardError("E0641"),
-            "cannot cast to a pointer of an unknown kind".to_owned(),
-        ),
+        // CastError::UnknownCastPtrKind | CastError::UnknownExprPtrKind => (
+        //     DiagnosticCode::RustcHardError("E0641"),
+        //     "cannot cast to a pointer of an unknown kind".to_owned(),
+        // ),
     };
     Diagnostic::new(code, message, display_range)
 }
@@ -457,20 +457,20 @@ fn foo<T: ?Sized>() {
         );
     }
 
-    #[test]
-    fn order_dependent_cast_inference() {
-        check_diagnostics(
-            r#"
-//- minicore: sized
-fn main() {
-    let x = &"hello";
-    let mut y = 0 as *const _;
-              //^^^^^^^^^^^^^ error: cannot cast to a pointer of an unknown kind
-    y = x as *const _;
-}
-"#,
-        );
-    }
+    //     #[test]
+    //     fn order_dependent_cast_inference() {
+    //         check_diagnostics(
+    //             r#"
+    // //- minicore: sized
+    // fn main() {
+    //     let x = &"hello";
+    //     let mut y = 0 as *const _;
+    //               //^^^^^^^^^^^^^ error: cannot cast to a pointer of an unknown kind
+    //     y = x as *const _;
+    // }
+    // "#,
+    //         );
+    //     }
 
     #[test]
     fn ptr_to_ptr_different_regions() {
@@ -1111,4 +1111,22 @@ fn foo() {
             "#,
         );
     }
+
+    #[test]
+    fn cast_isize_to_infer_pointer() {
+        check_diagnostics(
+            r#"
+//- minicore: coerce_unsized
+struct Foo {}
+
+struct Wrap<'a>(&'a mut Foo);
+
+fn main() {
+    let lparam: isize = 0;
+
+    let _wrap = Wrap(unsafe { &mut *(lparam as *mut _) });
+}
+        "#,
+        );
+    }
 }