@@ -38,6 +38,7 @@ use util::nodemap::FnvHashMap;
38
38
use std:: cmp;
39
39
use std:: default:: Default as StdDefault ;
40
40
use std:: mem;
41
+ use std:: fmt;
41
42
use syntax:: attr;
42
43
use syntax:: parse:: token:: InternedString ;
43
44
use syntax:: ast;
@@ -80,6 +81,41 @@ pub struct LintStore {
80
81
lint_cap : Option < Level > ,
81
82
}
82
83
84
+ /// When you call `add_lint` on the session, you wind up storing one
85
+ /// of these, which records a "potential lint" at a particular point.
86
+ pub struct EarlyLint {
87
+ /// what lint is this? (e.g., `dead_code`)
88
+ pub id : LintId ,
89
+
90
+ /// the span where the lint will be reported at
91
+ pub span : Span ,
92
+
93
+ /// the main message
94
+ pub msg : String ,
95
+ }
96
+
97
+ impl fmt:: Debug for EarlyLint {
98
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
99
+ f. debug_struct ( "EarlyLint" )
100
+ . field ( "id" , & self . id )
101
+ . field ( "span" , & self . span )
102
+ . field ( "msg" , & self . msg )
103
+ . finish ( )
104
+ }
105
+ }
106
+
107
+ impl EarlyLint {
108
+ pub fn new ( id : LintId , span : Span , msg : String ) -> Self {
109
+ EarlyLint { id : id, span : span, msg : msg }
110
+ }
111
+
112
+ pub fn matches ( & self , other : & EarlyLint ) -> bool {
113
+ self . id == other. id && self . span == other. span && self . msg == other. msg
114
+ }
115
+ }
116
+
117
+
118
+
83
119
/// Extra information for a future incompatibility lint. See the call
84
120
/// to `register_future_incompatible` in `librustc_lint/lib.rs` for
85
121
/// guidelines.
@@ -514,6 +550,11 @@ pub trait LintContext: Sized {
514
550
self . lookup_and_emit ( lint, Some ( span) , msg) ;
515
551
}
516
552
553
+ fn early_lint ( & self , early_lint : EarlyLint ) {
554
+ let mut err = self . struct_span_lint ( early_lint. id . lint , early_lint. span , & early_lint. msg ) ;
555
+ err. emit ( ) ;
556
+ }
557
+
517
558
fn struct_span_lint ( & self ,
518
559
lint : & ' static Lint ,
519
560
span : Span ,
@@ -1065,8 +1106,8 @@ impl<'a, 'b, 'tcx, 'v> hir_visit::Visitor<'v> for IdVisitor<'a, 'b, 'tcx> {
1065
1106
fn visit_id ( & mut self , id : ast:: NodeId ) {
1066
1107
if let Some ( lints) = self . cx . sess ( ) . lints . borrow_mut ( ) . remove ( & id) {
1067
1108
debug ! ( "LateContext::visit_id: id={:?} lints={:?}" , id, lints) ;
1068
- for ( lint_id , span , msg ) in lints {
1069
- self . cx . span_lint ( lint_id . lint , span , & msg [ .. ] )
1109
+ for early_lint in lints {
1110
+ self . cx . early_lint ( early_lint ) ;
1070
1111
}
1071
1112
}
1072
1113
}
@@ -1211,10 +1252,10 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1211
1252
// If we missed any lints added to the session, then there's a bug somewhere
1212
1253
// in the iteration code.
1213
1254
for ( id, v) in tcx. sess . lints . borrow ( ) . iter ( ) {
1214
- for & ( lint , span , ref msg ) in v {
1215
- span_bug ! ( span,
1216
- "unprocessed lint {} at {}: {}" ,
1217
- lint . to_string ( ) , tcx. map. node_to_string( * id) , * msg )
1255
+ for early_lint in v {
1256
+ span_bug ! ( early_lint . span,
1257
+ "unprocessed lint {:? } at {}" ,
1258
+ early_lint , tcx. map. node_to_string( * id) ) ;
1218
1259
}
1219
1260
}
1220
1261
@@ -1229,8 +1270,8 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) {
1229
1270
cx. with_lint_attrs ( & krate. attrs , |cx| {
1230
1271
// Lints may be assigned to the whole crate.
1231
1272
if let Some ( lints) = cx. sess . lints . borrow_mut ( ) . remove ( & ast:: CRATE_NODE_ID ) {
1232
- for ( lint_id , span , msg ) in lints {
1233
- cx. span_lint ( lint_id . lint , span , & msg [ .. ] )
1273
+ for early_lint in lints {
1274
+ cx. early_lint ( early_lint ) ;
1234
1275
}
1235
1276
}
1236
1277
@@ -1249,8 +1290,8 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) {
1249
1290
// If we missed any lints added to the session, then there's a bug somewhere
1250
1291
// in the iteration code.
1251
1292
for ( _, v) in sess. lints . borrow ( ) . iter ( ) {
1252
- for & ( lint , span , ref msg ) in v {
1253
- span_bug ! ( span, "unprocessed lint {}: { }" , lint . to_string ( ) , * msg )
1293
+ for early_lint in v {
1294
+ span_bug ! ( early_lint . span, "unprocessed lint {:? }" , early_lint ) ;
1254
1295
}
1255
1296
}
1256
1297
}
0 commit comments