@@ -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;
@@ -2704,55 +2704,43 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
27042704 let future_trait = self . tcx . require_lang_item ( LangItem :: Future , None ) ;
27052705
27062706 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-
27142707 let impls_future = self . type_implements_trait (
27152708 future_trait,
2716- self_ty . skip_binder ( ) ,
2709+ self . tcx . erase_late_bound_regions ( self_ty ) ,
27172710 ty:: List :: empty ( ) ,
27182711 obligation. param_env ,
27192712 ) ;
2713+ if !impls_future. must_apply_modulo_regions ( ) {
2714+ return ;
2715+ }
27202716
27212717 let item_def_id = self . tcx . associated_item_def_ids ( future_trait) [ 0 ] ;
27222718 // `<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 ) ,
27382728 obligation. param_env ,
2739- projection_ty,
27402729 obligation. cause . clone ( ) ,
2741- 0 ,
2742- & mut obligations ,
2730+ projection_ty ,
2731+ & mut vec ! [ ] ,
27432732 ) ;
27442733
27452734 debug ! (
27462735 "suggest_await_before_try: normalized_projection_type {:?}" ,
2747- self . resolve_vars_if_possible( normalized_ty )
2736+ self . resolve_vars_if_possible( projection_ty )
27482737 ) ;
27492738 let try_obligation = self . mk_trait_obligation_with_new_self_ty (
27502739 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 ( ) ) ) ,
27522741 ) ;
27532742 debug ! ( "suggest_await_before_try: try_trait_obligation {:?}" , try_obligation) ;
27542743 if self . predicate_may_hold ( & try_obligation)
2755- && impls_future. must_apply_modulo_regions ( )
27562744 && let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( span)
27572745 && snippet. ends_with ( '?' )
27582746 {
0 commit comments