@@ -22,8 +22,8 @@ use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
22
22
use rustc_lint:: builtin:: SELF_CONSTRUCTOR_FROM_OUTER_ITEM ;
23
23
use rustc_middle:: ty:: adjustment:: { Adjust , Adjustment , AutoBorrow , AutoBorrowMutability } ;
24
24
use rustc_middle:: ty:: {
25
- self , AdtKind , CanonicalUserType , GenericArgKind , GenericArgsRef , GenericParamDefKind ,
26
- IsIdentity , Ty , TyCtxt , TypeFoldable , TypeVisitable , TypeVisitableExt , UserArgs , UserSelfTy ,
25
+ self , AdtKind , CanonicalUserType , GenericArgsRef , GenericParamDefKind , IsIdentity , Ty , TyCtxt ,
26
+ TypeFoldable , TypeVisitable , TypeVisitableExt , UserArgs , UserSelfTy ,
27
27
} ;
28
28
use rustc_middle:: { bug, span_bug} ;
29
29
use rustc_session:: lint;
@@ -573,7 +573,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
573
573
/// Registers an obligation for checking later, during regionck, that `arg` is well-formed.
574
574
pub ( crate ) fn register_wf_obligation (
575
575
& self ,
576
- arg : ty:: GenericArg < ' tcx > ,
576
+ term : ty:: Term < ' tcx > ,
577
577
span : Span ,
578
578
code : traits:: ObligationCauseCode < ' tcx > ,
579
579
) {
@@ -583,16 +583,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
583
583
self . tcx ,
584
584
cause,
585
585
self . param_env ,
586
- ty:: Binder :: dummy ( ty :: PredicateKind :: Clause ( ty :: ClauseKind :: WellFormed ( arg ) ) ) ,
586
+ ty:: ClauseKind :: WellFormed ( term ) ,
587
587
) ) ;
588
588
}
589
589
590
590
/// Registers obligations that all `args` are well-formed.
591
591
pub ( crate ) fn add_wf_bounds ( & self , args : GenericArgsRef < ' tcx > , span : Span ) {
592
- for arg in args. iter ( ) . filter ( |arg| {
593
- matches ! ( arg. unpack( ) , GenericArgKind :: Type ( ..) | GenericArgKind :: Const ( ..) )
594
- } ) {
595
- self . register_wf_obligation ( arg, span, ObligationCauseCode :: WellFormed ( None ) ) ;
592
+ for term in args. iter ( ) . filter_map ( ty:: GenericArg :: as_term) {
593
+ self . register_wf_obligation ( term, span, ObligationCauseCode :: WellFormed ( None ) ) ;
596
594
}
597
595
}
598
596
@@ -1320,27 +1318,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1320
1318
infer_args : bool ,
1321
1319
) -> ty:: GenericArg < ' tcx > {
1322
1320
let tcx = self . fcx . tcx ( ) ;
1323
- match param. kind {
1324
- GenericParamDefKind :: Lifetime => self
1325
- . fcx
1326
- . re_infer (
1327
- self . span ,
1328
- rustc_hir_analysis:: hir_ty_lowering:: RegionInferReason :: Param ( param) ,
1329
- )
1330
- . into ( ) ,
1331
- GenericParamDefKind :: Type { .. } | GenericParamDefKind :: Const { .. } => {
1332
- if !infer_args && let Some ( default) = param. default_value ( tcx) {
1333
- // If we have a default, then it doesn't matter that we're not inferring
1334
- // the type/const arguments: We provide the default where any is missing.
1335
- return default. instantiate ( tcx, preceding_args) ;
1336
- }
1337
- // If no type/const arguments were provided, we have to infer them.
1338
- // This case also occurs as a result of some malformed input, e.g.,
1339
- // a lifetime argument being given instead of a type/const parameter.
1340
- // Using inference instead of `Error` gives better error messages.
1341
- self . fcx . var_for_def ( self . span , param)
1342
- }
1321
+ if !infer_args && let Some ( default) = param. default_value ( tcx) {
1322
+ // If we have a default, then it doesn't matter that we're not inferring
1323
+ // the type/const arguments: We provide the default where any is missing.
1324
+ return default. instantiate ( tcx, preceding_args) ;
1343
1325
}
1326
+ // If no type/const arguments were provided, we have to infer them.
1327
+ // This case also occurs as a result of some malformed input, e.g.,
1328
+ // a lifetime argument being given instead of a type/const parameter.
1329
+ // Using inference instead of `Error` gives better error messages.
1330
+ self . fcx . var_for_def ( self . span , param)
1344
1331
}
1345
1332
}
1346
1333
0 commit comments