From 4620e74fbb00ed8f74e33d8c047379bdbc4ae4a6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 25 Sep 2023 17:40:37 +0000 Subject: [PATCH 1/2] Only prevent field projections into opaque types, not types containing opaque types (cherry picked from commit 17b313fb5734df8186071d4e30e46673098bb6a9) --- .../src/mem_categorization.rs | 2 +- .../opaque-cast-field-access-in-future.rs | 27 +++++++++++++++++++ .../opaque-cast-field-access-in-future.stderr | 9 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/ui/impl-trait/opaque-cast-field-access-in-future.rs create mode 100644 tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index 7fb1dc2347e05..9574da0212f58 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -464,7 +464,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { // Opaque types can't have field projections, but we can instead convert // the current place in-place (heh) to the hidden type, and then apply all // follow up projections on that. - if node_ty != place_ty && place_ty.has_opaque_types() { + if node_ty != place_ty && matches!(place_ty.kind(), ty::Alias(ty::Opaque, ..)) { projections.push(Projection { kind: ProjectionKind::OpaqueCast, ty: node_ty }); } projections.push(Projection { kind, ty }); diff --git a/tests/ui/impl-trait/opaque-cast-field-access-in-future.rs b/tests/ui/impl-trait/opaque-cast-field-access-in-future.rs new file mode 100644 index 0000000000000..3e3bc09a62aa8 --- /dev/null +++ b/tests/ui/impl-trait/opaque-cast-field-access-in-future.rs @@ -0,0 +1,27 @@ +// edition: 2021 + +use std::future::Future; + +async fn bop() { + fold(run(), |mut foo| async move { + &mut foo.bar; + }) +} + +fn fold(_: Foo, f: F) +where + F: FnMut(Foo) -> Fut, +{ + loop {} +} + +struct Foo { + bar: Vec, +} + +fn run() -> Foo> { + //~^ ERROR type annotations needed + loop {} +} + +fn main() {} diff --git a/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr b/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr new file mode 100644 index 0000000000000..ee4343b110f26 --- /dev/null +++ b/tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr @@ -0,0 +1,9 @@ +error[E0282]: type annotations needed + --> $DIR/opaque-cast-field-access-in-future.rs:22:17 + | +LL | fn run() -> Foo> { + | ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0282`. From a544df15297afc959a384a923f9581d0c53ac5a4 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 28 Sep 2023 13:41:02 +0200 Subject: [PATCH 2/2] Update LLVM submodule (cherry picked from commit b325e9c60df758f1f1538c93e44b120a8fbf6d63) --- src/llvm-project | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-project b/src/llvm-project index 42263494d29fe..d404cba4e39df 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit 42263494d29febc26d3c1ebdaa7b63677573ec47 +Subproject commit d404cba4e39df595710869988ded7cbe1104b52f