mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Auto merge of #116156 - oli-obk:opaque_place_unwrap, r=compiler-errors
Only prevent field projections into opaque types, not types containing opaque types fixes https://github.com/rust-lang/rust/issues/115778 I did not think that original condition through properly... I'll also need to check the similar check around the other `ProjectionKind::OpaqueCast` creation site (this one is in hir, the other one is in mir), but I'll do that change in another PR that doesn't go into a beta backport.
This commit is contained in:
commit
e1636a0939
@ -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 });
|
||||
|
27
tests/ui/impl-trait/opaque-cast-field-access-in-future.rs
Normal file
27
tests/ui/impl-trait/opaque-cast-field-access-in-future.rs
Normal file
@ -0,0 +1,27 @@
|
||||
// edition: 2021
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
async fn bop() {
|
||||
fold(run(), |mut foo| async move {
|
||||
&mut foo.bar;
|
||||
})
|
||||
}
|
||||
|
||||
fn fold<Fut, F, U>(_: Foo<U>, f: F)
|
||||
where
|
||||
F: FnMut(Foo<U>) -> Fut,
|
||||
{
|
||||
loop {}
|
||||
}
|
||||
|
||||
struct Foo<F> {
|
||||
bar: Vec<F>,
|
||||
}
|
||||
|
||||
fn run() -> Foo<impl Future<Output = ()>> {
|
||||
//~^ ERROR type annotations needed
|
||||
loop {}
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,9 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/opaque-cast-field-access-in-future.rs:22:17
|
||||
|
|
||||
LL | fn run() -> Foo<impl Future<Output = ()>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
Loading…
Reference in New Issue
Block a user