@@ -24,6 +24,7 @@ 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:: * ;
2930use rustc:: hir:: def_id:: DefId ;
@@ -47,17 +48,14 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
4748 b : hir:: BodyId , s : Span , id : ast:: NodeId ) {
4849 intravisit:: walk_fn ( self , fk, fd, b, s, id) ;
4950
50- let def_id = self . tcx . hir . local_def_id ( id) ;
51-
52- check_body ( self . tcx , def_id, b) ;
51+ check_body ( self . tcx , b) ;
5352 }
5453
5554 fn visit_item ( & mut self , item : & ' tcx hir:: Item ) {
5655 intravisit:: walk_item ( self , item) ;
5756 match item. node {
5857 hir:: ItemStatic ( .., body_id) | hir:: ItemConst ( .., body_id) => {
59- let def_id = self . tcx . hir . local_def_id ( item. id ) ;
60- check_body ( self . tcx , def_id, body_id) ;
58+ check_body ( self . tcx , body_id) ;
6159 }
6260 _ => ( ) ,
6361 }
@@ -66,40 +64,53 @@ impl<'a, 'tcx> Visitor<'tcx> for OuterVisitor<'a, 'tcx> {
6664 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem ) {
6765 intravisit:: walk_impl_item ( self , ii) ;
6866 if let hir:: ImplItemKind :: Const ( _, body_id) = ii. node {
69- let def_id = self . tcx . hir . local_def_id ( ii. id ) ;
70- check_body ( self . tcx , def_id, body_id) ;
67+ check_body ( self . tcx , body_id) ;
7168 }
7269 }
7370
7471 fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem ) {
7572 intravisit:: walk_trait_item ( self , ti) ;
7673 if let hir:: TraitItemKind :: Const ( _, Some ( body_id) ) = ti. node {
77- let def_id = self . tcx . hir . local_def_id ( ti. id ) ;
78- check_body ( self . tcx , def_id, body_id) ;
74+ check_body ( self . tcx , body_id) ;
7975 }
8076 }
8177
8278 // Enum variants and types (e.g. `[T; { .. }]`) may have bodies too,
8379 // but they are const-evaluated during typeck.
8480}
8581
82+ fn check_body < ' a , ' tcx > (
83+ tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
84+ body_id : hir:: BodyId ,
85+ ) {
86+ let def_id = tcx. hir . body_owner_def_id ( body_id) ;
87+ let _ = tcx. check_match ( def_id) ;
88+ }
89+
8690pub fn check_crate < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) {
8791 tcx. hir . krate ( ) . visit_all_item_likes ( & mut OuterVisitor { tcx : tcx } . as_deep_visitor ( ) ) ;
8892 tcx. sess . abort_if_errors ( ) ;
8993}
9094
91- pub ( crate ) fn check_body < ' a , ' tcx > (
95+ pub ( crate ) fn check_match < ' a , ' tcx > (
9296 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
9397 def_id : DefId ,
94- body_id : hir:: BodyId ,
95- ) {
96- MatchVisitor {
97- tcx,
98- tables : tcx. body_tables ( body_id) ,
99- region_scope_tree : & tcx. region_scope_tree ( def_id) ,
100- param_env : tcx. param_env ( def_id) ,
101- identity_substs : Substs :: identity_for_item ( tcx, def_id) ,
102- } . visit_body ( tcx. hir . body ( body_id) ) ;
98+ ) -> Result < ( ) , ErrorReported > {
99+ let body_id = if let Some ( id) = tcx. hir . as_local_node_id ( def_id) {
100+ tcx. hir . body_owned_by ( id)
101+ } else {
102+ return Ok ( ( ) ) ;
103+ } ;
104+
105+ tcx. sess . track_errors ( || {
106+ MatchVisitor {
107+ tcx,
108+ tables : tcx. body_tables ( body_id) ,
109+ region_scope_tree : & tcx. region_scope_tree ( def_id) ,
110+ param_env : tcx. param_env ( def_id) ,
111+ identity_substs : Substs :: identity_for_item ( tcx, def_id) ,
112+ } . visit_body ( tcx. hir . body ( body_id) ) ;
113+ } )
103114}
104115
105116fn create_e0004 < ' a > ( sess : & ' a Session , sp : Span , error_message : String ) -> DiagnosticBuilder < ' a > {
0 commit comments