@@ -38,6 +38,7 @@ use rustc_span::def_id::LocalDefId;
3838use rustc_span:: symbol:: { kw, sym, Ident , Symbol } ;
3939use rustc_span:: { BytePos , DesugaringKind , ExpnKind , MacroKind , Span , DUMMY_SP } ;
4040use rustc_target:: spec:: abi;
41+ use std:: assert_matches:: debug_assert_matches;
4142use std:: borrow:: Cow ;
4243use std:: iter;
4344
@@ -4219,30 +4220,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
42194220 } ;
42204221
42214222 let origin = TypeVariableOrigin { kind : TypeVariableOriginKind :: TypeInference , span } ;
4222- let trait_def_id = proj. trait_def_id ( self . tcx ) ;
42234223 // Make `Self` be equivalent to the type of the call chain
42244224 // expression we're looking at now, so that we can tell what
42254225 // for example `Iterator::Item` is at this point in the chain.
4226- let args = GenericArgs :: for_item ( self . tcx , trait_def_id, |param, _| {
4227- match param. kind {
4228- ty:: GenericParamDefKind :: Type { .. } => {
4229- if param. index == 0 {
4230- return prev_ty. into ( ) ;
4231- }
4232- }
4233- ty:: GenericParamDefKind :: Lifetime | ty:: GenericParamDefKind :: Const { .. } => { }
4226+ let args = GenericArgs :: for_item ( self . tcx , proj. def_id , |param, _| {
4227+ if param. index == 0 {
4228+ debug_assert_matches ! ( param. kind, ty:: GenericParamDefKind :: Type { .. } ) ;
4229+ return prev_ty. into ( ) ;
42344230 }
42354231 self . var_for_def ( span, param)
42364232 } ) ;
42374233 // This will hold the resolved type of the associated type, if the
42384234 // current expression implements the trait that associated type is
42394235 // in. For example, this would be what `Iterator::Item` is here.
4240- let ty_var = self . infcx . next_ty_var ( origin) ;
4236+ let ty = self . infcx . next_ty_var ( origin) ;
42414237 // This corresponds to `<ExprTy as Iterator>::Item = _`.
42424238 let projection = ty:: Binder :: dummy ( ty:: PredicateKind :: Clause (
42434239 ty:: ClauseKind :: Projection ( ty:: ProjectionPredicate {
42444240 projection_ty : ty:: AliasTy :: new ( self . tcx , proj. def_id , args) ,
4245- term : ty_var . into ( ) ,
4241+ term : ty . into ( ) ,
42464242 } ) ,
42474243 ) ) ;
42484244 let body_def_id = self . tcx . hir ( ) . enclosing_body_owner ( body_id) ;
@@ -4254,14 +4250,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
42544250 param_env,
42554251 projection,
42564252 ) ) ;
4257- if ocx. select_where_possible ( ) . is_empty ( ) {
4258- // `ty_var` now holds the type that `Item` is for `ExprTy`.
4259- let ty_var = self . resolve_vars_if_possible ( ty_var) ;
4260- assocs_in_this_method. push ( Some ( ( span, ( proj. def_id , ty_var) ) ) ) ;
4253+ if ocx. select_where_possible ( ) . is_empty ( )
4254+ && let ty = self . resolve_vars_if_possible ( ty)
4255+ && !ty. is_ty_var ( )
4256+ {
4257+ assocs_in_this_method. push ( Some ( ( span, ( proj. def_id , ty) ) ) ) ;
42614258 } else {
42624259 // `<ExprTy as Iterator>` didn't select, so likely we've
42634260 // reached the end of the iterator chain, like the originating
4264- // `Vec<_>`.
4261+ // `Vec<_>` or the `ty` couldn't be determined .
42654262 // Keep the space consistent for later zipping.
42664263 assocs_in_this_method. push ( None ) ;
42674264 }
0 commit comments