@@ -111,44 +111,46 @@ impl Highlight {
111111/// Invokes `cargo build` at `path` and returns the generated diagnostic messages as [`Highlight`]s.
112112pub fn collect_highlights ( opts : & opts:: Dylint , path : & Path ) -> Result < Vec < Highlight > > {
113113 let start = Instant :: now ( ) ;
114+
114115 let output = cargo:: check ( "upgraded library package" )
115116 . quiet ( opts. quiet )
116117 . build ( )
117118 . sanitize_environment ( )
118119 . current_dir ( path)
119120 . arg ( "--message-format=json" )
120121 . logged_output ( false ) ?;
121- let elapsed = start. elapsed ( ) ;
122- eprintln ! (
123- "Checked upgraded library package in {} seconds" ,
124- elapsed. as_secs( )
125- ) ;
126-
127- if output. status . success ( ) {
128- return Ok ( Vec :: new ( ) ) ;
129- }
130122
131123 let mut highlights = Vec :: new ( ) ;
132- let stdout = String :: from_utf8 ( output. stdout ) ?;
133- for result in serde_json:: Deserializer :: from_str ( & stdout) . into_iter :: < Message > ( ) {
134- let message = result?;
135- if message. reason != "compiler-message" {
136- continue ;
137- }
138- let Some ( diagnostic) = message. diagnostic else {
139- continue ;
140- } ;
141- for span in diagnostic. spans {
142- if span. text . is_empty ( ) {
124+
125+ if !output. status . success ( ) {
126+ let stdout = String :: from_utf8 ( output. stdout ) ?;
127+ for result in serde_json:: Deserializer :: from_str ( & stdout) . into_iter :: < Message > ( ) {
128+ let message = result?;
129+ if message. reason != "compiler-message" {
130+ continue ;
131+ }
132+ let Some ( diagnostic) = message. diagnostic else {
143133 continue ;
134+ } ;
135+ for span in diagnostic. spans {
136+ if span. text . is_empty ( ) {
137+ continue ;
138+ }
139+ let highlight = Highlight :: try_new ( & diagnostic. message , span) ?;
140+ assert ! ( !highlight. tokens. is_empty( ) ) ;
141+ highlights. push ( highlight) ;
144142 }
145- let highlight = Highlight :: try_new ( & diagnostic. message , span) ?;
146- assert ! ( !highlight. tokens. is_empty( ) ) ;
147- highlights. push ( highlight) ;
148143 }
144+
145+ highlights. sort ( ) ;
149146 }
150147
151- highlights. sort ( ) ;
148+ let elapsed = start. elapsed ( ) ;
149+ eprintln ! (
150+ "Found {} highlights in {} seconds" ,
151+ highlights. len( ) ,
152+ elapsed. as_secs( )
153+ ) ;
152154
153155 Ok ( highlights)
154156}
0 commit comments