@@ -399,37 +399,25 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
399399 // For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`.
400400 //
401401 // First we build the defaulted substitution.
402- let mut defaulted_params = Vec :: new ( ) ;
403402 let substs = ty:: subst:: Substs :: for_item ( fcx. tcx , def_id, |def, _| {
404403 // All regions are identity.
405404 fcx. tcx . mk_region ( ty:: ReEarlyBound ( def. to_early_bound_region_data ( ) ) )
406405 } , |def, _| {
407406 if !is_our_default ( def) {
408- // Identity substitution.
409- fcx. tcx . mk_param_from_def ( def )
407+ // We don't want to use non-defaulted params in a substitution, mark as err .
408+ fcx. tcx . types . err
410409 } else {
411410 // Substitute with default.
412- defaulted_params. push ( def. index ) ;
413411 fcx. tcx . type_of ( def. def_id )
414412 }
415413 } ) ;
416- let defaulted_params = & defaulted_params;
417414 // Now we build the substituted predicates.
418415 for & pred in predicates. predicates . iter ( ) {
419- struct HasNonDefaulted < ' a > { defaulted_params : & ' a Vec < u32 > }
420- impl < ' tcx , ' a > ty:: fold:: TypeVisitor < ' tcx > for HasNonDefaulted < ' a > {
421- fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
422- match t. sty {
423- ty:: TyParam ( p) => !self . defaulted_params . contains ( & p. idx ) ,
424- _ => t. super_visit_with ( self )
425- }
426- }
427- }
416+ let substituted_pred = pred. subst ( fcx. tcx , substs) ;
428417 // If there is a non-defaulted param in the predicate, don't check it.
429- if pred . visit_with ( & mut HasNonDefaulted { defaulted_params } ) {
418+ if substituted_pred . references_error ( ) {
430419 continue ;
431420 }
432- let substituted_pred = pred. subst ( fcx. tcx , substs) ;
433421 // In trait defs, don't check `Self: Sized` when `Self` is the default.
434422 if let ty:: Predicate :: Trait ( trait_pred) = substituted_pred {
435423 // `skip_binder()` is ok, we're only inspecting for `has_self_ty()`.
0 commit comments