@@ -24,9 +24,11 @@ use rustc::ty::{self, Ty, TyCtxt};
2424use rustc:: ty:: subst:: Substs ;
2525use rustc:: lint;
2626use rustc_errors:: DiagnosticBuilder ;
27+ use rustc:: util:: common:: ErrorReported ;
2728
2829use 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 } ;
3032use rustc:: hir:: { self , Pat , PatKind } ;
3133
3234use rustc_back:: slice;
@@ -42,19 +44,10 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
4244 NestedVisitorMap :: OnlyBodies ( & self . tcx . hir )
4345 }
4446
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) ;
5851 }
5952}
6053
@@ -63,6 +56,27 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
6356 tcx. sess . abort_if_errors ( ) ;
6457}
6558
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+
6680fn create_e0004 < ' a > ( sess : & ' a Session , sp : Span , error_message : String ) -> DiagnosticBuilder < ' a > {
6781 struct_span_err ! ( sess, sp, E0004 , "{}" , & error_message)
6882}
0 commit comments