array comment + test for references

This commit is contained in:
Gus Wynn 2021-09-11 12:24:40 -07:00
parent 74ea16301e
commit 461a0f3da4
3 changed files with 85 additions and 20 deletions

View File

@ -462,7 +462,6 @@ pub fn check_must_not_suspend_ty<'tcx>(
descr_post: &str, descr_post: &str,
plural_len: usize, plural_len: usize,
) -> bool { ) -> bool {
debug!("FOUND TYPE: {:?}", ty);
if ty.is_unit() if ty.is_unit()
// || fcx.tcx.is_ty_uninhabited_from(fcx.tcx.parent_module(hir_id).to_def_id(), ty, fcx.param_env) // || 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 // FIXME: should this check is_ty_uninhabited_from
@ -563,25 +562,20 @@ pub fn check_must_not_suspend_ty<'tcx>(
} }
has_emitted has_emitted
} }
ty::Array(ty, len) => match len.try_eval_usize(fcx.tcx, fcx.param_env) { ty::Array(ty, len) => {
// If the array is empty we don't lint, to avoid false positives let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,);
Some(0) | None => false, check_must_not_suspend_ty(
// If the array is definitely non-empty, we can do `#[must_use]` checking. fcx,
Some(n) => { ty,
let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,); hir_id,
check_must_not_suspend_ty( expr,
fcx, source_span,
ty, yield_span,
hir_id, descr_pre,
expr, descr_post,
source_span, len.try_eval_usize(fcx.tcx, fcx.param_env).unwrap_or(0) as usize + 1,
yield_span, )
descr_pre, }
descr_post,
n as usize + 1,
)
}
},
_ => false, _ => false,
} }
} }

View File

@ -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() {
}

View File

@ -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