You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Field within opaque type is not captured by closure under old solver #155151
pubfnwut() -> implSized{structFoo{x:u32}iffalse{let foo = wut();let _closure = move || {// let foo = foo; // Works if this is uncommentedletFoo{ x } = foo;let _y = x;};}Foo{x:7}}
(Thanks to @theemathas for a minimization not requiring TAIT.)
I expected to see this happen: Compiles successfully.
Instead, this happened:
Compiling playground v0.0.1 (/playground)
error[E0381]: used binding `x` isn't initialized
--> src/lib.rs:9:22
|
8 | let Foo { x } = foo;
| - binding declared here but left uninitialized
9 | let _y = x;
| ^ `x` used here but it isn't initialized
warning: value captured by `foo.x` is never read
--> src/lib.rs:8:29
|
8 | let Foo { x } = foo;
| ^^^
|
= help: did you mean to capture by reference instead?
= note: `#[warn(unused_assignments)]` (part of `#[warn(unused)]`) on by default
For more information about this error, try `rustc --explain E0381`.
warning: `playground` (lib) generated 1 warning
error: could not compile `playground` (lib) due to 1 previous error; 1 warning emitted
Meta
(Tested on playground with stable 1.94.1 and nightly 1.96.)
For additional background, I noticed the issue while looking into situations where this code fails to create a binding for a PatKind::Binding node, because place is None:
Activity
Zalathar commentedon Apr 11, 2026
The failure only occurs under edition 2021 or later (since it requires precise-capture), and does not occur under
-Znext-solver.Zalathar commentedon Apr 11, 2026
Triggering this issue without TAIT requires some pretty contrived code, but with TAIT it's a lot more plausible:
rust/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs
Lines 15 to 24 in c29effd
This existing test currently doesn't trigger the bug, but actually using
aorbin the closure would produce a similar error.theemathas commentedon Apr 11, 2026
Possibly related to #119786. cc @meithecatte
Zalathar commentedon Apr 12, 2026
For additional background, I noticed the issue while looking into situations where this code fails to create a binding for a
PatKind::Bindingnode, becauseplaceis None:rust/compiler/rustc_mir_build/src/builder/matches/match_pair.rs
Lines 218 to 227 in bf4fbfb
Rollup merge of rust-lang#155280 - Zalathar:opaque-capture-bug, r=Jon…
Rollup merge of rust-lang#155280 - Zalathar:opaque-capture-bug, r=Jon…
Unrolled build for #155280
Rollup merge of rust-lang#162145 - Randl:test-fixed-issues-2, r=jackh726