Skip to content

Avoid misleading closure return type note#155770

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
chenyukang:yukang-fix-155670-closure-return-note
Apr 27, 2026
Merged

Avoid misleading closure return type note#155770
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
chenyukang:yukang-fix-155670-closure-return-note

Conversation

@chenyukang
Copy link
Copy Markdown
Member

@chenyukang chenyukang commented Apr 25, 2026

Fixes #155670

@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 Apr 25, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 25, 2026

r? @wesleywiser

rustbot has assigned @wesleywiser.
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 17 candidates

@wesleywiser
Copy link
Copy Markdown
Member

Thanks @chenyukang!

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 26, 2026

📌 Commit 5e00484 has been approved by wesleywiser

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 26, 2026
…re-return-note, r=wesleywiser

Avoid misleading closure return type note

Fixes rust-lang#155670
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 26, 2026
…re-return-note, r=wesleywiser

Avoid misleading closure return type note

Fixes rust-lang#155670
rust-bors Bot pushed a commit that referenced this pull request Apr 26, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #149624 (Fix requires_lto targets needing lto set in cargo)
 - #152443 (NVPTX: Drop support for old architectures and old ISAs)
 - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.)
 - #155588 (Implement more traits for FRTs)
 - #155682 (Add boxing suggestions for `impl Trait` return type mismatches)
 - #155770 (Avoid misleading closure return type note)
 - #155818 (Convert attribute `FinalizeFn` to fn pointer)
 - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`)
 - #155835 (couple of `crate_name` cleanups)
rust-bors Bot pushed a commit that referenced this pull request Apr 27, 2026
Rollup of 12 pull requests

Successful merges:

 - #149624 (Fix requires_lto targets needing lto set in cargo)
 - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.)
 - #155579 (Make Rcs and Arcs use pointer comparison for unsized types)
 - #155588 (Implement more traits for FRTs)
 - #155708 (Fix heap overflow in slice::join caused by misbehaving Borrow)
 - #155778 (Avoid Vec allocation in TyCtxt::mk_place_elem)
 - #151014 (std: sys: process: uefi: Add program searching)
 - #155682 (Add boxing suggestions for `impl Trait` return type mismatches)
 - #155770 (Avoid misleading closure return type note)
 - #155818 (Convert attribute `FinalizeFn` to fn pointer)
 - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`)
 - #155835 (couple of `crate_name` cleanups)
@rust-bors rust-bors Bot merged commit 78569d8 into rust-lang:main Apr 27, 2026
11 checks passed
rust-timer added a commit that referenced this pull request Apr 27, 2026
Rollup merge of #155770 - chenyukang:yukang-fix-155670-closure-return-note, r=wesleywiser

Avoid misleading closure return type note

Fixes #155670
&& let Some(fn_sig) = fcx.body_fn_sig()
&& fn_sig.output().is_ty_var()
&& fcx.ret_coercion.as_ref().is_some_and(|ret_coercion| {
fcx.resolve_vars_if_possible(ret_coercion.borrow().expected_ty()) == expected
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks Apr 27, 2026

Choose a reason for hiding this comment

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

I'm curious if this has fix this:

struct SmolStr;
const _: fn() -> SmolStr = || {
    match Some(()) {
        Some(()) => (),
        None => return SmolStr,
    };
    let _: String = {
        SmolStr
    };
    SmolStr
};

Or

struct SmolStr;
const _: fn() -> String = || {
    match Some(()) {
        Some(()) => (),
        None => return String::new(),
    };
    let _: String = {
        SmolStr
    };
    String::new()
};

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good catch, the first is handled well, but the second case will report an unexpected note, let me rethink it.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 27, 2026
…n-note-inner-block, r=wesleywiser

Avoid misleading closure return type note

A follow up fix for rust-lang#155670, fix a missed case rust-lang#155770 (comment)

r? @wesleywiser

cc @A4-Tacks
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 27, 2026
…n-note-inner-block, r=wesleywiser

Avoid misleading closure return type note

A follow up fix for rust-lang#155670, fix a missed case rust-lang#155770 (comment)

r? @wesleywiser

cc @A4-Tacks
rust-timer added a commit that referenced this pull request Apr 28, 2026
Rollup merge of #155874 - chenyukang:yukang-fix-155770-return-note-inner-block, r=wesleywiser

Avoid misleading closure return type note

A follow up fix for #155670, fix a missed case #155770 (comment)

r? @wesleywiser

cc @A4-Tacks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

Type mismatch helper not check is closure return block

4 participants