From 461a0f3da4acd6dfea31b9f12c1e14405b055438 Mon Sep 17 00:00:00 2001 From: Gus Wynn Date: Sat, 11 Sep 2021 12:24:40 -0700 Subject: [PATCH] array comment + test for references --- .../src/check/generator_interior.rs | 34 +++++++-------- src/test/ui/lint/must_not_suspend/ref.rs | 30 ++++++++++++++ src/test/ui/lint/must_not_suspend/ref.stderr | 41 +++++++++++++++++++ 3 files changed, 85 insertions(+), 20 deletions(-) create mode 100644 src/test/ui/lint/must_not_suspend/ref.rs create mode 100644 src/test/ui/lint/must_not_suspend/ref.stderr diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs index c4c09a55a6e..1b63d6d9741 100644 --- a/compiler/rustc_typeck/src/check/generator_interior.rs +++ b/compiler/rustc_typeck/src/check/generator_interior.rs @@ -462,7 +462,6 @@ pub fn check_must_not_suspend_ty<'tcx>( descr_post: &str, plural_len: usize, ) -> bool { - debug!("FOUND TYPE: {:?}", ty); if ty.is_unit() // || fcx.tcx.is_ty_uninhabited_from(fcx.tcx.parent_module(hir_id).to_def_id(), ty, fcx.param_env) // FIXME: should this check is_ty_uninhabited_from @@ -563,25 +562,20 @@ pub fn check_must_not_suspend_ty<'tcx>( } has_emitted } - ty::Array(ty, len) => match len.try_eval_usize(fcx.tcx, fcx.param_env) { - // If the array is empty we don't lint, to avoid false positives - Some(0) | None => false, - // If the array is definitely non-empty, we can do `#[must_use]` checking. - Some(n) => { - let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,); - check_must_not_suspend_ty( - fcx, - ty, - hir_id, - expr, - source_span, - yield_span, - descr_pre, - descr_post, - n as usize + 1, - ) - } - }, + ty::Array(ty, len) => { + let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,); + check_must_not_suspend_ty( + fcx, + ty, + hir_id, + expr, + source_span, + yield_span, + descr_pre, + descr_post, + len.try_eval_usize(fcx.tcx, fcx.param_env).unwrap_or(0) as usize + 1, + ) + } _ => false, } } diff --git a/src/test/ui/lint/must_not_suspend/ref.rs b/src/test/ui/lint/must_not_suspend/ref.rs new file mode 100644 index 00000000000..89fd73c187e --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/ref.rs @@ -0,0 +1,30 @@ +// edition:2018 +#![feature(must_not_suspend)] +#![deny(must_not_suspend)] + +#[must_not_suspend = "You gotta use Umm's, ya know?"] +struct Umm { + i: i64 +} + +struct Bar { + u: Umm, +} + +async fn other() {} + +impl Bar { + async fn uhoh(&mut self) { + let guard = &mut self.u; //~ ERROR `Umm` held across + //~^ ERROR `Umm` held across + + other().await; + + *guard = Umm { + i: 2 + } + } +} + +fn main() { +} diff --git a/src/test/ui/lint/must_not_suspend/ref.stderr b/src/test/ui/lint/must_not_suspend/ref.stderr new file mode 100644 index 00000000000..91c91a4b545 --- /dev/null +++ b/src/test/ui/lint/must_not_suspend/ref.stderr @@ -0,0 +1,41 @@ +error: `Umm` held across a yield point, but should not be + --> $DIR/ref.rs:18:26 + | +LL | let guard = &mut self.u; + | ^^^^^^ +... +LL | other().await; + | ------------- The value is held across this yield point + | +note: the lint level is defined here + --> $DIR/ref.rs:3:9 + | +LL | #![deny(must_not_suspend)] + | ^^^^^^^^^^^^^^^^ + = note: You gotta use Umm's, ya know? +help: `drop` this value before the yield point, or use a block (`{ ... }`) " + to shrink its scope + --> $DIR/ref.rs:18:26 + | +LL | let guard = &mut self.u; + | ^^^^^^ + +error: `Umm` held across a yield point, but should not be + --> $DIR/ref.rs:18:26 + | +LL | let guard = &mut self.u; + | ^^^^^^ +... +LL | other().await; + | ------------- The value is held across this yield point + | + = note: You gotta use Umm's, ya know? +help: `drop` this value before the yield point, or use a block (`{ ... }`) " + to shrink its scope + --> $DIR/ref.rs:18:26 + | +LL | let guard = &mut self.u; + | ^^^^^^ + +error: aborting due to 2 previous errors +