Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an impl Trait bound#157966
Merged
rust-bors[bot] merged 1 commit intoJul 6, 2026
Conversation
Collaborator
|
r? @mati865 rustbot has assigned @mati865. Use Why was this reviewer chosen?The reviewer was selected based on:
|
qaijuang
reviewed
Jun 16, 2026
Comment on lines
+4490
to
+4496
| let snippet = tcx.sess.source_map().span_to_snippet(span).unwrap(); | ||
| if span != expr.span { | ||
| err.help(format!( | ||
| "`!` can be coerced to any type; consider casting to a concrete type that implements the trait, e.g. \ | ||
| `{} as SomeType`", snippet | ||
| )); | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| let snippet = tcx.sess.source_map().span_to_snippet(span).unwrap(); | |
| if span != expr.span { | |
| err.help(format!( | |
| "`!` can be coerced to any type; consider casting to a concrete type that implements the trait, e.g. \ | |
| `{} as SomeType`", snippet | |
| )); | |
| } | |
| if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) | |
| && span != expr.span | |
| { | |
| err.help(format!( | |
| "`!` can be coerced to any type; consider casting to a concrete type that implements the trait, e.g. \ | |
| `{snippet} as SomeType`" | |
| )); | |
| } |
Member
|
@rustbot reroll |
davidtwco
requested changes
Jul 2, 2026
Collaborator
|
Reminder, once the PR becomes ready for a review, use |
… fails to satisfy an `impl Trait` bound
e0182f3 to
c9ad0e5
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Contributor
Author
|
@rustbot ready |
davidtwco
approved these changes
Jul 6, 2026
Member
|
@bors r+ rollup |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Jul 6, 2026
…estion-cast-never-type, r=davidtwco Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an `impl Trait` bound Fixes rust-lang#157923
This was referenced Jul 6, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Jul 6, 2026
…uwer Rollup of 12 pull requests Successful merges: - #156976 (enable eager `param_env` norm in new solver) - #158537 (Add `std::io::cursor::WriteThroughCursor`) - #158540 (Move `std::io::Seek` to `core::io`) - #157820 (consider subtyping when checking if an infer var is sized) - #158505 (Update POSIX edition links) - #158853 (Fix typo for link on nto-qnx.md) - #157466 (Better error message when bare type in impl parameter list) - #157966 (Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an `impl Trait` bound) - #158381 (Expose debug scope of statement and terminator in rustc_public) - #158405 (rustc_target: Add ARMv8-M related target features) - #158770 (Weaken guarantee for `From<legacy::RangeInclusive> for RangeInclusive`) - #158820 (Fix rustdoc ICE on deprecated note in inlined re-export chain)
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.
Fixes #157923