@@ -87,8 +87,8 @@ impl<'s> LintLevelsBuilder<'s> {
87
87
self . sets . list . push ( LintSet :: CommandLine { specs : FxHashMap :: default ( ) } ) ;
88
88
self . sets . lint_cap = sess. opts . lint_cap . unwrap_or ( Level :: Forbid ) ;
89
89
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) ;
92
92
let orig_level = level;
93
93
94
94
// If the cap is less than this specified level, e.g., if we've got
@@ -97,14 +97,15 @@ impl<'s> LintLevelsBuilder<'s> {
97
97
let level = cmp:: min ( level, self . sets . lint_cap ) ;
98
98
99
99
let lint_flag_val = Symbol :: intern ( lint_name) ;
100
+ let src = LintLevelSource :: CommandLine ( lint_flag_val, orig_level, position) ;
100
101
101
102
let ids = match store. find_lints ( & lint_name) {
102
103
Ok ( ids) => ids,
103
104
Err ( _) => continue , // errors handled in check_lint_name_cmdline above
104
105
} ;
106
+
105
107
for id in ids {
106
108
self . check_gated_lint ( id, DUMMY_SP ) ;
107
- let src = LintLevelSource :: CommandLine ( lint_flag_val, orig_level) ;
108
109
let specs = match self . sets . list . last ( ) . unwrap ( ) {
109
110
LintSet :: CommandLine { ref specs } => specs,
110
111
_ => unreachable ! ( ) ,
@@ -132,6 +133,22 @@ impl<'s> LintLevelsBuilder<'s> {
132
133
self . sets . list . push ( LintSet :: CommandLine { specs } ) ;
133
134
}
134
135
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
+
135
152
fn check_before_insert_spec (
136
153
& self ,
137
154
specs : & FxHashMap < LintId , LevelAndSource > ,
@@ -157,8 +174,8 @@ impl<'s> LintLevelsBuilder<'s> {
157
174
let id_name = id. lint . name_lower ( ) ;
158
175
let fcw_warning = match old_src {
159
176
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) ,
162
179
LintLevelSource :: ForceWarn ( _symbol) => {
163
180
bug ! ( "forced warn lint returned a forbid lint level" )
164
181
}
@@ -177,13 +194,13 @@ impl<'s> LintLevelsBuilder<'s> {
177
194
id. to_string( )
178
195
) ) ;
179
196
}
180
- LintLevelSource :: Node ( _, forbid_source_span, reason) => {
197
+ LintLevelSource :: Node ( _, forbid_source_span, reason, .. ) => {
181
198
diag_builder. span_label ( forbid_source_span, "`forbid` level set here" ) ;
182
199
if let Some ( rationale) = reason {
183
200
diag_builder. note ( & rationale. as_str ( ) ) ;
184
201
}
185
202
}
186
- LintLevelSource :: CommandLine ( _ , _ ) => {
203
+ LintLevelSource :: CommandLine ( .. ) => {
187
204
diag_builder. note ( "`forbid` lint level was set on command line" ) ;
188
205
}
189
206
_ => bug ! ( "forced warn lint returned a forbid lint level" ) ,
@@ -263,7 +280,7 @@ impl<'s> LintLevelsBuilder<'s> {
263
280
let mut specs = FxHashMap :: default ( ) ;
264
281
let sess = self . sess ;
265
282
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 ( ) ) {
267
284
let level = match Level :: from_symbol ( attr. name_or_empty ( ) ) {
268
285
None => continue ,
269
286
Some ( lvl) => lvl,
@@ -374,7 +391,10 @@ impl<'s> LintLevelsBuilder<'s> {
374
391
meta_item. path . segments . last ( ) . expect ( "empty lint name" ) . ident . name ,
375
392
sp,
376
393
reason,
394
+ self . get_current_depth ( ) ,
395
+ attr_pos,
377
396
) ;
397
+
378
398
for & id in * ids {
379
399
self . check_gated_lint ( id, attr. span ) ;
380
400
self . insert_spec ( & mut specs, id, ( level, src) ) ;
@@ -389,6 +409,8 @@ impl<'s> LintLevelsBuilder<'s> {
389
409
Symbol :: intern ( complete_name) ,
390
410
sp,
391
411
reason,
412
+ self . get_current_depth ( ) ,
413
+ attr_pos,
392
414
) ;
393
415
for id in ids {
394
416
self . insert_spec ( & mut specs, * id, ( level, src) ) ;
@@ -425,6 +447,8 @@ impl<'s> LintLevelsBuilder<'s> {
425
447
Symbol :: intern ( & new_lint_name) ,
426
448
sp,
427
449
reason,
450
+ self . get_current_depth ( ) ,
451
+ attr_pos,
428
452
) ;
429
453
for id in ids {
430
454
self . insert_spec ( & mut specs, * id, ( level, src) ) ;
@@ -495,7 +519,13 @@ impl<'s> LintLevelsBuilder<'s> {
495
519
// Ignore any errors or warnings that happen because the new name is inaccurate
496
520
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
497
521
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
+ ) ;
499
529
for & id in ids {
500
530
self . check_gated_lint ( id, attr. span ) ;
501
531
self . insert_spec ( & mut specs, id, ( level, src) ) ;
@@ -514,7 +544,7 @@ impl<'s> LintLevelsBuilder<'s> {
514
544
}
515
545
516
546
let ( lint_attr_name, lint_attr_span) = match * src {
517
- LintLevelSource :: Node ( name, span, _) => ( name, span) ,
547
+ LintLevelSource :: Node ( name, span, _, _ , _ ) => ( name, span) ,
518
548
_ => continue ,
519
549
} ;
520
550
0 commit comments