@@ -728,20 +728,36 @@ fn check_where_clauses<'tcx, 'fcx>(
728728 //
729729 // Here, the default `Vec<[u32]>` is not WF because `[u32]: Sized` does not hold.
730730 for param in & generics. params {
731- if let GenericParamDefKind :: Type { .. } = param. kind {
732- if is_our_default ( & param) {
733- let ty = fcx. tcx . type_of ( param. def_id ) ;
734- // Ignore dependent defaults -- that is, where the default of one type
735- // parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
736- // be sure if it will error or not as user might always specify the other.
737- if !ty. needs_subst ( ) {
731+ match param. kind {
732+ GenericParamDefKind :: Type { .. } => {
733+ if is_our_default ( & param) {
734+ let ty = fcx. tcx . type_of ( param. def_id ) ;
735+ // Ignore dependent defaults -- that is, where the default of one type
736+ // parameter includes another (e.g., `<T, U = T>`). In those cases, we can't
737+ // be sure if it will error or not as user might always specify the other.
738+ if !ty. needs_subst ( ) {
739+ fcx. register_wf_obligation (
740+ ty. into ( ) ,
741+ fcx. tcx . def_span ( param. def_id ) ,
742+ ObligationCauseCode :: MiscObligation ,
743+ ) ;
744+ }
745+ }
746+ }
747+ GenericParamDefKind :: Const { .. } => {
748+ // FIXME(const_generics_defaults): Figure out if this
749+ // is the behavior we want, see the comment further below.
750+ if is_our_default ( & param) {
751+ let default_ct = tcx. const_param_default ( param. def_id ) ;
738752 fcx. register_wf_obligation (
739- ty . into ( ) ,
753+ default_ct . into ( ) ,
740754 fcx. tcx . def_span ( param. def_id ) ,
741755 ObligationCauseCode :: MiscObligation ,
742756 ) ;
743757 }
744758 }
759+ // Doesn't have defaults.
760+ GenericParamDefKind :: Lifetime => { }
745761 }
746762 }
747763
@@ -774,14 +790,25 @@ fn check_where_clauses<'tcx, 'fcx>(
774790 fcx. tcx . mk_param_from_def ( param)
775791 }
776792 GenericParamDefKind :: Const { .. } => {
793+ // FIXME(const_generics_defaults): I(@lcnr) feel like always
794+ // using the const parameter is the right choice here, even
795+ // if it needs substs.
796+ //
797+ // Before stabilizing this we probably want to get some tests
798+ // where this makes a difference and figure out what's the exact
799+ // behavior we want here.
800+
801+ // If the param has a default, ...
777802 if is_our_default ( param) {
778803 let default_ct = tcx. const_param_default ( param. def_id ) ;
779- // Const params currently have to be concrete .
780- assert ! ( ! default_ct. needs_subst( ) ) ;
781- default_ct . into ( )
782- } else {
783- fcx . tcx . mk_param_from_def ( param )
804+ // ... and it's not a dependent default, .. .
805+ if ! default_ct. needs_subst ( ) {
806+ // ... then substitute it with the default.
807+ return default_ct . into ( ) ;
808+ }
784809 }
810+
811+ fcx. tcx . mk_param_from_def ( param)
785812 }
786813 }
787814 } ) ;
0 commit comments