@@ -43,7 +43,7 @@ use syntax::attr;
43
43
use syntax:: parse:: token:: InternedString ;
44
44
use syntax:: ast;
45
45
use syntax_pos:: Span ;
46
- use errors:: DiagnosticBuilder ;
46
+ use errors:: { self , Diagnostic , DiagnosticBuilder } ;
47
47
use hir;
48
48
use hir:: intravisit as hir_visit;
49
49
use syntax:: visit as ast_visit;
@@ -87,30 +87,36 @@ pub struct EarlyLint {
87
87
/// what lint is this? (e.g., `dead_code`)
88
88
pub id : LintId ,
89
89
90
- /// the span where the lint will be reported at
90
+ /// what span was it attached to (this is used for Eq comparisons;
91
+ /// it duplicates to some extent the information in
92
+ /// `diagnostic.span`)
91
93
pub span : Span ,
92
94
93
95
/// the main message
94
- pub msg : String ,
96
+ pub diagnostic : Diagnostic ,
95
97
}
96
98
97
99
impl fmt:: Debug for EarlyLint {
98
100
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
99
101
f. debug_struct ( "EarlyLint" )
100
102
. field ( "id" , & self . id )
101
- . field ( "span" , & self . span )
102
- . field ( "msg " , & self . msg )
103
+ . field ( "span" , & self . diagnostic . span )
104
+ . field ( "diagnostic " , & self . diagnostic )
103
105
. finish ( )
104
106
}
105
107
}
106
108
107
109
impl EarlyLint {
108
110
pub fn new ( id : LintId , span : Span , msg : String ) -> Self {
109
- EarlyLint { id : id, span : span, msg : msg }
111
+ let mut diagnostic = Diagnostic :: new ( errors:: Level :: Warning , & msg) ;
112
+ diagnostic. set_span ( span) ;
113
+ EarlyLint { id : id, span : span, diagnostic : diagnostic }
110
114
}
111
115
112
116
pub fn matches ( & self , other : & EarlyLint ) -> bool {
113
- self . id == other. id && self . span == other. span && self . msg == other. msg
117
+ self . id == other. id &&
118
+ self . span == other. span &&
119
+ self . diagnostic . message == other. diagnostic . message
114
120
}
115
121
}
116
122
@@ -551,7 +557,10 @@ pub trait LintContext: Sized {
551
557
}
552
558
553
559
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 ) ;
560
+ let mut err = self . struct_span_lint ( early_lint. id . lint ,
561
+ early_lint. span ,
562
+ & early_lint. diagnostic . message ) ;
563
+ err. copy_details_not_message ( & early_lint. diagnostic ) ;
555
564
err. emit ( ) ;
556
565
}
557
566
0 commit comments