From 15fd168ee0fe9b4ed24aaaa44cacaa264be4c60b Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 14 Apr 2026 21:06:52 +1000 Subject: [PATCH] Tests for precise-capture through RPIT and TAIT --- .../precise-capture-155151.current.stderr | 12 ++++++++++ .../impl-trait/rpit/precise-capture-155151.rs | 24 +++++++++++++++++++ .../precise-capture-155151.current.stderr | 12 ++++++++++ .../precise-capture-155151.rs | 22 +++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 tests/ui/impl-trait/rpit/precise-capture-155151.current.stderr create mode 100644 tests/ui/impl-trait/rpit/precise-capture-155151.rs create mode 100644 tests/ui/type-alias-impl-trait/precise-capture-155151.current.stderr create mode 100644 tests/ui/type-alias-impl-trait/precise-capture-155151.rs diff --git a/tests/ui/impl-trait/rpit/precise-capture-155151.current.stderr b/tests/ui/impl-trait/rpit/precise-capture-155151.current.stderr new file mode 100644 index 000000000000..39efb77067e7 --- /dev/null +++ b/tests/ui/impl-trait/rpit/precise-capture-155151.current.stderr @@ -0,0 +1,12 @@ +error[E0381]: used binding `x` isn't initialized + --> $DIR/precise-capture-155151.rs:19:22 + | +LL | let Foo { x } = foo; + | - binding declared here but left uninitialized +... +LL | let _y = x; + | ^ `x` used here but it isn't initialized + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0381`. diff --git a/tests/ui/impl-trait/rpit/precise-capture-155151.rs b/tests/ui/impl-trait/rpit/precise-capture-155151.rs new file mode 100644 index 000000000000..b01f1098c6c2 --- /dev/null +++ b/tests/ui/impl-trait/rpit/precise-capture-155151.rs @@ -0,0 +1,24 @@ +#![crate_type = "rlib"] +//@ revisions: current next +//@ edition: 2021 +//@[current] known-bug: #155151 +//@[current] check-fail +//@[next] compile-flags: -Znext-solver +//@[next] check-pass + +pub fn wut() -> impl Sized { + struct Foo { x: u32 } + + if false { + // `foo` has an opaque type, but this function knows that it's `Foo`. + let foo = wut(); + let _closure = move || { + let Foo { x } = foo; + // `x` should have been captured, but under old-solver the compiler + // thinks it's uninitialized here. + let _y = x; + }; + } + + Foo { x: 7 } +} diff --git a/tests/ui/type-alias-impl-trait/precise-capture-155151.current.stderr b/tests/ui/type-alias-impl-trait/precise-capture-155151.current.stderr new file mode 100644 index 000000000000..972bf142db67 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/precise-capture-155151.current.stderr @@ -0,0 +1,12 @@ +error[E0381]: used binding `x` isn't initialized + --> $DIR/precise-capture-155151.rs:20:18 + | +LL | let Foo { x } = foo; + | - binding declared here but left uninitialized +... +LL | let _y = x; + | ^ `x` used here but it isn't initialized + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0381`. diff --git a/tests/ui/type-alias-impl-trait/precise-capture-155151.rs b/tests/ui/type-alias-impl-trait/precise-capture-155151.rs new file mode 100644 index 000000000000..b470c9373e93 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/precise-capture-155151.rs @@ -0,0 +1,22 @@ +#![feature(type_alias_impl_trait)] +//@ revisions: current next +//@ edition: 2021 +//@[current] known-bug: #155151 +//@[current] check-fail +//@[next] compile-flags: -Znext-solver +//@[next] check-pass + +fn main() { + struct Foo { x: u32 } + + type T = impl Sized; + // `foo` has an opaque type, but this function knows that it's `Foo`. + let foo: T = Foo { x: 7 }; + + let _closure = move || { + let Foo { x } = foo; + // `x` should have been captured, but under old-solver the compiler + // thinks it's uninitialized here. + let _y = x; + }; +}