@@ -164,7 +164,7 @@ pub fn clause_obligations<'tcx>(
164
164
wf. compute ( ty. into ( ) ) ;
165
165
}
166
166
ty:: ClauseKind :: Projection ( t) => {
167
- wf. compute_projection ( t. projection_ty ) ;
167
+ wf. compute_alias ( t. projection_ty ) ;
168
168
wf. compute ( match t. term . unpack ( ) {
169
169
ty:: TermKind :: Ty ( ty) => ty. into ( ) ,
170
170
ty:: TermKind :: Const ( c) => c. into ( ) ,
@@ -396,36 +396,17 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
396
396
self . out . extend ( obligations) ;
397
397
}
398
398
399
- self . out . extend (
400
- trait_ref
401
- . args
402
- . iter ( )
403
- . enumerate ( )
404
- . filter ( |( _, arg) | {
405
- matches ! ( arg. unpack( ) , GenericArgKind :: Type ( ..) | GenericArgKind :: Const ( ..) )
406
- } )
407
- . filter ( |( _, arg) | !arg. has_escaping_bound_vars ( ) )
408
- . map ( |( i, arg) | {
409
- let mut cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
410
- // The first arg is the self ty - use the correct span for it.
411
- if i == 0 {
412
- if let Some ( hir:: ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) ) =
413
- item. map ( |i| & i. kind )
414
- {
415
- cause. span = self_ty. span ;
416
- }
417
- }
418
- traits:: Obligation :: with_depth (
419
- tcx,
420
- cause,
421
- depth,
422
- param_env,
423
- ty:: Binder :: dummy ( ty:: PredicateKind :: Clause ( ty:: ClauseKind :: WellFormed (
424
- arg,
425
- ) ) ) ,
426
- )
427
- } ) ,
428
- ) ;
399
+ if let Some ( hir:: ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) ) = item. map ( |i| & i. kind ) {
400
+ // FIXME: Could generalize this hack.
401
+ let span = std:: mem:: replace ( & mut self . span , self_ty. span ) ;
402
+ // make sure that the trait ref is WF.
403
+ trait_ref. args [ 0 ] . visit_with ( self ) ;
404
+ self . span = span;
405
+ ( & trait_ref. args [ 1 ..] ) . visit_with ( self ) ;
406
+ } else {
407
+ // make sure that the trait ref is WF.
408
+ trait_ref. visit_with ( self ) ;
409
+ }
429
410
}
430
411
431
412
// Compute the obligations that are required for `trait_ref` to be WF,
@@ -436,9 +417,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
436
417
}
437
418
}
438
419
439
- /// Pushes the obligations required for `trait_ref::Item` to be WF
420
+ /// Pushes the obligations required for an alias (except inherent) to be WF
440
421
/// into `self.out`.
441
- fn compute_projection ( & mut self , data : ty:: AliasTy < ' tcx > ) {
422
+ fn compute_alias ( & mut self , data : ty:: AliasTy < ' tcx > ) {
442
423
// A projection is well-formed if
443
424
//
444
425
// (a) its predicates hold (*)
@@ -463,9 +444,13 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
463
444
let obligations = self . nominal_obligations ( data. def_id , data. args ) ;
464
445
self . out . extend ( obligations) ;
465
446
466
- self . compute_projection_args ( data. args ) ;
447
+ // Make sure that projection args are WF.
448
+ data. visit_with ( self ) ;
467
449
}
468
450
451
+ /// Pushes the obligations required for an inherent alias to be WF
452
+ /// into `self.out`.
453
+ // FIXME(inherent_associated_types): Merge this function with `fn compute_alias`.
469
454
fn compute_inherent_projection ( & mut self , data : ty:: AliasTy < ' tcx > ) {
470
455
// An inherent projection is well-formed if
471
456
//
@@ -490,33 +475,8 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
490
475
self . out . extend ( obligations) ;
491
476
}
492
477
493
- self . compute_projection_args ( data. args ) ;
494
- }
495
-
496
- fn compute_projection_args ( & mut self , args : GenericArgsRef < ' tcx > ) {
497
- let tcx = self . tcx ( ) ;
498
- let cause = self . cause ( traits:: WellFormed ( None ) ) ;
499
- let param_env = self . param_env ;
500
- let depth = self . recursion_depth ;
501
-
502
- self . out . extend (
503
- args. iter ( )
504
- . filter ( |arg| {
505
- matches ! ( arg. unpack( ) , GenericArgKind :: Type ( ..) | GenericArgKind :: Const ( ..) )
506
- } )
507
- . filter ( |arg| !arg. has_escaping_bound_vars ( ) )
508
- . map ( |arg| {
509
- traits:: Obligation :: with_depth (
510
- tcx,
511
- cause. clone ( ) ,
512
- depth,
513
- param_env,
514
- ty:: Binder :: dummy ( ty:: PredicateKind :: Clause ( ty:: ClauseKind :: WellFormed (
515
- arg,
516
- ) ) ) ,
517
- )
518
- } ) ,
519
- ) ;
478
+ // Make sure that projection args are WF.
479
+ data. visit_with ( self ) ;
520
480
}
521
481
522
482
fn require_sized ( & mut self , subty : Ty < ' tcx > , cause : traits:: ObligationCauseCode < ' tcx > ) {
@@ -688,8 +648,8 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
688
648
// Simple cases that are WF if their type args are WF.
689
649
}
690
650
691
- ty:: Alias ( ty:: Projection , data) => {
692
- self . compute_projection ( data) ;
651
+ ty:: Alias ( ty:: Projection | ty :: Opaque | ty :: Weak , data) => {
652
+ self . compute_alias ( data) ;
693
653
return ; // Subtree handled by compute_projection.
694
654
}
695
655
ty:: Alias ( ty:: Inherent , data) => {
@@ -791,21 +751,6 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
791
751
// types appearing in the fn signature.
792
752
}
793
753
794
- ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) => {
795
- // All of the requirements on type parameters
796
- // have already been checked for `impl Trait` in
797
- // return position. We do need to check type-alias-impl-trait though.
798
- if self . tcx ( ) . is_type_alias_impl_trait ( def_id) {
799
- let obligations = self . nominal_obligations ( def_id, args) ;
800
- self . out . extend ( obligations) ;
801
- }
802
- }
803
-
804
- ty:: Alias ( ty:: Weak , ty:: AliasTy { def_id, args, .. } ) => {
805
- let obligations = self . nominal_obligations ( def_id, args) ;
806
- self . out . extend ( obligations) ;
807
- }
808
-
809
754
ty:: Dynamic ( data, r, _) => {
810
755
// WfObject
811
756
//
0 commit comments