@@ -87,8 +87,8 @@ impl<'s> LintLevelsBuilder<'s> {
8787 self . sets . list . push ( LintSet :: CommandLine { specs : FxHashMap :: default ( ) } ) ;
8888 self . sets . lint_cap = sess. opts . lint_cap . unwrap_or ( Level :: Forbid ) ;
8989
90- for & ( ref lint_name, level) in & sess. opts . lint_opts {
91- store. check_lint_name_cmdline ( sess, & lint_name, Some ( level) ) ;
90+ for ( position , & ( ref lint_name, level) ) in ( 0u32 .. ) . zip ( sess. opts . lint_opts . iter ( ) ) {
91+ store. check_lint_name_cmdline ( sess, & lint_name, level) ;
9292 let orig_level = level;
9393
9494 // If the cap is less than this specified level, e.g., if we've got
@@ -97,14 +97,15 @@ impl<'s> LintLevelsBuilder<'s> {
9797 let level = cmp:: min ( level, self . sets . lint_cap ) ;
9898
9999 let lint_flag_val = Symbol :: intern ( lint_name) ;
100+ let src = LintLevelSource :: CommandLine ( lint_flag_val, orig_level, position) ;
100101
101102 let ids = match store. find_lints ( & lint_name) {
102103 Ok ( ids) => ids,
103104 Err ( _) => continue , // errors handled in check_lint_name_cmdline above
104105 } ;
106+
105107 for id in ids {
106108 self . check_gated_lint ( id, DUMMY_SP ) ;
107- let src = LintLevelSource :: CommandLine ( lint_flag_val, orig_level) ;
108109 let specs = match self . sets . list . last ( ) . unwrap ( ) {
109110 LintSet :: CommandLine { ref specs } => specs,
110111 _ => unreachable ! ( ) ,
@@ -132,6 +133,22 @@ impl<'s> LintLevelsBuilder<'s> {
132133 self . sets . list . push ( LintSet :: CommandLine { specs } ) ;
133134 }
134135
136+ fn get_current_depth ( & self ) -> u32 {
137+ let mut idx = self . cur ;
138+ let mut depth = 0 ;
139+ loop {
140+ match & self . sets . list [ idx as usize ] {
141+ LintSet :: CommandLine { .. } => {
142+ return depth;
143+ }
144+ LintSet :: Node { parent, .. } => {
145+ depth += 1 ;
146+ idx = * parent;
147+ }
148+ }
149+ }
150+ }
151+
135152 fn check_before_insert_spec (
136153 & self ,
137154 specs : & FxHashMap < LintId , LevelAndSource > ,
@@ -157,8 +174,8 @@ impl<'s> LintLevelsBuilder<'s> {
157174 let id_name = id. lint . name_lower ( ) ;
158175 let fcw_warning = match old_src {
159176 LintLevelSource :: Default => false ,
160- LintLevelSource :: Node ( symbol, _ , _ ) => self . store . is_lint_group ( symbol) ,
161- LintLevelSource :: CommandLine ( symbol, _ ) => self . store . is_lint_group ( symbol) ,
177+ LintLevelSource :: Node ( symbol, .. ) => self . store . is_lint_group ( symbol) ,
178+ LintLevelSource :: CommandLine ( symbol, .. ) => self . store . is_lint_group ( symbol) ,
162179 LintLevelSource :: ForceWarn ( _symbol) => {
163180 bug ! ( "forced warn lint returned a forbid lint level" )
164181 }
@@ -177,13 +194,13 @@ impl<'s> LintLevelsBuilder<'s> {
177194 id. to_string( )
178195 ) ) ;
179196 }
180- LintLevelSource :: Node ( _, forbid_source_span, reason) => {
197+ LintLevelSource :: Node ( _, forbid_source_span, reason, .. ) => {
181198 diag_builder. span_label ( forbid_source_span, "`forbid` level set here" ) ;
182199 if let Some ( rationale) = reason {
183200 diag_builder. note ( & rationale. as_str ( ) ) ;
184201 }
185202 }
186- LintLevelSource :: CommandLine ( _ , _ ) => {
203+ LintLevelSource :: CommandLine ( .. ) => {
187204 diag_builder. note ( "`forbid` lint level was set on command line" ) ;
188205 }
189206 _ => bug ! ( "forced warn lint returned a forbid lint level" ) ,
@@ -263,7 +280,7 @@ impl<'s> LintLevelsBuilder<'s> {
263280 let mut specs = FxHashMap :: default ( ) ;
264281 let sess = self . sess ;
265282 let bad_attr = |span| struct_span_err ! ( sess, span, E0452 , "malformed lint attribute input" ) ;
266- for attr in attrs {
283+ for ( attr_pos , attr) in ( 0u32 .. ) . zip ( attrs. iter ( ) ) {
267284 let level = match Level :: from_symbol ( attr. name_or_empty ( ) ) {
268285 None => continue ,
269286 Some ( lvl) => lvl,
@@ -374,7 +391,10 @@ impl<'s> LintLevelsBuilder<'s> {
374391 meta_item. path . segments . last ( ) . expect ( "empty lint name" ) . ident . name ,
375392 sp,
376393 reason,
394+ self . get_current_depth ( ) ,
395+ attr_pos,
377396 ) ;
397+
378398 for & id in * ids {
379399 self . check_gated_lint ( id, attr. span ) ;
380400 self . insert_spec ( & mut specs, id, ( level, src) ) ;
@@ -389,6 +409,8 @@ impl<'s> LintLevelsBuilder<'s> {
389409 Symbol :: intern ( complete_name) ,
390410 sp,
391411 reason,
412+ self . get_current_depth ( ) ,
413+ attr_pos,
392414 ) ;
393415 for id in ids {
394416 self . insert_spec ( & mut specs, * id, ( level, src) ) ;
@@ -425,6 +447,8 @@ impl<'s> LintLevelsBuilder<'s> {
425447 Symbol :: intern ( & new_lint_name) ,
426448 sp,
427449 reason,
450+ self . get_current_depth ( ) ,
451+ attr_pos,
428452 ) ;
429453 for id in ids {
430454 self . insert_spec ( & mut specs, * id, ( level, src) ) ;
@@ -495,7 +519,13 @@ impl<'s> LintLevelsBuilder<'s> {
495519 // Ignore any errors or warnings that happen because the new name is inaccurate
496520 // NOTE: `new_name` already includes the tool name, so we don't have to add it again.
497521 if let CheckLintNameResult :: Ok ( ids) = store. check_lint_name ( & new_name, None ) {
498- let src = LintLevelSource :: Node ( Symbol :: intern ( & new_name) , sp, reason) ;
522+ let src = LintLevelSource :: Node (
523+ Symbol :: intern ( & new_name) ,
524+ sp,
525+ reason,
526+ self . get_current_depth ( ) ,
527+ attr_pos,
528+ ) ;
499529 for & id in ids {
500530 self . check_gated_lint ( id, attr. span ) ;
501531 self . insert_spec ( & mut specs, id, ( level, src) ) ;
@@ -514,7 +544,7 @@ impl<'s> LintLevelsBuilder<'s> {
514544 }
515545
516546 let ( lint_attr_name, lint_attr_span) = match * src {
517- LintLevelSource :: Node ( name, span, _) => ( name, span) ,
547+ LintLevelSource :: Node ( name, span, _, _ , _ ) => ( name, span) ,
518548 _ => continue ,
519549 } ;
520550
0 commit comments