Skip to content

Commit 2af1ebf

Browse files
committed
error formatting and fix build
1 parent ee1d2ea commit 2af1ebf

File tree

8 files changed

+67
-43
lines changed

8 files changed

+67
-43
lines changed

compiler/rustc_feature/src/active.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ declare_features! (
679679
/// Allows `let...else` statements.
680680
(active, let_else, "1.56.0", Some(87335), None),
681681

682-
/// Allows `#[must_not_suspend]`.
683-
(active, must_not_suspend, "1.56.0", Some(83310), None),
682+
/// Allows the `#[must_not_suspend]` attribute.
683+
(active, must_not_suspend, "1.57.0", Some(83310), None),
684684

685685

686686
// -------------------------------------------------------------------------

compiler/rustc_lint_defs/src/builtin.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,8 @@ declare_lint! {
315315
}
316316

317317
declare_lint! {
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)
318+
/// The `must_not_suspend` lint guards against values that shouldn't be held across yield points
319+
/// (`.await`)
326320
///
327321
/// ### Example
328322
///
@@ -339,9 +333,23 @@ declare_lint! {
339333
/// yield_now().await;
340334
/// }
341335
/// ```
336+
///
337+
/// {{produces}}
338+
///
339+
/// ### Explanation
340+
///
341+
/// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
342+
/// attribute being held across yield points. A "yield" point is usually a `.await` in an async
343+
/// function.
344+
///
345+
/// This attribute can be used to mark values that are semantically incorrect across yields
346+
/// (like certain types of timers), values that have async alternatives, and values that
347+
/// regularly cause problems with the `Send`-ness of async fn's returned futures (like
348+
/// `MutexGuard`'s)
349+
///
342350
pub MUST_NOT_SUSPEND,
343351
Warn,
344-
"Use of a `#[must_not_suspend]` value across a yield point",
352+
"use of a `#[must_not_suspend]` value across a yield point",
345353
}
346354

347355
declare_lint! {

compiler/rustc_typeck/src/check/generator_interior.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,10 @@ pub fn check_must_not_suspend_ty<'tcx>(
463463
plural_len: usize,
464464
) -> bool {
465465
if ty.is_unit()
466+
// FIXME: should this check `is_ty_uninhabited_from`. This query is not available in this stage
467+
// of typeck (before ReVar and RePlaceholder are removed), but may remove noise, like in
468+
// `must_use`
466469
// || fcx.tcx.is_ty_uninhabited_from(fcx.tcx.parent_module(hir_id).to_def_id(), ty, fcx.param_env)
467-
// FIXME: should this check is_ty_uninhabited_from
468470
{
469471
return true;
470472
}
@@ -496,6 +498,7 @@ pub fn check_must_not_suspend_ty<'tcx>(
496498
descr_pre,
497499
descr_post,
498500
),
501+
// FIXME: support adding the attribute to TAITs
499502
ty::Opaque(def, _) => {
500503
let mut has_emitted = false;
501504
for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
@@ -604,18 +607,18 @@ fn check_must_not_suspend_def(
604607
);
605608
let mut err = lint.build(&msg);
606609

610+
// add span pointing to the offending yield/await
611+
err.span_label(yield_span, "the value is held across this yield point");
612+
607613
// Add optional reason note
608614
if let Some(note) = attr.value_str() {
609-
err.note(&note.as_str());
615+
err.span_note(source_span, &note.as_str());
610616
}
611617

612-
// add span pointing to the offending yield/await)
613-
err.span_label(yield_span, "The value is held across this yield point");
614-
615618
// Add some quick suggestions on what to do
616619
err.span_help(
617620
source_span,
618-
"`drop` this value before the yield point, or use a block (`{ ... }`) \"
621+
"`drop` this value before the yield point, or use a block (`{ ... }`) \
619622
to shrink its scope",
620623
);
621624

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ error: boxed `Umm` held across a yield point, but should not be
44
LL | let _guard = bar();
55
| ^^^^^^
66
LL | other().await;
7-
| ------------- The value is held across this yield point
7+
| ------------- the value is held across this yield point
88
|
99
note: the lint level is defined here
1010
--> $DIR/boxed.rs:3:9
1111
|
1212
LL | #![deny(must_not_suspend)]
1313
| ^^^^^^^^^^^^^^^^
14-
= note: You gotta use Umm's, ya know?
15-
help: `drop` this value before the yield point, or use a block (`{ ... }`) "
16-
to shrink its scope
14+
note: You gotta use Umm's, ya know?
15+
--> $DIR/boxed.rs:20:9
16+
|
17+
LL | let _guard = bar();
18+
| ^^^^^^
19+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
1720
--> $DIR/boxed.rs:20:9
1821
|
1922
LL | let _guard = bar();

src/test/ui/lint/must_not_suspend/ref.stderr

+14-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@ LL | let guard = &mut self.u;
55
| ^^^^^^
66
...
77
LL | other().await;
8-
| ------------- The value is held across this yield point
8+
| ------------- the value is held across this yield point
99
|
1010
note: the lint level is defined here
1111
--> $DIR/ref.rs:3:9
1212
|
1313
LL | #![deny(must_not_suspend)]
1414
| ^^^^^^^^^^^^^^^^
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
15+
note: You gotta use Umm's, ya know?
16+
--> $DIR/ref.rs:18:26
17+
|
18+
LL | let guard = &mut self.u;
19+
| ^^^^^^
20+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
1821
--> $DIR/ref.rs:18:26
1922
|
2023
LL | let guard = &mut self.u;
@@ -27,11 +30,14 @@ LL | let guard = &mut self.u;
2730
| ^^^^^^
2831
...
2932
LL | other().await;
30-
| ------------- The value is held across this yield point
33+
| ------------- the value is held across this yield point
3134
|
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+
note: You gotta use Umm's, ya know?
36+
--> $DIR/ref.rs:18:26
37+
|
38+
LL | let guard = &mut self.u;
39+
| ^^^^^^
40+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
3541
--> $DIR/ref.rs:18:26
3642
|
3743
LL | let guard = &mut self.u;

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

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ LL | let _guard1 = r#impl();
55
| ^^^^^^^
66
...
77
LL | other().await;
8-
| ------------- The value is held across this yield point
8+
| ------------- the value is held across this yield point
99
|
1010
note: the lint level is defined here
1111
--> $DIR/trait.rs:3:9
1212
|
1313
LL | #![deny(must_not_suspend)]
1414
| ^^^^^^^^^^^^^^^^
15-
help: `drop` this value before the yield point, or use a block (`{ ... }`) "
16-
to shrink its scope
15+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
1716
--> $DIR/trait.rs:21:9
1817
|
1918
LL | let _guard1 = r#impl();
@@ -26,10 +25,9 @@ LL | let _guard2 = r#dyn();
2625
| ^^^^^^^
2726
LL |
2827
LL | other().await;
29-
| ------------- The value is held across this yield point
28+
| ------------- the value is held across this yield point
3029
|
31-
help: `drop` this value before the yield point, or use a block (`{ ... }`) "
32-
to shrink its scope
30+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
3331
--> $DIR/trait.rs:22:9
3432
|
3533
LL | let _guard2 = r#dyn();

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@ error: `Umm` held across a yield point, but should not be
44
LL | let _guard = bar();
55
| ^^^^^^
66
LL | other().await;
7-
| ------------- The value is held across this yield point
7+
| ------------- the value is held across this yield point
88
|
99
note: the lint level is defined here
1010
--> $DIR/unit.rs:3:9
1111
|
1212
LL | #![deny(must_not_suspend)]
1313
| ^^^^^^^^^^^^^^^^
14-
= note: You gotta use Umm's, ya know?
15-
help: `drop` this value before the yield point, or use a block (`{ ... }`) "
16-
to shrink its scope
14+
note: You gotta use Umm's, ya know?
15+
--> $DIR/unit.rs:20:9
16+
|
17+
LL | let _guard = bar();
18+
| ^^^^^^
19+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
1720
--> $DIR/unit.rs:20:9
1821
|
1922
LL | let _guard = bar();

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ warning: `Umm` held across a yield point, but should not be
44
LL | let _guard = bar();
55
| ^^^^^^
66
LL | other().await;
7-
| ------------- The value is held across this yield point
7+
| ------------- the value is held across this yield point
88
|
99
= note: `#[warn(must_not_suspend)]` on by default
10-
= note: You gotta use Umm's, ya know?
11-
help: `drop` this value before the yield point, or use a block (`{ ... }`) "
12-
to shrink its scope
10+
note: You gotta use Umm's, ya know?
11+
--> $DIR/warn.rs:20:9
12+
|
13+
LL | let _guard = bar();
14+
| ^^^^^^
15+
help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
1316
--> $DIR/warn.rs:20:9
1417
|
1518
LL | let _guard = bar();

0 commit comments

Comments
 (0)