Skip to content

Commit c42c77b

Browse files
committed
Update to still be correct without drop tracking
1 parent 89d3506 commit c42c77b

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
457457
}
458458

459459
#[derive(Default)]
460-
pub struct SuspendCheckData<'a, 'tcx> {
460+
struct SuspendCheckData<'a, 'tcx> {
461461
expr: Option<&'tcx Expr<'tcx>>,
462462
source_span: Span,
463463
yield_span: Span,
@@ -472,7 +472,7 @@ pub struct SuspendCheckData<'a, 'tcx> {
472472
//
473473
// Note that this technique was chosen over things like a `Suspend` marker trait
474474
// as it is simpler and has precedent in the compiler
475-
pub fn check_must_not_suspend_ty<'tcx>(
475+
fn check_must_not_suspend_ty<'tcx>(
476476
fcx: &FnCtxt<'_, 'tcx>,
477477
ty: Ty<'tcx>,
478478
hir_id: HirId,
@@ -582,7 +582,9 @@ pub fn check_must_not_suspend_ty<'tcx>(
582582
},
583583
)
584584
}
585-
ty::Ref(_region, ty, _mutability) => {
585+
// If drop tracking is enabled, we want to look through references, since the referrent
586+
// may not be considered live across the await point.
587+
ty::Ref(_region, ty, _mutability) if fcx.sess().opts.debugging_opts.drop_tracking => {
586588
let descr_pre = &format!("{}reference{} to ", data.descr_pre, plural_suffix);
587589
check_must_not_suspend_ty(fcx, ty, hir_id, SuspendCheckData { descr_pre, ..data })
588590
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: reference to `Umm` held across a suspend point, but should not be
2+
--> $DIR/ref-drop-tracking.rs:19:13
3+
|
4+
LL | let guard = &mut self.u;
5+
| ^^^^^
6+
LL |
7+
LL | other().await;
8+
| ------ the value is held across this suspend point
9+
|
10+
note: the lint level is defined here
11+
--> $DIR/ref-drop-tracking.rs:4:9
12+
|
13+
LL | #![deny(must_not_suspend)]
14+
| ^^^^^^^^^^^^^^^^
15+
note: You gotta use Umm's, ya know?
16+
--> $DIR/ref-drop-tracking.rs:19:13
17+
|
18+
LL | let guard = &mut self.u;
19+
| ^^^^^
20+
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
21+
--> $DIR/ref-drop-tracking.rs:19:13
22+
|
23+
LL | let guard = &mut self.u;
24+
| ^^^^^
25+
26+
error: aborting due to previous error
27+
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error: reference to `Umm` held across a suspend point, but should not be
2-
--> $DIR/ref.rs:18:13
1+
error: `Umm` held across a suspend point, but should not be
2+
--> $DIR/ref.rs:18:26
33
|
44
LL | let guard = &mut self.u;
55
| ^^^^^^
@@ -13,15 +13,15 @@ note: the lint level is defined here
1313
LL | #![deny(must_not_suspend)]
1414
| ^^^^^^^^^^^^^^^^
1515
note: You gotta use Umm's, ya know?
16-
--> $DIR/ref.rs:18:13
16+
--> $DIR/ref.rs:18:26
1717
|
1818
LL | let guard = &mut self.u;
19-
| ^^^^^
19+
| ^^^^^^
2020
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
21-
--> $DIR/ref.rs:18:13
21+
--> $DIR/ref.rs:18:26
2222
|
2323
LL | let guard = &mut self.u;
24-
| ^^^^^
24+
| ^^^^^^
2525

2626
error: aborting due to previous error
2727

0 commit comments

Comments
 (0)