Improved diagnostics for non-primitive cast on non-primitive types (Arc, Option)#140196
Merged
bors merged 1 commit intorust-lang:masterfrom Apr 25, 2025
Merged
Improved diagnostics for non-primitive cast on non-primitive types (Arc, Option)#140196bors merged 1 commit intorust-lang:masterfrom
Arc, Option)#140196bors merged 1 commit intorust-lang:masterfrom
Conversation
Collaborator
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use |
ShE3py
reviewed
Apr 23, 2025
wesleywiser
approved these changes
Apr 24, 2025
Member
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 25, 2025
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#137096 (Stabilize flags for doctest cross compilation) - rust-lang#140148 (CI: use aws codebuild for job dist-arm-linux) - rust-lang#140187 ([AIX] Handle AIX dynamic library extensions within c-link-to-rust-dylib run-make test) - rust-lang#140196 (Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`)) - rust-lang#140210 (Work around cygwin issue on condvar timeout) - rust-lang#140213 (mention about `x.py setup` in `INSTALL.md`) - rust-lang#140229 (`DelimArgs` tweaks) - rust-lang#140248 (Fix impl block items indent) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 25, 2025
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#137096 (Stabilize flags for doctest cross compilation) - rust-lang#140148 (CI: use aws codebuild for job dist-arm-linux) - rust-lang#140187 ([AIX] Handle AIX dynamic library extensions within c-link-to-rust-dylib run-make test) - rust-lang#140196 (Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`)) - rust-lang#140210 (Work around cygwin issue on condvar timeout) - rust-lang#140213 (mention about `x.py setup` in `INSTALL.md`) - rust-lang#140229 (`DelimArgs` tweaks) - rust-lang#140248 (Fix impl block items indent) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Apr 25, 2025
Rollup merge of rust-lang#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 rust-lang#135412
github-actions bot
pushed a commit
to model-checking/verify-rust-std
that referenced
this pull request
May 9, 2025
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#137096 (Stabilize flags for doctest cross compilation) - rust-lang#140148 (CI: use aws codebuild for job dist-arm-linux) - rust-lang#140187 ([AIX] Handle AIX dynamic library extensions within c-link-to-rust-dylib run-make test) - rust-lang#140196 (Improved diagnostics for non-primitive cast on non-primitive types (`Arc`, `Option`)) - rust-lang#140210 (Work around cygwin issue on condvar timeout) - rust-lang#140213 (mention about `x.py setup` in `INSTALL.md`) - rust-lang#140229 (`DelimArgs` tweaks) - rust-lang#140248 (Fix impl block items indent) r? `@ghost` `@rustbot` modify labels: rollup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
here is a small fix that improving error messaging when user is trying to do something like this
before it looks like this
which looks horrible to be honest
so i made a small fix that make errors looks like this
What improves?
Arc<str>::from("x")which makes no sense because of missing::Related Issue
fixes #135412