]> git.lizzy.rs Git - rust.git/commitdiff
error formatting and fix build
authorGus Wynn <guswynn@gmail.com>
Mon, 13 Sep 2021 15:19:40 +0000 (08:19 -0700)
committerGus Wynn <guswynn@gmail.com>
Mon, 13 Sep 2021 15:19:40 +0000 (08:19 -0700)
compiler/rustc_feature/src/active.rs
compiler/rustc_lint_defs/src/builtin.rs
compiler/rustc_typeck/src/check/generator_interior.rs
src/test/ui/lint/must_not_suspend/boxed.stderr
src/test/ui/lint/must_not_suspend/ref.stderr
src/test/ui/lint/must_not_suspend/trait.stderr
src/test/ui/lint/must_not_suspend/unit.stderr
src/test/ui/lint/must_not_suspend/warn.stderr

index 66569270bd21ec3c4555948218b8b9d16f79f013..6ab925cfa9b7f70ae0bebcb457324d8165e12e34 100644 (file)
@@ -679,8 +679,8 @@ pub fn set(&self, features: &mut Features, span: Span) {
     /// Allows `let...else` statements.
     (active, let_else, "1.56.0", Some(87335), None),
 
-    /// Allows `#[must_not_suspend]`.
-    (active, must_not_suspend, "1.56.0", Some(83310), None),
+    /// Allows the `#[must_not_suspend]` attribute.
+    (active, must_not_suspend, "1.57.0", Some(83310), None),
 
 
     // -------------------------------------------------------------------------
index 781ac6a14a4b32a7b8490a4229fd0b8a07681c70..a192056e244bd2c6216fdd8d3bd1d114781067b8 100644 (file)
 }
 
 declare_lint! {
-    /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
-    /// attribute being held across yield points. A "yield" point is usually a `.await` in an async
-    /// function.
-    ///
-    /// This attribute can be used to mark values that are semantically incorrect across yields
-    /// (like certain types of timers), values that have async alternatives, and values that
-    /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
-    /// `MutexGuard`'s)
+    /// The `must_not_suspend` lint guards against values that shouldn't be held across yield points
+    /// (`.await`)
     ///
     /// ### Example
     ///
     ///     yield_now().await;
     /// }
     /// ```
+    ///
+    /// {{produces}}
+    ///
+    /// ### Explanation
+    ///
+    /// The `must_not_suspend` lint detects values that are marked with the `#[must_not_suspend]`
+    /// attribute being held across yield points. A "yield" point is usually a `.await` in an async
+    /// function.
+    ///
+    /// This attribute can be used to mark values that are semantically incorrect across yields
+    /// (like certain types of timers), values that have async alternatives, and values that
+    /// regularly cause problems with the `Send`-ness of async fn's returned futures (like
+    /// `MutexGuard`'s)
+    ///
     pub MUST_NOT_SUSPEND,
     Warn,
-    "Use of a `#[must_not_suspend]` value across a yield point",
+    "use of a `#[must_not_suspend]` value across a yield point",
 }
 
 declare_lint! {
index 1b63d6d9741481282fafb21e3d403d2e15c8e0d9..7e4bc08c1723c50b89ee8225eb63f9f2cc8582df 100644 (file)
@@ -463,8 +463,10 @@ pub fn check_must_not_suspend_ty<'tcx>(
     plural_len: usize,
 ) -> bool {
     if ty.is_unit()
+    // FIXME: should this check `is_ty_uninhabited_from`. This query is not available in this stage
+    // of typeck (before ReVar and RePlaceholder are removed), but may remove noise, like in
+    // `must_use`
     // || 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
     {
         return true;
     }
@@ -496,6 +498,7 @@ pub fn check_must_not_suspend_ty<'tcx>(
             descr_pre,
             descr_post,
         ),
+        // FIXME: support adding the attribute to TAITs
         ty::Opaque(def, _) => {
             let mut has_emitted = false;
             for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) {
@@ -604,18 +607,18 @@ fn check_must_not_suspend_def(
                     );
                     let mut err = lint.build(&msg);
 
+                    // add span pointing to the offending yield/await
+                    err.span_label(yield_span, "the value is held across this yield point");
+
                     // Add optional reason note
                     if let Some(note) = attr.value_str() {
-                        err.note(&note.as_str());
+                        err.span_note(source_span, &note.as_str());
                     }
 
-                    // add span pointing to the offending yield/await)
-                    err.span_label(yield_span, "The value is held across this yield point");
-
                     // Add some quick suggestions on what to do
                     err.span_help(
                         source_span,
-                        "`drop` this value before the yield point, or use a block (`{ ... }`) \"
+                        "`drop` this value before the yield point, or use a block (`{ ... }`) \
                         to shrink its scope",
                     );
 
index c3c23db7d72f7e825bab8833b058b44e5d2d6af8..7bd80405b5de61d9916f7b3646ec067d361271d4 100644 (file)
@@ -4,16 +4,19 @@ error: boxed `Umm` held across a yield point, but should not be
 LL |     let _guard = bar();
    |         ^^^^^^
 LL |     other().await;
-   |     ------------- The value is held across this yield point
+   |     ------------- the value is held across this yield point
    |
 note: the lint level is defined here
   --> $DIR/boxed.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
+note: You gotta use Umm's, ya know?
+  --> $DIR/boxed.rs:20:9
+   |
+LL |     let _guard = bar();
+   |         ^^^^^^
+help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
   --> $DIR/boxed.rs:20:9
    |
 LL |     let _guard = bar();
index 91c91a4b545f8291e6ec3c61e9244609c02425d0..d2a550d7b45d4807e8d6a1ebd257e5b863a63e54 100644 (file)
@@ -5,16 +5,19 @@ LL |         let guard = &mut self.u;
    |                          ^^^^^^
 ...
 LL |         other().await;
-   |         ------------- The value is held across this yield point
+   |         ------------- 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
+note: You gotta use Umm's, ya know?
+  --> $DIR/ref.rs:18:26
+   |
+LL |         let guard = &mut self.u;
+   |                          ^^^^^^
+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;
@@ -27,11 +30,14 @@ LL |         let guard = &mut self.u;
    |                          ^^^^^^
 ...
 LL |         other().await;
-   |         ------------- The value is held across this yield point
+   |         ------------- 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
+note: You gotta use Umm's, ya know?
+  --> $DIR/ref.rs:18:26
+   |
+LL |         let guard = &mut self.u;
+   |                          ^^^^^^
+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;
index 1175cbb9192083ef9db5dd8d00e911333f947ada..8d7bb80876440cbddcedd1e67d9fc67c2b4f7baa 100644 (file)
@@ -5,15 +5,14 @@ LL |     let _guard1 = r#impl();
    |         ^^^^^^^
 ...
 LL |     other().await;
-   |     ------------- The value is held across this yield point
+   |     ------------- the value is held across this yield point
    |
 note: the lint level is defined here
   --> $DIR/trait.rs:3:9
    |
 LL | #![deny(must_not_suspend)]
    |         ^^^^^^^^^^^^^^^^
-help: `drop` this value before the yield point, or use a block (`{ ... }`) "
-                        to shrink its scope
+help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
   --> $DIR/trait.rs:21:9
    |
 LL |     let _guard1 = r#impl();
@@ -26,10 +25,9 @@ LL |     let _guard2 = r#dyn();
    |         ^^^^^^^
 LL | 
 LL |     other().await;
-   |     ------------- The value is held across this yield point
+   |     ------------- the value is held across this yield point
    |
-help: `drop` this value before the yield point, or use a block (`{ ... }`) "
-                        to shrink its scope
+help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
   --> $DIR/trait.rs:22:9
    |
 LL |     let _guard2 = r#dyn();
index cff00dd8ca4099466455f16ca1c4c7ea0f83961b..87e0fd27e70f2c73d4c548c295d461cc0c9d6500 100644 (file)
@@ -4,16 +4,19 @@ error: `Umm` held across a yield point, but should not be
 LL |     let _guard = bar();
    |         ^^^^^^
 LL |     other().await;
-   |     ------------- The value is held across this yield point
+   |     ------------- the value is held across this yield point
    |
 note: the lint level is defined here
   --> $DIR/unit.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
+note: You gotta use Umm's, ya know?
+  --> $DIR/unit.rs:20:9
+   |
+LL |     let _guard = bar();
+   |         ^^^^^^
+help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
   --> $DIR/unit.rs:20:9
    |
 LL |     let _guard = bar();
index bda44d051ee7c4149fe3bf7c9785f65a37739d10..03b77520c9f9f526113032b02a5eea7f322b2556 100644 (file)
@@ -4,12 +4,15 @@ warning: `Umm` held across a yield point, but should not be
 LL |     let _guard = bar();
    |         ^^^^^^
 LL |     other().await;
-   |     ------------- The value is held across this yield point
+   |     ------------- the value is held across this yield point
    |
    = note: `#[warn(must_not_suspend)]` on by default
-   = note: You gotta use Umm's, ya know?
-help: `drop` this value before the yield point, or use a block (`{ ... }`) "
-                        to shrink its scope
+note: You gotta use Umm's, ya know?
+  --> $DIR/warn.rs:20:9
+   |
+LL |     let _guard = bar();
+   |         ^^^^^^
+help: `drop` this value before the yield point, or use a block (`{ ... }`) to shrink its scope
   --> $DIR/warn.rs:20:9
    |
 LL |     let _guard = bar();