]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_hir_analysis/src/check/generator_interior.rs
Auto merge of #103185 - chenyukang:yukang/fix-span-next-point, r=davidtwco
[rust.git] / compiler / rustc_hir_analysis / src / check / generator_interior.rs
index 254a19368bfe2bc6fbc4364021d6c1f32edec394..898419b5b237450ec2b62f9bc95001bbf6dbfaeb 100644 (file)
@@ -6,7 +6,7 @@
 use self::drop_ranges::DropRanges;
 use super::FnCtxt;
 use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
-use rustc_errors::pluralize;
+use rustc_errors::{pluralize, DelayDm};
 use rustc_hir as hir;
 use rustc_hir::def::{CtorKind, DefKind, Res};
 use rustc_hir::def_id::DefId;
@@ -610,33 +610,33 @@ fn check_must_not_suspend_def(
             rustc_session::lint::builtin::MUST_NOT_SUSPEND,
             hir_id,
             data.source_span,
-            |lint| {
-                let msg = format!(
+            DelayDm(|| {
+                format!(
                     "{}`{}`{} held across a suspend point, but should not be",
                     data.descr_pre,
                     tcx.def_path_str(def_id),
                     data.descr_post,
-                );
-                let mut err = lint.build(&msg);
-
+                )
+            }),
+            |lint| {
                 // add span pointing to the offending yield/await
-                err.span_label(data.yield_span, "the value is held across this suspend point");
+                lint.span_label(data.yield_span, "the value is held across this suspend point");
 
                 // Add optional reason note
                 if let Some(note) = attr.value_str() {
                     // FIXME(guswynn): consider formatting this better
-                    err.span_note(data.source_span, note.as_str());
+                    lint.span_note(data.source_span, note.as_str());
                 }
 
                 // Add some quick suggestions on what to do
                 // FIXME: can `drop` work as a suggestion here as well?
-                err.span_help(
+                lint.span_help(
                     data.source_span,
                     "consider using a block (`{ ... }`) \
                     to shrink the value's scope, ending before the suspend point",
                 );
 
-                err.emit();
+                lint
             },
         );