Skip to content

Improve type mismatch annotation for lets with block-wrapped initializers - #161730

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-127048-local-type-mismatch-attribution
Aug 28, 2026
Merged

Improve type mismatch annotation for lets with block-wrapped initializers#161730
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-127048-local-type-mismatch-attribution

Conversation

@chenyukang

@chenyukang chenyukang commented Aug 25, 2026

Copy link
Copy Markdown
Member

Fixes #127048

@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 Aug 25, 2026
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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 75 candidates
  • Random selection from 16 candidates

@folkertdev folkertdev 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.

Comment thread compiler/rustc_hir_typeck/src/demand.rs Outdated
parent => Some(parent),
},
) else {
return;

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.

why is this early return correct? Maybe add a comment?

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.

i think it's better to change it to expect here, an expression must have a non-block ancestor.

Comment thread compiler/rustc_hir_typeck/src/demand.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/demand.rs Outdated
match (self.tcx.parent_hir_node(expr.hir_id), error) {
// Skip nested block find the correct parent node to point at
let mut current_hir_id = expr.hir_id;
let Some(parent) = self.tcx.hir_parent_iter(expr.hir_id).find_map(

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.

I played around with a labeled block here instead but it's not obviously better.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 26, 2026
@chenyukang
chenyukang force-pushed the yukang-fix-127048-local-type-mismatch-attribution branch 2 times, most recently from ca30e20 to a83939a Compare August 26, 2026 15:25
@folkertdev

Copy link
Copy Markdown
Contributor

CI got stuck somehow. Maybe just rebase on current main and try again?

@chenyukang
chenyukang force-pushed the yukang-fix-127048-local-type-mismatch-attribution branch from a83939a to ef175bb Compare August 27, 2026 00:46
@rustbot

rustbot commented Aug 27, 2026

Copy link
Copy Markdown
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.

@folkertdev

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ef175bb has been approved by folkertdev

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 27, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
rust-bors Bot pushed a commit that referenced this pull request Aug 27, 2026
Rollup of 7 pull requests

Successful merges:

 - #150075 (Implement clamp_to)
 - #157145 (Codegen Overloaded LLVM intrinsics based on their name)
 - #161866 (delegation: add tests fixating behavior of delegating to default trait implementations)
 - #161456 (reduce perf impact of scalar size checks)
 - #161730 (Improve type mismatch annotation for lets with block-wrapped initializers)
 - #161828 (Never type after-stabilization cleanup)
 - #161860 (atomicptr.rs test: remove unused import)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 27, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
Rollup of 14 pull requests

Successful merges:

 - #150075 (Implement clamp_to)
 - #159103 (fix(reborrow): recursive implementation)
 - #160848 (std: avoid aliasing violations when wrapping opaque C types)
 - #161421 (Include startup crt objects on WASI for more outputs)
 - #161805 (Prefer ambiguous candidates when deduplicating traits in scope, so `ambiguous_glob_imported_traits` doesn't depend on import order)
 - #161862 (Put data segment in specified section with link_section on wasm)
 - #161866 (delegation: add tests fixating behavior of delegating to default trait implementations)
 - #161456 (reduce perf impact of scalar size checks)
 - #161666 (Print vendor instructions in `x vendor`)
 - #161730 (Improve type mismatch annotation for lets with block-wrapped initializers)
 - #161828 (Never type after-stabilization cleanup)
 - #161860 (atomicptr.rs test: remove unused import)
 - #161870 (bind to [::1] instead of 127.0.0.1 in documentation examples for v6 UDP methods)
 - #161876 (rustdoc: Correctly handle when a macro generates multiple items in `--generate-macro-expansion`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Aug 28, 2026
…-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes rust-lang#127048
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #158609 (Update sccache to 0.16.0)
 - #150075 (Implement clamp_to)
 - #159103 (fix(reborrow): recursive implementation)
 - #160562 (add target feature ABI checks for SPARC)
 - #160848 (std: avoid aliasing violations when wrapping opaque C types)
 - #161421 (Include startup crt objects on WASI for more outputs)
 - #161805 (Prefer ambiguous candidates when deduplicating traits in scope, so `ambiguous_glob_imported_traits` doesn't depend on import order)
 - #161862 (Put data segment in specified section with link_section on wasm)
 - #161866 (delegation: add tests fixating behavior of delegating to default trait implementations)
 - #161456 (reduce perf impact of scalar size checks)
 - #161528 (Add regression test to ensure optimal compilation)
 - #161666 (Print vendor instructions in `x vendor`)
 - #161730 (Improve type mismatch annotation for lets with block-wrapped initializers)
 - #161828 (Never type after-stabilization cleanup)
 - #161859 (Do not optimize MIR for comptime ConstFns)
 - #161860 (atomicptr.rs test: remove unused import)
 - #161870 (bind to [::1] instead of 127.0.0.1 in documentation examples for v6 UDP methods)
 - #161876 (rustdoc: Correctly handle when a macro generates multiple items in `--generate-macro-expansion`)
 - #161889 (Add link to ownership section in ptr::read docs)
 - #161890 (rustdoc: some clarifying comments)
 - #161891 (Mark `extern_item_impls` feature as incomplete)

Failed merges:

 - #161702 (Use `drop_guard` in some places in {core,alloc,std})
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
…uwer

Rollup of 21 pull requests

Successful merges:

 - #150075 (Implement clamp_to)
 - #159103 (fix(reborrow): recursive implementation)
 - #160562 (add target feature ABI checks for SPARC)
 - #160848 (std: avoid aliasing violations when wrapping opaque C types)
 - #161421 (Include startup crt objects on WASI for more outputs)
 - #161805 (Prefer ambiguous candidates when deduplicating traits in scope, so `ambiguous_glob_imported_traits` doesn't depend on import order)
 - #161862 (Put data segment in specified section with link_section on wasm)
 - #161866 (delegation: add tests fixating behavior of delegating to default trait implementations)
 - #157218 (Track items behind `cfg_select` in the same way we do for `cfg`)
 - #161456 (reduce perf impact of scalar size checks)
 - #161528 (Add regression test to ensure optimal compilation)
 - #161666 (Print vendor instructions in `x vendor`)
 - #161730 (Improve type mismatch annotation for lets with block-wrapped initializers)
 - #161828 (Never type after-stabilization cleanup)
 - #161859 (Do not optimize MIR for comptime ConstFns)
 - #161860 (atomicptr.rs test: remove unused import)
 - #161870 (bind to [::1] instead of 127.0.0.1 in documentation examples for v6 UDP methods)
 - #161876 (rustdoc: Correctly handle when a macro generates multiple items in `--generate-macro-expansion`)
 - #161889 (Add link to ownership section in ptr::read docs)
 - #161890 (rustdoc: some clarifying comments)
 - #161891 (Mark `extern_item_impls` feature as incomplete)

Failed merges:

 - #161702 (Use `drop_guard` in some places in {core,alloc,std})
@rust-bors
rust-bors Bot merged commit 8d6bd02 into rust-lang:main Aug 28, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Aug 28, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 28, 2026
Rollup merge of #161730 - chenyukang:yukang-fix-127048-local-type-mismatch-attribution, r=folkertdev

Improve type mismatch annotation for lets with block-wrapped initializers

Fixes #127048
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 is incorrectly attributed in certain closures / async blocks

3 participants