@@ -134,36 +134,34 @@ fn verify_feature_enabled(
134134 ) ;
135135
136136 let message = if let Some ( span) =
137- get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false )
137+ get_key_value_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] )
138138 {
139139 Level :: Error
140140 . title ( & title)
141141 . snippet (
142142 Snippet :: source ( manifest. contents ( ) )
143143 . origin ( & manifest_path)
144- . annotation ( Level :: Error . span ( span) . label ( & label) )
144+ . annotation ( Level :: Error . span ( span. key ) . label ( & label) )
145145 . fold ( true ) ,
146146 )
147147 . footer ( Level :: Help . title ( & help) )
148148 } else {
149- let lint_span = get_span (
149+ let lint_span = get_key_value_span (
150150 ws_document,
151151 & [ "workspace" , "lints" , "cargo" , lint_name] ,
152- false ,
153152 )
154153 . unwrap_or_else ( || {
155154 panic ! ( "could not find `cargo::{lint_name}` in `[lints]`, or `[workspace.lints]` " )
156155 } ) ;
157156
158- let inherited_note = if let ( Some ( inherit_span_key) , Some ( inherit_span_value) ) = (
159- get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , false ) ,
160- get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , true ) ,
161- ) {
157+ let inherited_note = if let Some ( inherit_span) =
158+ get_key_value_span ( manifest. document ( ) , & [ "lints" , "workspace" ] )
159+ {
162160 Level :: Note . title ( & second_title) . snippet (
163161 Snippet :: source ( manifest. contents ( ) )
164162 . origin ( & manifest_path)
165163 . annotation (
166- Level :: Note . span ( inherit_span_key . start ..inherit_span_value . end ) ,
164+ Level :: Note . span ( inherit_span . key . start ..inherit_span . value . end ) ,
167165 )
168166 . fold ( true ) ,
169167 )
@@ -176,7 +174,7 @@ fn verify_feature_enabled(
176174 . snippet (
177175 Snippet :: source ( ws_contents)
178176 . origin ( & ws_path)
179- . annotation ( Level :: Error . span ( lint_span) . label ( & label) )
177+ . annotation ( Level :: Error . span ( lint_span. key ) . label ( & label) )
180178 . fold ( true ) ,
181179 )
182180 . footer ( inherited_note)
@@ -189,22 +187,26 @@ fn verify_feature_enabled(
189187 Ok ( ( ) )
190188}
191189
192- pub fn get_span (
190+ #[ derive( Clone ) ]
191+ pub struct TomlSpan {
192+ pub key : Range < usize > ,
193+ pub value : Range < usize > ,
194+ }
195+
196+ pub fn get_key_value_span (
193197 document : & toml:: Spanned < toml:: de:: DeTable < ' static > > ,
194198 path : & [ & str ] ,
195- get_value : bool ,
196- ) -> Option < Range < usize > > {
199+ ) -> Option < TomlSpan > {
197200 let mut table = document. get_ref ( ) ;
198201 let mut iter = path. into_iter ( ) . peekable ( ) ;
199202 while let Some ( key) = iter. next ( ) {
200203 let key_s: & str = key. as_ref ( ) ;
201204 let ( key, item) = table. get_key_value ( key_s) ?;
202205 if iter. peek ( ) . is_none ( ) {
203- return if get_value {
204- Some ( item. span ( ) )
205- } else {
206- Some ( key. span ( ) )
207- } ;
206+ return Some ( TomlSpan {
207+ key : key. span ( ) ,
208+ value : item. span ( ) ,
209+ } ) ;
208210 }
209211 if let Some ( next_table) = item. get_ref ( ) . as_table ( ) {
210212 table = next_table;
@@ -213,7 +215,10 @@ pub fn get_span(
213215 if let Some ( array) = item. get_ref ( ) . as_array ( ) {
214216 let next = iter. next ( ) . unwrap ( ) ;
215217 return array. iter ( ) . find_map ( |item| match item. get_ref ( ) {
216- toml:: de:: DeValue :: String ( s) if s == next => Some ( item. span ( ) ) ,
218+ toml:: de:: DeValue :: String ( s) if s == next => Some ( TomlSpan {
219+ key : key. span ( ) ,
220+ value : item. span ( ) ,
221+ } ) ,
217222 _ => None ,
218223 } ) ;
219224 }
@@ -455,14 +460,14 @@ pub fn check_im_a_teapot(
455460 let manifest_path = rel_cwd_manifest_path ( path, gctx) ;
456461 let emitted_reason = IM_A_TEAPOT . emitted_source ( lint_level, reason) ;
457462
458- let key_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , false ) . unwrap ( ) ;
459- let value_span = get_span ( manifest . document ( ) , & [ "package" , "im-a-teapot" ] , true ) . unwrap ( ) ;
463+ let span = get_key_value_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] ) . unwrap ( ) ;
464+
460465 let message = level
461466 . title ( IM_A_TEAPOT . desc )
462467 . snippet (
463468 Snippet :: source ( manifest. contents ( ) )
464469 . origin ( & manifest_path)
465- . annotation ( level. span ( key_span . start ..value_span . end ) )
470+ . annotation ( level. span ( span . key . start ..span . value . end ) )
466471 . fold ( true ) ,
467472 )
468473 . footer ( Level :: Note . title ( & emitted_reason) ) ;
@@ -542,33 +547,31 @@ fn output_unknown_lints(
542547 }
543548
544549 let mut message = if let Some ( span) =
545- get_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] , false )
550+ get_key_value_span ( manifest. document ( ) , & [ "lints" , "cargo" , lint_name] )
546551 {
547552 level. title ( & title) . snippet (
548553 Snippet :: source ( manifest. contents ( ) )
549554 . origin ( & manifest_path)
550- . annotation ( Level :: Error . span ( span) )
555+ . annotation ( Level :: Error . span ( span. key ) )
551556 . fold ( true ) ,
552557 )
553558 } else {
554- let lint_span = get_span (
559+ let lint_span = get_key_value_span (
555560 ws_document,
556561 & [ "workspace" , "lints" , "cargo" , lint_name] ,
557- false ,
558562 )
559563 . unwrap_or_else ( || {
560564 panic ! ( "could not find `cargo::{lint_name}` in `[lints]`, or `[workspace.lints]` " )
561565 } ) ;
562566
563- let inherited_note = if let ( Some ( inherit_span_key) , Some ( inherit_span_value) ) = (
564- get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , false ) ,
565- get_span ( manifest. document ( ) , & [ "lints" , "workspace" ] , true ) ,
566- ) {
567+ let inherited_note = if let Some ( inherit_span) =
568+ get_key_value_span ( manifest. document ( ) , & [ "lints" , "workspace" ] )
569+ {
567570 Level :: Note . title ( & second_title) . snippet (
568571 Snippet :: source ( manifest. contents ( ) )
569572 . origin ( & manifest_path)
570573 . annotation (
571- Level :: Note . span ( inherit_span_key . start ..inherit_span_value . end ) ,
574+ Level :: Note . span ( inherit_span . key . start ..inherit_span . value . end ) ,
572575 )
573576 . fold ( true ) ,
574577 )
@@ -580,7 +583,7 @@ fn output_unknown_lints(
580583 level. title ( & title) . snippet (
581584 Snippet :: source ( ws_contents)
582585 . origin ( & ws_path)
583- . annotation ( Level :: Error . span ( lint_span) )
586+ . annotation ( Level :: Error . span ( lint_span. key ) )
584587 . fold ( true ) ,
585588 )
586589 } ;
0 commit comments