@@ -90,7 +90,7 @@ impl Lint {
90
90
pkg_lints : & TomlToolLints ,
91
91
ws_lints : & TomlToolLints ,
92
92
edition : Edition ,
93
- ) -> LintLevel {
93
+ ) -> ( LintLevel , LintLevelReason ) {
94
94
self . groups
95
95
. iter ( )
96
96
. map ( |g| {
@@ -117,8 +117,8 @@ impl Lint {
117
117
edition,
118
118
) ,
119
119
) ) )
120
- . max_by_key ( |( n, ( l, p) ) | ( l == & LintLevel :: Forbid , * p, std:: cmp:: Reverse ( * n) ) )
121
- . map ( |( _, ( l, _) ) | l )
120
+ . max_by_key ( |( n, ( l, _ , p) ) | ( l == & LintLevel :: Forbid , * p, std:: cmp:: Reverse ( * n) ) )
121
+ . map ( |( _, ( l, r , _) ) | ( l , r ) )
122
122
. unwrap ( )
123
123
}
124
124
}
@@ -164,34 +164,61 @@ impl From<TomlLintLevel> for LintLevel {
164
164
}
165
165
}
166
166
167
+ #[ derive( Copy , Clone , Debug ) ]
168
+ pub enum LintLevelReason {
169
+ Default ,
170
+ Edition ( Edition ) ,
171
+ Package ,
172
+ Workspace ,
173
+ }
174
+
175
+ impl Display for LintLevelReason {
176
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
177
+ match self {
178
+ LintLevelReason :: Default => write ! ( f, "by default" ) ,
179
+ LintLevelReason :: Edition ( edition) => write ! ( f, "in edition {}" , edition) ,
180
+ LintLevelReason :: Package => write ! ( f, "in `[lints]`" ) ,
181
+ LintLevelReason :: Workspace => write ! ( f, "in `[workspace.lints]`" ) ,
182
+ }
183
+ }
184
+ }
185
+
167
186
fn level_priority (
168
187
name : & str ,
169
188
default_level : LintLevel ,
170
189
edition_lint_opts : Option < ( Edition , LintLevel ) > ,
171
190
pkg_lints : & TomlToolLints ,
172
191
ws_lints : & TomlToolLints ,
173
192
edition : Edition ,
174
- ) -> ( LintLevel , i8 ) {
175
- let unspecified_level = if let Some ( level) = edition_lint_opts
193
+ ) -> ( LintLevel , LintLevelReason , i8 ) {
194
+ let ( unspecified_level, reason ) = if let Some ( level) = edition_lint_opts
176
195
. filter ( |( e, _) | edition >= * e)
177
196
. map ( |( _, l) | l)
178
197
{
179
- level
198
+ ( level, LintLevelReason :: Edition ( edition ) )
180
199
} else {
181
- default_level
200
+ ( default_level, LintLevelReason :: Default )
182
201
} ;
183
202
184
203
// Don't allow the group to be overridden if the level is `Forbid`
185
204
if unspecified_level == LintLevel :: Forbid {
186
- return ( unspecified_level, 0 ) ;
205
+ return ( unspecified_level, reason , 0 ) ;
187
206
}
188
207
189
208
if let Some ( defined_level) = pkg_lints. get ( name) {
190
- ( defined_level. level ( ) . into ( ) , defined_level. priority ( ) )
209
+ (
210
+ defined_level. level ( ) . into ( ) ,
211
+ LintLevelReason :: Package ,
212
+ defined_level. priority ( ) ,
213
+ )
191
214
} else if let Some ( defined_level) = ws_lints. get ( name) {
192
- ( defined_level. level ( ) . into ( ) , defined_level. priority ( ) )
215
+ (
216
+ defined_level. level ( ) . into ( ) ,
217
+ LintLevelReason :: Workspace ,
218
+ defined_level. priority ( ) ,
219
+ )
193
220
} else {
194
- ( unspecified_level, 0 )
221
+ ( unspecified_level, reason , 0 )
195
222
}
196
223
}
197
224
@@ -212,7 +239,7 @@ pub fn check_im_a_teapot(
212
239
gctx : & GlobalContext ,
213
240
) -> CargoResult < ( ) > {
214
241
let manifest = pkg. manifest ( ) ;
215
- let lint_level = IM_A_TEAPOT . level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
242
+ let ( lint_level, reason ) = IM_A_TEAPOT . level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
216
243
if lint_level == LintLevel :: Allow {
217
244
return Ok ( ( ) ) ;
218
245
}
@@ -227,7 +254,10 @@ pub fn check_im_a_teapot(
227
254
}
228
255
let level = lint_level. to_diagnostic_level ( ) ;
229
256
let manifest_path = rel_cwd_manifest_path ( path, gctx) ;
230
- let emitted_reason = format ! ( "`cargo::{}` is set to `{lint_level}`" , IM_A_TEAPOT . name) ;
257
+ let emitted_reason = format ! (
258
+ "`cargo::{}` is set to `{lint_level}` {reason}" ,
259
+ IM_A_TEAPOT . name
260
+ ) ;
231
261
232
262
let key_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , false ) . unwrap ( ) ;
233
263
let value_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , true ) . unwrap ( ) ;
@@ -287,7 +317,7 @@ pub fn check_implicit_features(
287
317
return Ok ( ( ) ) ;
288
318
}
289
319
290
- let lint_level = IMPLICIT_FEATURES . level ( pkg_lints, ws_lints, edition) ;
320
+ let ( lint_level, reason ) = IMPLICIT_FEATURES . level ( pkg_lints, ws_lints, edition) ;
291
321
if lint_level == LintLevel :: Allow {
292
322
return Ok ( ( ) ) ;
293
323
}
@@ -332,7 +362,7 @@ pub fn check_implicit_features(
332
362
) ;
333
363
if emitted_source. is_none ( ) {
334
364
emitted_source = Some ( format ! (
335
- "`cargo::{}` is set to `{lint_level}`" ,
365
+ "`cargo::{}` is set to `{lint_level}` {reason} " ,
336
366
IMPLICIT_FEATURES . name
337
367
) ) ;
338
368
message = message. footer ( Level :: Note . title ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
@@ -370,7 +400,7 @@ pub fn unused_dependencies(
370
400
return Ok ( ( ) ) ;
371
401
}
372
402
373
- let lint_level = UNUSED_OPTIONAL_DEPENDENCY . level ( pkg_lints, ws_lints, edition) ;
403
+ let ( lint_level, reason ) = UNUSED_OPTIONAL_DEPENDENCY . level ( pkg_lints, ws_lints, edition) ;
374
404
if lint_level == LintLevel :: Allow {
375
405
return Ok ( ( ) ) ;
376
406
}
@@ -436,7 +466,7 @@ pub fn unused_dependencies(
436
466
) ;
437
467
if emitted_source. is_none ( ) {
438
468
emitted_source = Some ( format ! (
439
- "`cargo::{}` is set to `{lint_level}`" ,
469
+ "`cargo::{}` is set to `{lint_level}` {reason} " ,
440
470
UNUSED_OPTIONAL_DEPENDENCY . name
441
471
) ) ;
442
472
message =
0 commit comments