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