@@ -1890,12 +1890,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1890
1890
//
1891
1891
// - `BuiltinDerivedObligation` with a generator witness (B)
1892
1892
// - `BuiltinDerivedObligation` with a generator (B)
1893
- // - `BuiltinDerivedObligation` with `std::future::GenFuture` (B)
1894
1893
// - `BuiltinDerivedObligation` with `impl std::future::Future` (B)
1895
1894
// - `BuiltinDerivedObligation` with `impl std::future::Future` (B)
1896
1895
// - `BuiltinDerivedObligation` with a generator witness (A)
1897
1896
// - `BuiltinDerivedObligation` with a generator (A)
1898
- // - `BuiltinDerivedObligation` with `std::future::GenFuture` (A)
1899
1897
// - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
1900
1898
// - `BuiltinDerivedObligation` with `impl std::future::Future` (A)
1901
1899
// - `BindingObligation` with `impl_send (Send requirement)
@@ -2637,79 +2635,44 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2637
2635
}
2638
2636
} ;
2639
2637
2640
- let from_generator = tcx. lang_items ( ) . from_generator_fn ( ) . unwrap ( ) ;
2641
-
2642
2638
// Don't print the tuple of capture types
2643
- ' print: {
2644
- if !is_upvar_tys_infer_tuple {
2645
- let msg = format ! ( "required because it appears within the type `{}`" , ty) ;
2646
- match ty. kind ( ) {
2647
- ty:: Adt ( def, _) => {
2648
- // `gen_future` is used in all async functions; it doesn't add any additional info.
2649
- if self . tcx . is_diagnostic_item ( sym:: gen_future, def. did ( ) ) {
2650
- break ' print;
2651
- }
2652
- match self . tcx . opt_item_ident ( def. did ( ) ) {
2653
- Some ( ident) => err. span_note ( ident. span , & msg) ,
2654
- None => err. note ( & msg) ,
2655
- }
2656
- }
2657
- ty:: Opaque ( def_id, _) => {
2658
- // Avoid printing the future from `core::future::from_generator`, it's not helpful
2659
- if tcx. parent ( * def_id) == from_generator {
2660
- break ' print;
2661
- }
2662
-
2663
- // If the previous type is `from_generator`, this is the future generated by the body of an async function.
2664
- // Avoid printing it twice (it was already printed in the `ty::Generator` arm below).
2665
- let is_future = tcx. ty_is_opaque_future ( ty) ;
2666
- debug ! (
2667
- ?obligated_types,
2668
- ?is_future,
2669
- "note_obligation_cause_code: check for async fn"
2670
- ) ;
2671
- if is_future
2672
- && obligated_types. last ( ) . map_or ( false , |ty| match ty. kind ( ) {
2673
- ty:: Opaque ( last_def_id, _) => {
2674
- tcx. parent ( * last_def_id) == from_generator
2675
- }
2676
- _ => false ,
2677
- } )
2678
- {
2679
- break ' print;
2680
- }
2681
- err. span_note ( self . tcx . def_span ( def_id) , & msg)
2682
- }
2683
- ty:: GeneratorWitness ( bound_tys) => {
2684
- use std:: fmt:: Write ;
2685
-
2686
- // FIXME: this is kind of an unusual format for rustc, can we make it more clear?
2687
- // Maybe we should just remove this note altogether?
2688
- // FIXME: only print types which don't meet the trait requirement
2689
- let mut msg =
2690
- "required because it captures the following types: " . to_owned ( ) ;
2691
- for ty in bound_tys. skip_binder ( ) {
2692
- write ! ( msg, "`{}`, " , ty) . unwrap ( ) ;
2693
- }
2694
- err. note ( msg. trim_end_matches ( ", " ) )
2695
- }
2696
- ty:: Generator ( def_id, _, _) => {
2697
- let sp = self . tcx . def_span ( def_id) ;
2698
-
2699
- // Special-case this to say "async block" instead of `[static generator]`.
2700
- let kind = tcx. generator_kind ( def_id) . unwrap ( ) ;
2701
- err. span_note (
2702
- sp,
2703
- & format ! ( "required because it's used within this {}" , kind) ,
2704
- )
2639
+ if !is_upvar_tys_infer_tuple {
2640
+ let msg = format ! ( "required because it appears within the type `{}`" , ty) ;
2641
+ match ty. kind ( ) {
2642
+ ty:: Adt ( def, _) => match self . tcx . opt_item_ident ( def. did ( ) ) {
2643
+ Some ( ident) => err. span_note ( ident. span , & msg) ,
2644
+ None => err. note ( & msg) ,
2645
+ } ,
2646
+ ty:: Opaque ( def_id, _) => err. span_note ( self . tcx . def_span ( def_id) , & msg) ,
2647
+ ty:: GeneratorWitness ( bound_tys) => {
2648
+ use std:: fmt:: Write ;
2649
+
2650
+ // FIXME: this is kind of an unusual format for rustc, can we make it more clear?
2651
+ // Maybe we should just remove this note altogether?
2652
+ // FIXME: only print types which don't meet the trait requirement
2653
+ let mut msg =
2654
+ "required because it captures the following types: " . to_owned ( ) ;
2655
+ for ty in bound_tys. skip_binder ( ) {
2656
+ write ! ( msg, "`{}`, " , ty) . unwrap ( ) ;
2705
2657
}
2706
- ty:: Closure ( def_id, _) => err. span_note (
2707
- self . tcx . def_span ( def_id) ,
2708
- & format ! ( "required because it's used within this closure" ) ,
2709
- ) ,
2710
- _ => err. note ( & msg) ,
2711
- } ;
2712
- }
2658
+ err. note ( msg. trim_end_matches ( ", " ) )
2659
+ }
2660
+ ty:: Generator ( def_id, _, _) => {
2661
+ let sp = self . tcx . def_span ( def_id) ;
2662
+
2663
+ // Special-case this to say "async block" instead of `[static generator]`.
2664
+ let kind = tcx. generator_kind ( def_id) . unwrap ( ) ;
2665
+ err. span_note (
2666
+ sp,
2667
+ & format ! ( "required because it's used within this {}" , kind) ,
2668
+ )
2669
+ }
2670
+ ty:: Closure ( def_id, _) => err. span_note (
2671
+ self . tcx . def_span ( def_id) ,
2672
+ & format ! ( "required because it's used within this closure" ) ,
2673
+ ) ,
2674
+ _ => err. note ( & msg) ,
2675
+ } ;
2713
2676
}
2714
2677
2715
2678
obligated_types. push ( ty) ;
0 commit comments