about summary refs log tree commit diff
path: root/tests/ui/coercion
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-04-23 15:58:50 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-04-24 03:20:19 +0500
commitc9deaf6aaa8e389e11e39abb9aca77e6340d176e (patch)
treefe7cf8ead3db254ec39e5968d7580850dbb334e1 /tests/ui/coercion
parentb8005bff3248cfc6e327faf4fa631ac49bb49ba9 (diff)
downloadrust-c9deaf6aaa8e389e11e39abb9aca77e6340d176e.tar.gz
rust-c9deaf6aaa8e389e11e39abb9aca77e6340d176e.zip
fix for issue 135412
Diffstat (limited to 'tests/ui/coercion')
-rw-r--r--tests/ui/coercion/issue-73886.stderr7
-rw-r--r--tests/ui/coercion/non-primitive-cast-135412.fixed10
-rw-r--r--tests/ui/coercion/non-primitive-cast-135412.rs10
-rw-r--r--tests/ui/coercion/non-primitive-cast-135412.stderr29
4 files changed, 55 insertions, 1 deletions
diff --git a/tests/ui/coercion/issue-73886.stderr b/tests/ui/coercion/issue-73886.stderr
index a6f8ba65ab5..0d4c90017cf 100644
--- a/tests/ui/coercion/issue-73886.stderr
+++ b/tests/ui/coercion/issue-73886.stderr
@@ -8,9 +8,14 @@ error[E0605]: non-primitive cast: `u32` as `Option<_>`
   --> $DIR/issue-73886.rs:4:13
    |
 LL |     let _ = 7u32 as Option<_>;
-   |             ^^^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Option<_>::from(7u32)`
+   |             ^^^^^^^^^^^^^^^^^
    |
    = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
+help: consider using the `From` trait instead
+   |
+LL -     let _ = 7u32 as Option<_>;
+LL +     let _ = Option::<_>::from(7u32);
+   |
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/coercion/non-primitive-cast-135412.fixed b/tests/ui/coercion/non-primitive-cast-135412.fixed
new file mode 100644
index 00000000000..5cadc9368d5
--- /dev/null
+++ b/tests/ui/coercion/non-primitive-cast-135412.fixed
@@ -0,0 +1,10 @@
+//@ run-rustfix
+
+use std::sync::Arc;
+
+fn main() {
+    let _ = Option::<_>::from(7u32);
+    //~^ ERROR non-primitive cast: `u32` as `Option<_>`
+    let _ = Arc::<str>::from("String");
+    //~^ ERROR non-primitive cast: `&'static str` as `Arc<str>`
+}
diff --git a/tests/ui/coercion/non-primitive-cast-135412.rs b/tests/ui/coercion/non-primitive-cast-135412.rs
new file mode 100644
index 00000000000..67a3ef340d2
--- /dev/null
+++ b/tests/ui/coercion/non-primitive-cast-135412.rs
@@ -0,0 +1,10 @@
+//@ run-rustfix
+
+use std::sync::Arc;
+
+fn main() {
+    let _ = 7u32 as Option<_>;
+    //~^ ERROR non-primitive cast: `u32` as `Option<_>`
+    let _ = "String" as Arc<str>;
+    //~^ ERROR non-primitive cast: `&'static str` as `Arc<str>`
+}
diff --git a/tests/ui/coercion/non-primitive-cast-135412.stderr b/tests/ui/coercion/non-primitive-cast-135412.stderr
new file mode 100644
index 00000000000..7e5861f83e9
--- /dev/null
+++ b/tests/ui/coercion/non-primitive-cast-135412.stderr
@@ -0,0 +1,29 @@
+error[E0605]: non-primitive cast: `u32` as `Option<_>`
+  --> $DIR/non-primitive-cast-135412.rs:6:13
+   |
+LL |     let _ = 7u32 as Option<_>;
+   |             ^^^^^^^^^^^^^^^^^
+   |
+   = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
+help: consider using the `From` trait instead
+   |
+LL -     let _ = 7u32 as Option<_>;
+LL +     let _ = Option::<_>::from(7u32);
+   |
+
+error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
+  --> $DIR/non-primitive-cast-135412.rs:8:13
+   |
+LL |     let _ = "String" as Arc<str>;
+   |             ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
+help: consider using the `From` trait instead
+   |
+LL -     let _ = "String" as Arc<str>;
+LL +     let _ = Arc::<str>::from("String");
+   |
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0605`.