Improve E0308 error message for impl Trait return mismatches#155546
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Apr 22, 2026
Merged
Improve E0308 error message for impl Trait return mismatches#155546rust-bors[bot] merged 1 commit intorust-lang:mainfrom
impl Trait return mismatches#155546rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
When a function returns `impl Trait`, all branches must return the same
concrete type. Previously, the compiler showed:
expected `First` because of return type
This was misleading, as it suggested the return type was `First`, rather
than any single type implementing the trait.
Update the diagnostic to:
expected a single type implementing `Value` because of return type
Also highlight the first return expression to make it clearer why
subsequent returns do not match.
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Collaborator
|
r? @chenyukang rustbot has assigned @chenyukang. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Contributor
Author
|
Fix: #155366 |
Contributor
Author
|
cc: @DanielEScherzer |
DanielEScherzer
approved these changes
Apr 20, 2026
Contributor
|
@bors r+ |
Contributor
rust-bors Bot
pushed a commit
that referenced
this pull request
Apr 21, 2026
…uwer Rollup of 5 pull requests Successful merges: - #155546 (Improve E0308 error message for `impl Trait` return mismatches) - #152834 (Fix incorrect `let` to `const` suggestion for pattern bindings) - #155425 (Remove duplicated `Flags` methods.) - #155547 (Use per-parent disambiguators everywhere) - #155590 (Remove AttributeLintKind variants - part 5)
rust-timer
added a commit
that referenced
this pull request
Apr 22, 2026
Rollup merge of #155546 - Unique-Usman:ua/impl_traits, r=estebank Improve E0308 error message for `impl Trait` return mismatches When a function returns `impl Trait`, all branches must return the same concrete type. Previously, the compiler showed: expected `First` because of return type This was misleading, as it suggested the return type was `First`, rather than any single type implementing the trait. Update the diagnostic to: expected a single type implementing `Value` because of return type Also highlight the first return expression to make it clearer why subsequent returns do not match.
Member
nit: @Unique-Usman The issue is automatically closed only when this phrase is in the PR description, not comment. |
Contributor
Author
|
noted. |
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Apr 26, 2026
Add boxing suggestions for `impl Trait` return type mismatches A sort of a follow up pr to this -> rust-lang#155546
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Apr 26, 2026
Add boxing suggestions for `impl Trait` return type mismatches A sort of a follow up pr to this -> rust-lang#155546
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Apr 27, 2026
Add boxing suggestions for `impl Trait` return type mismatches A sort of a follow up pr to this -> rust-lang#155546
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.
When a function returns
impl Trait, all branches must return the same concrete type. Previously, the compiler showed:This was misleading, as it suggested the return type was
First, rather than any single type implementing the trait.Update the diagnostic to:
Also highlight the first return expression to make it clearer why subsequent returns do not match.