@@ -5,7 +5,7 @@ use super::{
5
5
6
6
use crate :: autoderef:: Autoderef ;
7
7
use crate :: infer:: InferCtxt ;
8
- use crate :: traits:: normalize_projection_type ;
8
+ use crate :: traits:: normalize_to ;
9
9
10
10
use rustc_data_structures:: fx:: FxHashSet ;
11
11
use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -2706,55 +2706,43 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
2706
2706
let future_trait = self . tcx . require_lang_item ( LangItem :: Future , None ) ;
2707
2707
2708
2708
let self_ty = self . resolve_vars_if_possible ( trait_pred. self_ty ( ) ) ;
2709
-
2710
- // Do not check on infer_types to avoid panic in evaluate_obligation.
2711
- if self_ty. has_infer_types ( ) {
2712
- return ;
2713
- }
2714
- let self_ty = self . tcx . erase_regions ( self_ty) ;
2715
-
2716
2709
let impls_future = self . type_implements_trait (
2717
2710
future_trait,
2718
- self_ty . skip_binder ( ) ,
2711
+ self . tcx . erase_late_bound_regions ( self_ty ) ,
2719
2712
ty:: List :: empty ( ) ,
2720
2713
obligation. param_env ,
2721
2714
) ;
2715
+ if !impls_future. must_apply_modulo_regions ( ) {
2716
+ return ;
2717
+ }
2722
2718
2723
2719
let item_def_id = self . tcx . associated_item_def_ids ( future_trait) [ 0 ] ;
2724
2720
// `<T as Future>::Output`
2725
- let projection_ty = ty:: ProjectionTy {
2726
- // `T`
2727
- substs : self . tcx . mk_substs_trait (
2728
- trait_pred. self_ty ( ) . skip_binder ( ) ,
2729
- & self . fresh_substs_for_item ( span, item_def_id) [ 1 ..] ,
2730
- ) ,
2731
- // `Future::Output`
2732
- item_def_id,
2733
- } ;
2734
-
2735
- let mut selcx = SelectionContext :: new ( self ) ;
2736
-
2737
- let mut obligations = vec ! [ ] ;
2738
- let normalized_ty = normalize_projection_type (
2739
- & mut selcx,
2721
+ let projection_ty = trait_pred. map_bound ( |trait_pred| {
2722
+ self . tcx . mk_projection (
2723
+ item_def_id,
2724
+ // Future::Output has no substs
2725
+ self . tcx . mk_substs_trait ( trait_pred. self_ty ( ) , & [ ] ) ,
2726
+ )
2727
+ } ) ;
2728
+ let projection_ty = normalize_to (
2729
+ & mut SelectionContext :: new ( self ) ,
2740
2730
obligation. param_env ,
2741
- projection_ty,
2742
2731
obligation. cause . clone ( ) ,
2743
- 0 ,
2744
- & mut obligations ,
2732
+ projection_ty ,
2733
+ & mut vec ! [ ] ,
2745
2734
) ;
2746
2735
2747
2736
debug ! (
2748
2737
"suggest_await_before_try: normalized_projection_type {:?}" ,
2749
- self . resolve_vars_if_possible( normalized_ty )
2738
+ self . resolve_vars_if_possible( projection_ty )
2750
2739
) ;
2751
2740
let try_obligation = self . mk_trait_obligation_with_new_self_ty (
2752
2741
obligation. param_env ,
2753
- trait_pred. map_bound ( |trait_pred| ( trait_pred, normalized_ty . ty ( ) . unwrap ( ) ) ) ,
2742
+ trait_pred. map_bound ( |trait_pred| ( trait_pred, projection_ty . skip_binder ( ) ) ) ,
2754
2743
) ;
2755
2744
debug ! ( "suggest_await_before_try: try_trait_obligation {:?}" , try_obligation) ;
2756
2745
if self . predicate_may_hold ( & try_obligation)
2757
- && impls_future. must_apply_modulo_regions ( )
2758
2746
&& let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
2759
2747
&& snippet. ends_with ( '?' )
2760
2748
{
0 commit comments