about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-04-25 00:53:59 +0200
committerGitHub <noreply@github.com>2025-04-25 00:53:59 +0200
commit02ebca2784329d8712dfa7164545042c73e073e9 (patch)
tree4a1c64724a4f9d5eb21db17c3fef0b797543759b /compiler/rustc_codegen_llvm/src
parent4c0d38b93ed22e17b18948ed64008afd495ac5b0 (diff)
parentc9deaf6aaa8e389e11e39abb9aca77e6340d176e (diff)
downloadrust-02ebca2784329d8712dfa7164545042c73e073e9.tar.gz
rust-02ebca2784329d8712dfa7164545042c73e073e9.zip
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 #135412
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
0 files changed, 0 insertions, 0 deletions