fn note_obligation_cause_for_async_await(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        target_span: Span,
        scope_span: &Option<Span>,
        snippet: String,
        first_generator: DefId,
        last_generator: Option<DefId>,
        trait_ref: ty::TraitRef<'_>,
        target_ty: Ty<'tcx>,
        tables: &ty::TypeckTables<'_>,
        obligation: &PredicateObligation<'tcx>,
        next_code: Option<&ObligationCauseCode<'tcx>>,
    ) {
        let source_map = self.tcx.sess.source_map();

        let is_async_fn = self.tcx.parent(first_generator)
            .map(|parent_did| self.tcx.asyncness(parent_did))
            .map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
            .unwrap_or(false);
        let is_async_move = self.tcx.hir().as_local_hir_id(first_generator)
            .and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
            .map(|body_id| self.tcx.hir().body(body_id))
            .and_then(|body| body.generator_kind())
            .map(|generator_kind| match generator_kind {
                hir::GeneratorKind::Async(..) => true,
                _ => false,
            })
            .unwrap_or(false);
        let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };

        // Special case the primary error message when send or sync is the trait that was
        // not implemented.
        let is_send = self.tcx.is_diagnostic_item(sym::send_trait, trait_ref.def_id);
        let is_sync = self.tcx.is_diagnostic_item(sym::sync_trait, trait_ref.def_id);
        let trait_explanation = if is_send || is_sync {
            let (trait_name, trait_verb) = if is_send {
                ("`Send`", "sent")
            } else {
                ("`Sync`", "shared")
            };

            err.clear_code();
            err.set_primary_message(
                format!("future cannot be {} between threads safely", trait_verb)
            );

            let original_span = err.span.primary_span().unwrap();
            let mut span = MultiSpan::from_span(original_span);

            let message = if let Some(name) = last_generator
                .and_then(|generator_did| self.tcx.parent(generator_did))
                .and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
                .and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
            {
                format!("future returned by `{}` is not {}", name, trait_name)
            } else {
                format!("future is not {}", trait_name)
            };

            span.push_span_label(original_span, message);
            err.set_span(span);

            format!("is not {}", trait_name)
        } else {
            format!("does not implement `{}`", trait_ref.print_only_trait_path())
        };

        // Look at the last interior type to get a span for the `.await`.
        let await_span = tables.generator_interior_types.iter().map(|i| i.span).last().unwrap();
        let mut span = MultiSpan::from_span(await_span);
        span.push_span_label(
            await_span,
            format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet));

        span.push_span_label(target_span, format!("has type `{}`", target_ty));

        // If available, use the scope span to annotate the drop location.
        if let Some(scope_span) = scope_span {
            span.push_span_label(
                source_map.end_point(*scope_span),
                format!("`{}` is later dropped here", snippet),
            );
        }

        err.span_note(span, &format!(
            "future {} as this value is used across an {}",
            trait_explanation,
            await_or_yield,
        ));

        // Add a note for the item obligation that remains - normally a note pointing to the
        // bound that introduced the obligation (e.g. `T: Send`).
        debug!("note_obligation_cause_for_async_await: next_code={:?}", next_code);
        self.note_obligation_cause_code(
            err,
            &obligation.predicate,
            next_code.unwrap(),
            &mut Vec::new(),
        );
    }
/// Unconditionally adds the diagnostic note described in
/// `maybe_note_obligation_cause_for_async_await`'s documentation comment.
Unconditionally adds the diagnostic note described in
`maybe_note_obligation_cause_for_async_await`'s documentation comment.
Unconditionally adds the diagnostic note described in ` maybe_note_obligation_cause_for_async_await ` ' s documentation comment .
fn note_obligation_cause_for_async_await(
        &self,
        err: &mut DiagnosticBuilder<'_>,
        target_span: Span,
        scope_span: &Option<Span>,
        snippet: String,
        first_generator: DefId,
        last_generator: Option<DefId>,
        trait_ref: ty::TraitRef<'_>,
        target_ty: Ty<'tcx>,
        tables: &ty::TypeckTables<'_>,
        obligation: &PredicateObligation<'tcx>,
        next_code: Option<&ObligationCauseCode<'tcx>>,
    ) {
        let source_map = self.tcx.sess.source_map();
        let is_async_fn = self.tcx.parent(first_generator)
            .map(|parent_did| self.tcx.asyncness(parent_did))
            .map(|parent_asyncness| parent_asyncness == hir::IsAsync::Async)
            .unwrap_or(false);
        let is_async_move = self.tcx.hir().as_local_hir_id(first_generator)
            .and_then(|hir_id| self.tcx.hir().maybe_body_owned_by(hir_id))
            .map(|body_id| self.tcx.hir().body(body_id))
            .and_then(|body| body.generator_kind())
            .map(|generator_kind| match generator_kind {
                hir::GeneratorKind::Async(..) => true,
                _ => false,
            })
            .unwrap_or(false);
        let await_or_yield = if is_async_fn || is_async_move { "await" } else { "yield" };
        // Special case the primary error message when send or sync is the trait that was
        // not implemented.
        let is_send = self.tcx.is_diagnostic_item(sym::send_trait, trait_ref.def_id);
        let is_sync = self.tcx.is_diagnostic_item(sym::sync_trait, trait_ref.def_id);
        let trait_explanation = if is_send || is_sync {
            let (trait_name, trait_verb) = if is_send {
                ("`Send`", "sent")
            } else {
                ("`Sync`", "shared")
            };
            err.clear_code();
            err.set_primary_message(
                format!("future cannot be {} between threads safely", trait_verb)
            );
            let original_span = err.span.primary_span().unwrap();
            let mut span = MultiSpan::from_span(original_span);
            let message = if let Some(name) = last_generator
                .and_then(|generator_did| self.tcx.parent(generator_did))
                .and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
                .and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
            {
                format!("future returned by `{}` is not {}", name, trait_name)
            } else {
                format!("future is not {}", trait_name)
            };
            span.push_span_label(original_span, message);
            err.set_span(span);
            format!("is not {}", trait_name)
        } else {
            format!("does not implement `{}`", trait_ref.print_only_trait_path())
        };
        // Look at the last interior type to get a span for the `.await`.
        let await_span = tables.generator_interior_types.iter().map(|i| i.span).last().unwrap();
        let mut span = MultiSpan::from_span(await_span);
        span.push_span_label(
            await_span,
            format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet));
        span.push_span_label(target_span, format!("has type `{}`", target_ty));
        // If available, use the scope span to annotate the drop location.
        if let Some(scope_span) = scope_span {
            span.push_span_label(
                source_map.end_point(*scope_span),
                format!("`{}` is later dropped here", snippet),
            );
        }
        err.span_note(span, &format!(
            "future {} as this value is used across an {}",
            trait_explanation,
            await_or_yield,
        ));
        // Add a note for the item obligation that remains - normally a note pointing to the
        // bound that introduced the obligation (e.g. `T: Send`).
        debug!("note_obligation_cause_for_async_await: next_code={:?}", next_code);
        self.note_obligation_cause_code(
            err,
            &obligation.predicate,
            next_code.unwrap(),
            &mut Vec::new(),
        );
    }
fn note_obligation_cause_for_async_await ( & self , err : & mut DiagnosticBuilder < ' _ > , target_span : Span , scope_span : & Option < Span > , snippet : String , first_generator : DefId , last_generator : Option < DefId > , trait_ref : ty :: TraitRef < ' _ > , target_ty : Ty < ' tcx > , tables : & ty :: TypeckTables < ' _ > , obligation : & PredicateObligation < ' tcx > , next_code : Option < & ObligationCauseCode < ' tcx > > , ) { let source_map = self . tcx . sess . source_map ( ) ; let is_async_fn = self . tcx . parent ( first_generator ) . map ( | parent_did | self . tcx . asyncness ( parent_did ) ) . map ( | parent_asyncness | parent_asyncness == hir :: IsAsync :: Async ) . unwrap_or ( false ) ; let is_async_move = self . tcx . hir ( ) . as_local_hir_id ( first_generator ) . and_then ( | hir_id | self . tcx . hir ( ) . maybe_body_owned_by ( hir_id ) ) . map ( | body_id | self . tcx . hir ( ) . body ( body_id ) ) . and_then ( | body | body . generator_kind ( ) ) . map ( | generator_kind | match generator_kind { hir :: GeneratorKind :: Async ( .. ) => true , _ => false , } ) . unwrap_or ( false ) ; let await_or_yield = if is_async_fn || is_async_move { " " } else { " " } ; // Special case the primary error message when send or sync is the trait that was // not implemented. let is_send = self . tcx . is_diagnostic_item ( sym :: send_trait , trait_ref . def_id ) ; let is_sync = self . tcx . is_diagnostic_item ( sym :: sync_trait , trait_ref . def_id ) ; let trait_explanation = if is_send || is_sync { let ( trait_name , trait_verb ) = if is_send { ( " " , " " ) } else { ( " " , " " ) } ; err . clear_code ( ) ; err . set_primary_message ( format ! ( " " trait_verb ) ) ; let original_span = err . span . primary_span ( ) . unwrap ( ) ; let mut span = MultiSpan :: from_span ( original_span ) ; let message = if let Some ( name ) = last_generator . and_then ( | generator_did | self . tcx . parent ( generator_did ) ) . and_then ( | parent_did | self . tcx . hir ( ) . as_local_hir_id ( parent_did ) ) . and_then ( | parent_hir_id | self . tcx . hir ( ) . opt_name ( parent_hir_id ) ) { format ! ( " " name trait_name ) } else { format ! ( " " trait_name ) } ; span . push_span_label ( original_span , message ) ; err . set_span ( span ) ; format ! ( " " trait_name ) } else { format ! ( " " trait_ref print_only_trait_path ( ) ) } ; // Look at the last interior type to get a span for the `.await`. let await_span = tables . generator_interior_types . iter ( ) . map ( | i | i . span ) . last ( ) . unwrap ( ) ; let mut span = MultiSpan :: from_span ( await_span ) ; span . push_span_label ( await_span , format ! ( " " await_or_yield snippet ) ) ; span . push_span_label ( target_span , format ! ( " " target_ty ) ) ; // If available, use the scope span to annotate the drop location. if let Some ( scope_span ) = scope_span { span . push_span_label ( source_map . end_point ( * scope_span ) , format ! ( " " snippet ) , ) ; } err . span_note ( span , & format ! ( " " trait_explanation await_or_yield ) ) ; // Add a note for the item obligation that remains - normally a note pointing to the // bound that introduced the obligation (e.g. `T: Send`). debug ! ( " " next_code ) ; self . note_obligation_cause_code ( err , & obligation . predicate , next_code . unwrap ( ) , & mut Vec :: new ( ) , ) ; }
Unconditionally adds the diagnostic note described in
`maybe_note_obligation_cause_for_async_await`'s documentation comment.
Unconditionally adds the diagnostic note described in ` maybe_note_obligation_cause_for_async_await ` ' s documentation comment .
&self
err
&mut DiagnosticBuilder<'_>
target_span
Span
scope_span
&Option<Span>
snippet
String
first_generator
DefId
last_generator
Option<DefId>
trait_ref
ty::TraitRef<'_>
target_ty
Ty<'tcx>
tables
&ty::TypeckTables<'_>
obligation
&PredicateObligation<'tcx>
next_code
Option<&ObligationCauseCode<'tcx>>