@@ -5,7 +5,7 @@ use super::{
55
66use crate :: autoderef:: Autoderef ;
77use crate :: infer:: InferCtxt ;
8- use crate :: traits:: normalize_projection_type ;
8+ use crate :: traits:: normalize_to ;
99
1010use rustc_data_structures:: fx:: FxHashSet ;
1111use rustc_data_structures:: stack:: ensure_sufficient_stack;
@@ -2706,55 +2706,43 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
27062706 let future_trait = self . tcx . require_lang_item ( LangItem :: Future , None ) ;
27072707
27082708 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-
27162709 let impls_future = self . type_implements_trait (
27172710 future_trait,
2718- self_ty . skip_binder ( ) ,
2711+ self . tcx . erase_late_bound_regions ( self_ty ) ,
27192712 ty:: List :: empty ( ) ,
27202713 obligation. param_env ,
27212714 ) ;
2715+ if !impls_future. must_apply_modulo_regions ( ) {
2716+ return ;
2717+ }
27222718
27232719 let item_def_id = self . tcx . associated_item_def_ids ( future_trait) [ 0 ] ;
27242720 // `<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 ) ,
27402730 obligation. param_env ,
2741- projection_ty,
27422731 obligation. cause . clone ( ) ,
2743- 0 ,
2744- & mut obligations ,
2732+ projection_ty ,
2733+ & mut vec ! [ ] ,
27452734 ) ;
27462735
27472736 debug ! (
27482737 "suggest_await_before_try: normalized_projection_type {:?}" ,
2749- self . resolve_vars_if_possible( normalized_ty )
2738+ self . resolve_vars_if_possible( projection_ty )
27502739 ) ;
27512740 let try_obligation = self . mk_trait_obligation_with_new_self_ty (
27522741 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 ( ) ) ) ,
27542743 ) ;
27552744 debug ! ( "suggest_await_before_try: try_trait_obligation {:?}" , try_obligation) ;
27562745 if self . predicate_may_hold ( & try_obligation)
2757- && impls_future. must_apply_modulo_regions ( )
27582746 && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
27592747 && snippet. ends_with ( '?' )
27602748 {
0 commit comments