@@ -24,9 +24,11 @@ use rustc::ty::{self, Ty, TyCtxt};
24
24
use rustc:: ty:: subst:: Substs ;
25
25
use rustc:: lint;
26
26
use rustc_errors:: DiagnosticBuilder ;
27
+ use rustc:: util:: common:: ErrorReported ;
27
28
28
29
use rustc:: hir:: def:: * ;
29
- use rustc:: hir:: intravisit:: { self , Visitor , FnKind , NestedVisitorMap } ;
30
+ use rustc:: hir:: def_id:: DefId ;
31
+ use rustc:: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
30
32
use rustc:: hir:: { self , Pat , PatKind } ;
31
33
32
34
use rustc_back:: slice;
@@ -42,19 +44,10 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
42
44
NestedVisitorMap :: OnlyBodies ( & self . tcx . hir )
43
45
}
44
46
45
- fn visit_fn ( & mut self , fk : FnKind < ' tcx > , fd : & ' tcx hir:: FnDecl ,
46
- b : hir:: BodyId , s : Span , id : ast:: NodeId ) {
47
- intravisit:: walk_fn ( self , fk, fd, b, s, id) ;
48
-
49
- let def_id = self . tcx . hir . local_def_id ( id) ;
50
-
51
- MatchVisitor {
52
- tcx : self . tcx ,
53
- tables : self . tcx . body_tables ( b) ,
54
- region_scope_tree : & self . tcx . region_scope_tree ( def_id) ,
55
- param_env : self . tcx . param_env ( def_id) ,
56
- identity_substs : Substs :: identity_for_item ( self . tcx , def_id) ,
57
- } . visit_body ( self . tcx . hir . body ( b) ) ;
47
+ fn visit_body ( & mut self , body : & ' tcx hir:: Body ) {
48
+ intravisit:: walk_body ( self , body) ;
49
+ let def_id = self . tcx . hir . body_owner_def_id ( body. id ( ) ) ;
50
+ let _ = self . tcx . check_match ( def_id) ;
58
51
}
59
52
}
60
53
@@ -63,6 +56,27 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
63
56
tcx. sess . abort_if_errors ( ) ;
64
57
}
65
58
59
+ pub ( crate ) fn check_match < ' a , ' tcx > (
60
+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
61
+ def_id : DefId ,
62
+ ) -> Result < ( ) , ErrorReported > {
63
+ let body_id = if let Some ( id) = tcx. hir . as_local_node_id ( def_id) {
64
+ tcx. hir . body_owned_by ( id)
65
+ } else {
66
+ return Ok ( ( ) ) ;
67
+ } ;
68
+
69
+ tcx. sess . track_errors ( || {
70
+ MatchVisitor {
71
+ tcx,
72
+ tables : tcx. body_tables ( body_id) ,
73
+ region_scope_tree : & tcx. region_scope_tree ( def_id) ,
74
+ param_env : tcx. param_env ( def_id) ,
75
+ identity_substs : Substs :: identity_for_item ( tcx, def_id) ,
76
+ } . visit_body ( tcx. hir . body ( body_id) ) ;
77
+ } )
78
+ }
79
+
66
80
fn create_e0004 < ' a > ( sess : & ' a Session , sp : Span , error_message : String ) -> DiagnosticBuilder < ' a > {
67
81
struct_span_err ! ( sess, sp, E0004 , "{}" , & error_message)
68
82
}
0 commit comments