Skip to content

Commit 74ea163

Browse files
committed
skip the uninhabitated check and comments
1 parent 67ee91e commit 74ea163

File tree

12 files changed

+59
-26
lines changed

12 files changed

+59
-26
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,28 @@ declare_lint! {
315315
}
316316

317317
declare_lint! {
318-
/// [the reference]: https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute
318+
/// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
319+
/// attribute being held across yield points. A "yield" point is usually a `.await` in an async
320+
/// function.
321+
///
322+
/// This attribute can be used to mark values that are semantically incorrect across yields
323+
/// (like certain types of timers), values that have async alternatives, and values that
324+
/// regularly cause problems with the `Send`-ness of async fn's returned futures (like
325+
/// `MutexGuard`'s)
326+
///
327+
/// ### Example
328+
///
329+
/// ```rust
330+
/// #[must_not_suspend]
331+
/// struct SyncThing {}
332+
///
333+
/// async fn yield() {}
334+
///
335+
/// pub async fn uhoh() {
336+
/// let guard = SyncThing {};
337+
/// yield().await;
338+
/// }
339+
/// ```
319340
pub MUST_NOT_SUSPEND,
320341
Warn,
321342
"Use of a `#[must_not_suspend]` value across a yield point",

compiler/rustc_passes/src/check_attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1018,15 +1018,15 @@ impl CheckAttrVisitor<'tcx> {
10181018
/// Checks if `#[must_not_suspend]` is applied to a function. Returns `true` if valid.
10191019
fn check_must_not_suspend(&self, attr: &Attribute, span: &Span, target: Target) -> bool {
10201020
match target {
1021-
Target::Fn | Target::Method(..) | Target::ForeignFn | Target::Closure => {
1021+
Target::Struct | Target::Enum | Target::Union | Target::Trait => true,
1022+
_ => {
10221023
self.tcx
10231024
.sess
1024-
.struct_span_err(attr.span, "`must_not_suspend` attribute should be applied to a struct, enum, `impl Trait`, or `dyn Trait`")
1025-
.span_label(*span, "is a function")
1025+
.struct_span_err(attr.span, "`must_not_suspend` attribute should be applied to a struct, enum, or trait")
1026+
.span_label(*span, "is not a struct, enum, or trait")
10261027
.emit();
10271028
false
10281029
}
1029-
_ => true,
10301030
}
10311031
}
10321032

compiler/rustc_typeck/src/check/generator_interior.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
124124

125125
check_must_not_suspend_ty(
126126
self.fcx,
127-
ty::ParamEnv::empty(),
128127
ty,
129128
hir_id,
130129
expr,
@@ -454,7 +453,6 @@ impl<'a, 'tcx> Visitor<'tcx> for ArmPatCollector<'a> {
454453
// for creating must_use diagnostics
455454
pub fn check_must_not_suspend_ty<'tcx>(
456455
fcx: &FnCtxt<'_, 'tcx>,
457-
param_env: ty::ParamEnv<'tcx>,
458456
ty: Ty<'tcx>,
459457
hir_id: HirId,
460458
expr: Option<&'tcx Expr<'tcx>>,
@@ -464,8 +462,10 @@ pub fn check_must_not_suspend_ty<'tcx>(
464462
descr_post: &str,
465463
plural_len: usize,
466464
) -> bool {
465+
debug!("FOUND TYPE: {:?}", ty);
467466
if ty.is_unit()
468-
|| fcx.tcx.is_ty_uninhabited_from(fcx.tcx.parent_module(hir_id).to_def_id(), ty, param_env)
467+
// || fcx.tcx.is_ty_uninhabited_from(fcx.tcx.parent_module(hir_id).to_def_id(), ty, fcx.param_env)
468+
// FIXME: should this check is_ty_uninhabited_from
469469
{
470470
return true;
471471
}
@@ -478,7 +478,6 @@ pub fn check_must_not_suspend_ty<'tcx>(
478478
let descr_pre = &format!("{}boxed ", descr_pre);
479479
check_must_not_suspend_ty(
480480
fcx,
481-
param_env,
482481
boxed_ty,
483482
hir_id,
484483
expr,
@@ -547,36 +546,31 @@ pub fn check_must_not_suspend_ty<'tcx>(
547546
}
548547
ty::Tuple(ref tys) => {
549548
let mut has_emitted = false;
550-
/*
551-
let spans = if let hir::ExprKind::Tup(comps) = &expr.kind {
549+
let spans = if let Some(hir::ExprKind::Tup(comps)) = expr.map(|e| &e.kind) {
552550
debug_assert_eq!(comps.len(), tys.len());
553551
comps.iter().map(|e| e.span).collect()
554552
} else {
555553
vec![]
556554
};
557-
*/
558-
let spans = vec![];
559555
for (i, ty) in tys.iter().map(|k| k.expect_ty()).enumerate() {
560556
let descr_post = &format!(" in tuple element {}", i);
561557
let span = *spans.get(i).unwrap_or(&source_span);
562558
if check_must_not_suspend_ty(
563-
fcx, param_env, ty, hir_id, expr, span, yield_span, descr_pre, descr_post,
564-
plural_len,
559+
fcx, ty, hir_id, expr, span, yield_span, descr_pre, descr_post, plural_len,
565560
) {
566561
has_emitted = true;
567562
}
568563
}
569564
has_emitted
570565
}
571-
ty::Array(ty, len) => match len.try_eval_usize(fcx.tcx, param_env) {
566+
ty::Array(ty, len) => match len.try_eval_usize(fcx.tcx, fcx.param_env) {
572567
// If the array is empty we don't lint, to avoid false positives
573568
Some(0) | None => false,
574569
// If the array is definitely non-empty, we can do `#[must_use]` checking.
575570
Some(n) => {
576571
let descr_pre = &format!("{}array{} of ", descr_pre, plural_suffix,);
577572
check_must_not_suspend_ty(
578573
fcx,
579-
param_env,
580574
ty,
581575
hir_id,
582576
expr,

src/test/ui/lint/must_not_suspend/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn bar() -> Box<Umm> {
1717
async fn other() {}
1818

1919
pub async fn uhoh() {
20-
let _guard = bar(); //~ boxed `Umm` held across
20+
let _guard = bar(); //~ ERROR boxed `Umm` held across
2121
other().await;
2222
}
2323

src/test/ui/lint/must_not_suspend/feature-gate-must_not_suspend.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// edition:2018
22

3-
#[must_not_suspend = "You gotta use Umm's, ya know?"] //~ the `#[must_not_suspend]`
3+
#[must_not_suspend = "You gotta use Umm's, ya know?"] //~ ERROR the `#[must_not_suspend]`
44
struct Umm {
55
_i: i64
66
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// edition:2018
2+
#![feature(must_not_suspend)]
3+
#![deny(must_not_suspend)]
4+
5+
#[must_not_suspend] //~ ERROR attribute should be
6+
mod inner {}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `must_not_suspend` attribute should be applied to a struct, enum, or trait
2+
--> $DIR/other_items.rs:5:1
3+
|
4+
LL | #[must_not_suspend]
5+
| ^^^^^^^^^^^^^^^^^^^
6+
LL | mod inner {}
7+
| ------------ is not a struct, enum, or trait
8+
9+
error: aborting due to previous error
10+

src/test/ui/lint/must_not_suspend/return.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![feature(must_not_suspend)]
33
#![deny(must_not_suspend)]
44

5-
#[must_not_suspend] //~ attribute should be
5+
#[must_not_suspend] //~ ERROR attribute should be
66
fn foo() -> i32 {
77
0
88
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: `must_not_suspend` attribute should be applied to a struct, enum, `impl Trait`, or `dyn Trait`
1+
error: `must_not_suspend` attribute should be applied to a struct, enum, or trait
22
--> $DIR/return.rs:5:1
33
|
44
LL | #[must_not_suspend]
55
| ^^^^^^^^^^^^^^^^^^^
66
LL | / fn foo() -> i32 {
77
LL | | 0
88
LL | | }
9-
| |_- is a function
9+
| |_- is not a struct, enum, or trait
1010

1111
error: aborting due to previous error
1212

src/test/ui/lint/must_not_suspend/trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ fn r#dyn() -> Box<dyn Wow> {
1818
async fn other() {}
1919

2020
pub async fn uhoh() {
21-
let _guard1 = r#impl(); //~ implementer of `Wow` held across
22-
let _guard2 = r#dyn(); //~ boxed `Wow` trait object held across
21+
let _guard1 = r#impl(); //~ ERROR implementer of `Wow` held across
22+
let _guard2 = r#dyn(); //~ ERROR boxed `Wow` trait object held across
2323

2424
other().await;
2525
}

src/test/ui/lint/must_not_suspend/unit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn bar() -> Umm {
1717
async fn other() {}
1818

1919
pub async fn uhoh() {
20-
let _guard = bar(); //~ `Umm` held across
20+
let _guard = bar(); //~ ERROR `Umm` held across
2121
other().await;
2222
}
2323

src/test/ui/lint/must_not_suspend/warn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn bar() -> Umm {
1717
async fn other() {}
1818

1919
pub async fn uhoh() {
20-
let _guard = bar(); //~ `Umm` held across
20+
let _guard = bar(); //~ WARNING `Umm` held across
2121
other().await;
2222
}
2323

0 commit comments

Comments
 (0)