Skip to content

Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an impl Trait bound#157966

Open
Muhtasim-Rasheed wants to merge 1 commit into
rust-lang:mainfrom
Muhtasim-Rasheed:issue-157923-suggestion-cast-never-type
Open

Emit a suggestion to cast the never type into a concrete type when it fails to satisfy an impl Trait bound#157966
Muhtasim-Rasheed wants to merge 1 commit into
rust-lang:mainfrom
Muhtasim-Rasheed:issue-157923-suggestion-cast-never-type

Conversation

@Muhtasim-Rasheed

@Muhtasim-Rasheed Muhtasim-Rasheed commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #157923

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

r? @mati865

rustbot has assigned @mati865.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 20 candidates

@qaijuang qaijuang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a quick glance 👀

View changes since this review

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
));
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`"
));
}

@mati865

mati865 commented Jun 17, 2026

Copy link
Copy Markdown
Member

@rustbot reroll

@rustbot rustbot assigned davidtwco and unassigned mati865 Jun 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emit a suggestion to cast ! to a concrete type when ! is infered as the hidden type for impl Trait and ! doesn't implement Trait

5 participants