@@ -591,12 +591,23 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
591
591
}
592
592
593
593
fn check_expr_pat_type ( & mut self , id : ast:: NodeId , span : Span ) -> bool {
594
+ self . span = span;
594
595
if let Some ( ty) = self . tables . node_id_to_type_opt ( id) {
595
- self . span = span;
596
- ty. visit_with ( self )
597
- } else {
598
- false
596
+ if ty. visit_with ( self ) {
597
+ return true ;
598
+ }
599
+ }
600
+ if self . tables . node_substs ( id) . visit_with ( self ) {
601
+ return true ;
599
602
}
603
+ if let Some ( adjustments) = self . tables . adjustments . get ( & id) {
604
+ for adjustment in adjustments {
605
+ if adjustment. target . visit_with ( self ) {
606
+ return true ;
607
+ }
608
+ }
609
+ }
610
+ false
600
611
}
601
612
602
613
fn check_item ( & mut self , item_id : ast:: NodeId ) -> & mut Self {
@@ -660,11 +671,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
660
671
}
661
672
hir:: ExprMethodCall ( name, ..) => {
662
673
// Method calls have to be checked specially.
663
- if let Some ( method) = self . tables . method_map . get ( & ty:: MethodCall :: expr ( expr. id ) ) {
664
- self . span = name. span ;
665
- if method. ty . visit_with ( self ) || method. substs . visit_with ( self ) {
666
- return ;
667
- }
674
+ let def_id = self . tables . type_dependent_defs [ & expr. id ] . def_id ( ) ;
675
+ self . span = name. span ;
676
+ if self . tcx . type_of ( def_id) . visit_with ( self ) {
677
+ return ;
668
678
}
669
679
}
670
680
_ => { }
@@ -673,6 +683,24 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
673
683
intravisit:: walk_expr ( self , expr) ;
674
684
}
675
685
686
+ fn visit_qpath ( & mut self , qpath : & ' tcx hir:: QPath , id : ast:: NodeId , span : Span ) {
687
+ // Inherent associated constants don't have self type in substs,
688
+ // we have to check it additionally.
689
+ if let hir:: QPath :: TypeRelative ( ..) = * qpath {
690
+ if let Some ( def) = self . tables . type_dependent_defs . get ( & id) . cloned ( ) {
691
+ if let Some ( assoc_item) = self . tcx . opt_associated_item ( def. def_id ( ) ) {
692
+ if let ty:: ImplContainer ( impl_def_id) = assoc_item. container {
693
+ if self . tcx . type_of ( impl_def_id) . visit_with ( self ) {
694
+ return ;
695
+ }
696
+ }
697
+ }
698
+ }
699
+ }
700
+
701
+ intravisit:: walk_qpath ( self , qpath, id, span) ;
702
+ }
703
+
676
704
// Check types of patterns
677
705
fn visit_pat ( & mut self , pattern : & ' tcx hir:: Pat ) {
678
706
if self . check_expr_pat_type ( pattern. id , pattern. span ) {
@@ -769,25 +797,11 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
769
797
self . tcx . sess . span_err ( self . span , & msg) ;
770
798
return true ;
771
799
}
772
- if let ty:: TyFnDef ( ..) = ty. sty {
773
- // Inherent static methods don't have self type in substs,
774
- // we have to check it additionally.
775
- let mut impl_def_id = None ;
776
- if let Some ( node_id) = self . tcx . hir . as_local_node_id ( def_id) {
777
- if let hir:: map:: NodeImplItem ( ..) = self . tcx . hir . get ( node_id) {
778
- impl_def_id = Some ( self . tcx . hir . get_parent_did ( node_id) ) ;
779
- }
780
- } else if let Some ( Def :: Method ( ..) ) = self . tcx . describe_def ( def_id) {
781
- let candidate_impl_def_id = self . tcx . parent_def_id ( def_id)
782
- . expect ( "no parent for method def_id" ) ;
783
- // `is_none` means it's an impl, not a trait
784
- if self . tcx . describe_def ( candidate_impl_def_id) . is_none ( ) {
785
- impl_def_id = Some ( candidate_impl_def_id)
786
- }
787
- }
788
- if let Some ( impl_def_id) = impl_def_id {
789
- let self_ty = self . tcx . type_of ( impl_def_id) ;
790
- if self_ty. visit_with ( self ) {
800
+ // Inherent static methods don't have self type in substs,
801
+ // we have to check it additionally.
802
+ if let Some ( assoc_item) = self . tcx . opt_associated_item ( def_id) {
803
+ if let ty:: ImplContainer ( impl_def_id) = assoc_item. container {
804
+ if self . tcx . type_of ( impl_def_id) . visit_with ( self ) {
791
805
return true ;
792
806
}
793
807
}
@@ -829,7 +843,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
829
843
self . tcx . sess . span_err ( self . span , & msg) ;
830
844
return true ;
831
845
}
832
- // Skip `Self` to avoid infinite recursion
846
+ // `Self` here is the same `TyAnon`, so skip it to avoid infinite recursion
833
847
for subst in trait_ref. substs . iter ( ) . skip ( 1 ) {
834
848
if subst. visit_with ( self ) {
835
849
return true ;
0 commit comments