88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11+ use middle:: def_id:: DefId ;
1112use middle:: ty:: Region ;
1213use mir:: repr:: * ;
1314use rustc_data_structures:: tuple_slice:: TupleSlice ;
15+ use syntax:: codemap:: Span ;
1416
1517pub trait Visitor < ' tcx > {
1618 // Override these, and call `self.super_xxx` to revert back to the
@@ -56,6 +58,18 @@ pub trait Visitor<'tcx> {
5658 self . super_constant ( constant) ;
5759 }
5860
61+ fn visit_literal ( & mut self , literal : & Literal < ' tcx > ) {
62+ self . super_literal ( literal) ;
63+ }
64+
65+ fn visit_def_id ( & mut self , def_id : DefId ) {
66+ self . super_def_id ( def_id) ;
67+ }
68+
69+ fn visit_span ( & mut self , span : Span ) {
70+ self . super_span ( span) ;
71+ }
72+
5973 // The `super_xxx` methods comprise the default behavior and are
6074 // not meant to be overidden.
6175
@@ -74,6 +88,8 @@ pub trait Visitor<'tcx> {
7488 }
7589
7690 fn super_statement ( & mut self , block : BasicBlock , statement : & Statement < ' tcx > ) {
91+ self . visit_span ( statement. span ) ;
92+
7793 match statement. kind {
7894 StatementKind :: Assign ( ref lvalue, ref rvalue) => {
7995 self . visit_assign ( block, lvalue, rvalue) ;
@@ -218,7 +234,26 @@ pub trait Visitor<'tcx> {
218234 fn super_branch ( & mut self , _source : BasicBlock , _target : BasicBlock ) {
219235 }
220236
221- fn super_constant ( & mut self , _constant : & Constant < ' tcx > ) {
237+ fn super_constant ( & mut self , constant : & Constant < ' tcx > ) {
238+ self . visit_span ( constant. span ) ;
239+ self . visit_literal ( & constant. literal ) ;
240+ }
241+
242+ fn super_literal ( & mut self , literal : & Literal < ' tcx > ) {
243+ match * literal {
244+ Literal :: Item { def_id, .. } => {
245+ self . visit_def_id ( def_id) ;
246+ } ,
247+ Literal :: Value { .. } => {
248+ // Nothing to do
249+ }
250+ }
251+ }
252+
253+ fn super_def_id ( & mut self , _def_id : DefId ) {
254+ }
255+
256+ fn super_span ( & mut self , _span : Span ) {
222257 }
223258}
224259
0 commit comments