diff options
| author | Michael Goulet <michael@errs.io> | 2025-05-28 12:17:18 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-05-28 12:17:18 +0000 |
| commit | 3a736e2726dcd4cb534eaf64b25196fa45a26a03 (patch) | |
| tree | 10510a91f582d06840e9f4ec7de027b9e3dccab2 | |
| parent | 0fc6f1672bdde8163164f10e46d2d9ffcaeb2161 (diff) | |
| download | rust-3a736e2726dcd4cb534eaf64b25196fa45a26a03.tar.gz rust-3a736e2726dcd4cb534eaf64b25196fa45a26a03.zip | |
Handle e2021 precise capturing of unsafe binder
| -rw-r--r-- | compiler/rustc_middle/src/ty/closure.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/builder/expr/as_place.rs | 4 | ||||
| -rw-r--r-- | tests/ui/unsafe-binders/cat-projection.rs | 3 |
3 files changed, 9 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index ff9096695d4..df67bb505a6 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -117,6 +117,10 @@ impl<'tcx> CapturedPlace<'tcx> { } }, + HirProjectionKind::UnwrapUnsafeBinder => { + write!(&mut symbol, "__unwrap").unwrap(); + } + // Ignore derefs for now, as they are likely caused by // autoderefs that don't appear in the original code. HirProjectionKind::Deref => {} diff --git a/compiler/rustc_mir_build/src/builder/expr/as_place.rs b/compiler/rustc_mir_build/src/builder/expr/as_place.rs index 830a129c585..f8c64d7d13e 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_place.rs @@ -101,12 +101,12 @@ fn convert_to_hir_projections_and_truncate_for_capture( variant = Some(*idx); continue; } + ProjectionElem::UnwrapUnsafeBinder(_) => HirProjectionKind::UnwrapUnsafeBinder, // These do not affect anything, they just make sure we know the right type. ProjectionElem::OpaqueCast(_) | ProjectionElem::Subtype(..) => continue, ProjectionElem::Index(..) | ProjectionElem::ConstantIndex { .. } - | ProjectionElem::Subslice { .. } - | ProjectionElem::UnwrapUnsafeBinder(_) => { + | ProjectionElem::Subslice { .. } => { // We don't capture array-access projections. // We can stop here as arrays are captured completely. break; diff --git a/tests/ui/unsafe-binders/cat-projection.rs b/tests/ui/unsafe-binders/cat-projection.rs index dd7a78d59b3..0ce8579a688 100644 --- a/tests/ui/unsafe-binders/cat-projection.rs +++ b/tests/ui/unsafe-binders/cat-projection.rs @@ -1,3 +1,6 @@ +//@ revisions: e2015 e2021 +//@[e2015] edition: 2015 +//@[e2021] edition: 2021 //@ check-pass #![feature(unsafe_binders)] |
