File tree Expand file tree Collapse file tree 3 files changed +85
-20
lines changed
compiler/rustc_typeck/src/check
src/test/ui/lint/must_not_suspend Expand file tree Collapse file tree 3 files changed +85
-20
lines changed Original file line number Diff line number Diff line change @@ -462,7 +462,6 @@ pub fn check_must_not_suspend_ty<'tcx>(
462462 descr_post : & str ,
463463 plural_len : usize ,
464464) -> bool {
465- debug ! ( "FOUND TYPE: {:?}" , ty) ;
466465 if ty. is_unit ( )
467466 // || fcx.tcx.is_ty_uninhabited_from(fcx.tcx.parent_module(hir_id).to_def_id(), ty, fcx.param_env)
468467 // FIXME: should this check is_ty_uninhabited_from
@@ -563,25 +562,20 @@ pub fn check_must_not_suspend_ty<'tcx>(
563562 }
564563 has_emitted
565564 }
566- ty:: Array ( ty, len) => match len. try_eval_usize ( fcx. tcx , fcx. param_env ) {
567- // If the array is empty we don't lint, to avoid false positives
568- Some ( 0 ) | None => false ,
569- // If the array is definitely non-empty, we can do `#[must_use]` checking.
570- Some ( n) => {
571- let descr_pre = & format ! ( "{}array{} of " , descr_pre, plural_suffix, ) ;
572- check_must_not_suspend_ty (
573- fcx,
574- ty,
575- hir_id,
576- expr,
577- source_span,
578- yield_span,
579- descr_pre,
580- descr_post,
581- n as usize + 1 ,
582- )
583- }
584- } ,
565+ ty:: Array ( ty, len) => {
566+ let descr_pre = & format ! ( "{}array{} of " , descr_pre, plural_suffix, ) ;
567+ check_must_not_suspend_ty (
568+ fcx,
569+ ty,
570+ hir_id,
571+ expr,
572+ source_span,
573+ yield_span,
574+ descr_pre,
575+ descr_post,
576+ len. try_eval_usize ( fcx. tcx , fcx. param_env ) . unwrap_or ( 0 ) as usize + 1 ,
577+ )
578+ }
585579 _ => false ,
586580 }
587581}
Original file line number Diff line number Diff line change 1+ // edition:2018
2+ #![ feature( must_not_suspend) ]
3+ #![ deny( must_not_suspend) ]
4+
5+ #[ must_not_suspend = "You gotta use Umm's, ya know?" ]
6+ struct Umm {
7+ i : i64
8+ }
9+
10+ struct Bar {
11+ u : Umm ,
12+ }
13+
14+ async fn other ( ) { }
15+
16+ impl Bar {
17+ async fn uhoh ( & mut self ) {
18+ let guard = & mut self . u ; //~ ERROR `Umm` held across
19+ //~^ ERROR `Umm` held across
20+
21+ other ( ) . await ;
22+
23+ * guard = Umm {
24+ i : 2
25+ }
26+ }
27+ }
28+
29+ fn main ( ) {
30+ }
Original file line number Diff line number Diff line change 1+ error: `Umm` held across a yield point, but should not be
2+ --> $DIR/ref.rs:18:26
3+ |
4+ LL | let guard = &mut self.u;
5+ | ^^^^^^
6+ ...
7+ LL | other().await;
8+ | ------------- The value is held across this yield point
9+ |
10+ note: the lint level is defined here
11+ --> $DIR/ref.rs:3:9
12+ |
13+ LL | #![deny(must_not_suspend)]
14+ | ^^^^^^^^^^^^^^^^
15+ = note: You gotta use Umm's, ya know?
16+ help: `drop` this value before the yield point, or use a block (`{ ... }`) "
17+ to shrink its scope
18+ --> $DIR/ref.rs:18:26
19+ |
20+ LL | let guard = &mut self.u;
21+ | ^^^^^^
22+
23+ error: `Umm` held across a yield point, but should not be
24+ --> $DIR/ref.rs:18:26
25+ |
26+ LL | let guard = &mut self.u;
27+ | ^^^^^^
28+ ...
29+ LL | other().await;
30+ | ------------- The value is held across this yield point
31+ |
32+ = note: You gotta use Umm's, ya know?
33+ help: `drop` this value before the yield point, or use a block (`{ ... }`) "
34+ to shrink its scope
35+ --> $DIR/ref.rs:18:26
36+ |
37+ LL | let guard = &mut self.u;
38+ | ^^^^^^
39+
40+ error: aborting due to 2 previous errors
41+
You can’t perform that action at this time.
0 commit comments