about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorGus Wynn <guswynn@gmail.com>2021-09-13 08:19:40 -0700
committerGus Wynn <guswynn@gmail.com>2021-09-13 08:19:40 -0700
commit2af1ebfbdf01e4aa43fd9b1b5af602b545101e1f (patch)
tree61263b7478f56fd26bb4b3638167105dbab06eee /compiler
parentee1d2ea3b73d07d95d5c22ccd1e884e3674fcec6 (diff)
downloadrust-2af1ebfbdf01e4aa43fd9b1b5af602b545101e1f.tar.gz
rust-2af1ebfbdf01e4aa43fd9b1b5af602b545101e1f.zip
error formatting and fix build
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_feature/src/active.rs4
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs26
-rw-r--r--compiler/rustc_typeck/src/check/generator_interior.rs15
3 files changed, 28 insertions, 17 deletions
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index 66569270bd2..6ab925cfa9b 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -679,8 +679,8 @@ declare_features! (
     /// 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),
 
 
     // -------------------------------------------------------------------------
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs
index 781ac6a14a4..a192056e244 100644
--- a/compiler/rustc_lint_defs/src/builtin.rs
+++ b/compiler/rustc_lint_defs/src/builtin.rs
@@ -315,14 +315,8 @@ declare_lint! {
 }
 
 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
     ///
@@ -339,9 +333,23 @@ declare_lint! {
     ///     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! {
diff --git a/compiler/rustc_typeck/src/check/generator_interior.rs b/compiler/rustc_typeck/src/check/generator_interior.rs
index 1b63d6d9741..7e4bc08c172 100644
--- a/compiler/rustc_typeck/src/check/generator_interior.rs
+++ b/compiler/rustc_typeck/src/check/generator_interior.rs
@@ -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",
                     );