@@ -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:: {
@@ -2406,19 +2405,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24062405 }
24072406 } ;
24082407
2409- let future_trait = self . tcx . lang_items ( ) . future_trait ( ) . unwrap ( ) ;
2410- let opaque_ty_is_future = |def_id| {
2411- self . tcx . explicit_item_bounds ( def_id) . iter ( ) . any ( |( predicate, _) | {
2412- if let ty:: PredicateKind :: Trait ( trait_predicate) =
2413- predicate. kind ( ) . skip_binder ( )
2414- {
2415- trait_predicate. trait_ref . def_id == future_trait
2416- } else {
2417- false
2418- }
2419- } )
2420- } ;
2421-
24222408 let from_generator = tcx. lang_items ( ) . from_generator_fn ( ) . unwrap ( ) ;
24232409
24242410 // Don't print the tuple of capture types
@@ -2444,13 +2430,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24442430
24452431 // If the previous type is `from_generator`, this is the future generated by the body of an async function.
24462432 // Avoid printing it twice (it was already printed in the `ty::Generator` arm below).
2447- let is_future = opaque_ty_is_future ( def_id ) ;
2433+ let is_future = tcx . ty_is_opaque_future ( ty ) ;
24482434 debug ! (
24492435 ?obligated_types,
24502436 ?is_future,
24512437 "note_obligation_cause_code: check for async fn"
24522438 ) ;
2453- if opaque_ty_is_future ( def_id )
2439+ if is_future
24542440 && obligated_types. last ( ) . map_or ( false , |ty| match ty. kind ( ) {
24552441 ty:: Opaque ( last_def_id, _) => {
24562442 tcx. parent ( * last_def_id) == from_generator
@@ -2475,15 +2461,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
24752461 }
24762462 err. note ( msg. trim_end_matches ( ", " ) )
24772463 }
2478- ty:: Generator ( def_id, _, movability ) => {
2464+ ty:: Generator ( def_id, _, _ ) => {
24792465 let sp = self . tcx . def_span ( def_id) ;
24802466
24812467 // Special-case this to say "async block" instead of `[static generator]`.
2482- let kind = if * movability == Movability :: Static {
2483- "async block"
2484- } else {
2485- "generator"
2486- } ;
2468+ let kind = tcx. generator_kind ( def_id) . unwrap ( ) ;
24872469 err. span_note (
24882470 sp,
24892471 & format ! ( "required because it's used within this {}" , kind) ,
0 commit comments