@@ -8,7 +8,6 @@ use crate::infer::InferCtxt;
88use crate :: traits:: normalize_to;
99
1010use hir:: HirId ;
11- use rustc_ast:: Movability ;
1211use rustc_data_structures:: fx:: FxHashSet ;
1312use rustc_data_structures:: stack:: ensure_sufficient_stack;
1413use rustc_errors:: {
@@ -2396,19 +2395,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
23962395 }
23972396 } ;
23982397
2399- let future_trait = self . tcx . lang_items ( ) . future_trait ( ) . unwrap ( ) ;
2400- let opaque_ty_is_future = |def_id| {
2401- self . tcx . explicit_item_bounds ( def_id) . iter ( ) . any ( |( predicate, _) | {
2402- if let ty:: PredicateKind :: Trait ( trait_predicate) =
2403- predicate. kind ( ) . skip_binder ( )
2404- {
2405- trait_predicate. trait_ref . def_id == future_trait
2406- } else {
2407- false
2408- }
2409- } )
2410- } ;
2411-
24122398 let from_generator = tcx. lang_items ( ) . from_generator_fn ( ) . unwrap ( ) ;
24132399
24142400 // Don't print the tuple of capture types
@@ -2434,13 +2420,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24342420
24352421 // If the previous type is `from_generator`, this is the future generated by the body of an async function.
24362422 // Avoid printing it twice (it was already printed in the `ty::Generator` arm below).
2437- let is_future = opaque_ty_is_future ( def_id ) ;
2423+ let is_future = tcx . ty_is_opaque_future ( ty ) ;
24382424 debug ! (
24392425 ?obligated_types,
24402426 ?is_future,
24412427 "note_obligation_cause_code: check for async fn"
24422428 ) ;
2443- if opaque_ty_is_future ( def_id )
2429+ if is_future
24442430 && obligated_types. last ( ) . map_or ( false , |ty| match ty. kind ( ) {
24452431 ty:: Opaque ( last_def_id, _) => {
24462432 tcx. parent ( * last_def_id) == from_generator
@@ -2465,15 +2451,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24652451 }
24662452 err. note ( msg. trim_end_matches ( ", " ) )
24672453 }
2468- ty:: Generator ( def_id, _, movability ) => {
2454+ ty:: Generator ( def_id, _, _ ) => {
24692455 let sp = self . tcx . def_span ( def_id) ;
24702456
24712457 // Special-case this to say "async block" instead of `[static generator]`.
2472- let kind = if * movability == Movability :: Static {
2473- "async block"
2474- } else {
2475- "generator"
2476- } ;
2458+ let kind = tcx. generator_kind ( def_id) . unwrap ( ) ;
24772459 err. span_note (
24782460 sp,
24792461 & format ! ( "required because it's used within this {}" , kind) ,
0 commit comments