-
Notifications
You must be signed in to change notification settings - Fork 390
Commit 3815e09
authored
Rollup merge of #140196 - Kivooeo:new-fix-two, r=wesleywiser
Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`)
here is a small fix that improving error messaging when user is trying to do something like this
```rust
let _ = "x" as Arc<str>;
let _ = 2 as Option<i32>;
```
before it looks like this
```rust
error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
--> src\main.rs:3:13
|
3 | let _ = "x" as Arc<str>;
| ^^^^^^^^^^^^^^^ help: consider using the `From` trait instead: `Arc<str>::from("x")`
error[E0605]: non-primitive cast: `i32` as `Option<i32>`
--> src\main.rs:4:13
|
4 | let _ = 2 as Option<i32>;
```
which looks horrible to be honest
so i made a small fix that make errors looks like this
```rust
error[E0605]: non-primitive cast: `&'static str` as `Arc<str>`
|
3 | let _ = "x" 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
|
3 - let _ = "x" as Arc<str>;
3 + let _ = Arc::<str>::from("x");
|
error[E0605]: non-primitive cast: `i32` as `Option<i32>`
|
4 | let _ = 2 as Option<i32>;
| ^^^^^^^^^^^^^^^^
|
= 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
|
4 - let _ = 2 as Option<i32>;
4 + let _ = Option::<i32>::from(2);
```
**What improves?**
1) `Arc<str>::from("x")` which makes no sense because of missing `::`
2) readability
**Related Issue**
fixes #135412File tree
Expand file treeCollapse file tree
0 file changed
+0
-0
lines changedFilter options
Expand file treeCollapse file tree
0 file changed
+0
-0
lines changed
0 commit comments