@@ -69,28 +69,36 @@ pub trait LevelTrait {
69
69
pkg_lints : & TomlToolLints ,
70
70
ws_lints : & TomlToolLints ,
71
71
edition : Edition ,
72
- ) -> ( LintLevel , i8 ) {
73
- let unspecified_level = if let Some ( level) = self
72
+ ) -> ( LintLevel , LintLevelReason , i8 ) {
73
+ let ( unspecified_level, reason ) = if let Some ( level) = self
74
74
. edition_lint_opts ( )
75
75
. filter ( |( e, _) | edition >= * e)
76
76
. map ( |( _, l) | l)
77
77
{
78
- level
78
+ ( level, LintLevelReason :: Edition ( edition ) )
79
79
} else {
80
- self . default_level ( )
80
+ ( self . default_level ( ) , LintLevelReason :: Default )
81
81
} ;
82
82
83
83
// Don't allow the group to be overridden if the level is `Forbid`
84
84
if unspecified_level == LintLevel :: Forbid {
85
- return ( unspecified_level, 0 ) ;
85
+ return ( unspecified_level, reason , 0 ) ;
86
86
}
87
87
88
88
if let Some ( defined_level) = pkg_lints. get ( self . name ( ) ) {
89
- ( defined_level. level ( ) . into ( ) , defined_level. priority ( ) )
89
+ (
90
+ defined_level. level ( ) . into ( ) ,
91
+ LintLevelReason :: Package ,
92
+ defined_level. priority ( ) ,
93
+ )
90
94
} else if let Some ( defined_level) = ws_lints. get ( self . name ( ) ) {
91
- ( defined_level. level ( ) . into ( ) , defined_level. priority ( ) )
95
+ (
96
+ defined_level. level ( ) . into ( ) ,
97
+ LintLevelReason :: Workspace ,
98
+ defined_level. priority ( ) ,
99
+ )
92
100
} else {
93
- ( unspecified_level, 0 )
101
+ ( unspecified_level, reason , 0 )
94
102
}
95
103
}
96
104
}
@@ -153,16 +161,16 @@ impl Lint {
153
161
lints : & TomlToolLints ,
154
162
ws_lints : & TomlToolLints ,
155
163
edition : Edition ,
156
- ) -> LintLevel {
164
+ ) -> ( LintLevel , LintLevelReason ) {
157
165
self . groups
158
166
. iter ( )
159
167
. map ( |g| ( g. name , g. level_priority ( lints, ws_lints, edition) ) )
160
168
. chain ( std:: iter:: once ( (
161
169
self . name ,
162
170
self . level_priority ( lints, ws_lints, edition) ,
163
171
) ) )
164
- . max_by_key ( |( n, ( l, p) ) | ( l == & LintLevel :: Forbid , * p, std:: cmp:: Reverse ( * n) ) )
165
- . map ( |( _, ( l, _) ) | l )
172
+ . max_by_key ( |( n, ( l, _ , p) ) | ( l == & LintLevel :: Forbid , * p, std:: cmp:: Reverse ( * n) ) )
173
+ . map ( |( _, ( l, r , _) ) | ( l , r ) )
166
174
. unwrap ( )
167
175
}
168
176
}
@@ -208,6 +216,25 @@ impl From<TomlLintLevel> for LintLevel {
208
216
}
209
217
}
210
218
219
+ #[ derive( Copy , Clone , Debug ) ]
220
+ pub enum LintLevelReason {
221
+ Default ,
222
+ Edition ( Edition ) ,
223
+ Package ,
224
+ Workspace ,
225
+ }
226
+
227
+ impl Display for LintLevelReason {
228
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
229
+ match self {
230
+ LintLevelReason :: Default => write ! ( f, "by default" ) ,
231
+ LintLevelReason :: Edition ( edition) => write ! ( f, "in edition {}" , edition) ,
232
+ LintLevelReason :: Package => write ! ( f, "in `[lints]`" ) ,
233
+ LintLevelReason :: Workspace => write ! ( f, "in `[workspace.lints]`" ) ,
234
+ }
235
+ }
236
+ }
237
+
211
238
const IM_A_TEAPOT : Lint = Lint {
212
239
name : "im_a_teapot" ,
213
240
desc : "`im_a_teapot` is specified" ,
@@ -225,7 +252,7 @@ pub fn check_im_a_teapot(
225
252
gctx : & GlobalContext ,
226
253
) -> CargoResult < ( ) > {
227
254
let manifest = pkg. manifest ( ) ;
228
- let lint_level = IM_A_TEAPOT . level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
255
+ let ( lint_level, reason ) = IM_A_TEAPOT . level ( pkg_lints, ws_lints, manifest. edition ( ) ) ;
229
256
if lint_level == LintLevel :: Allow {
230
257
return Ok ( ( ) ) ;
231
258
}
@@ -240,7 +267,10 @@ pub fn check_im_a_teapot(
240
267
}
241
268
let level = lint_level. to_diagnostic_level ( ) ;
242
269
let manifest_path = rel_cwd_manifest_path ( path, gctx) ;
243
- let emitted_reason = format ! ( "`cargo::{}` is set to `{lint_level}`" , IM_A_TEAPOT . name) ;
270
+ let emitted_reason = format ! (
271
+ "`cargo::{}` is set to `{lint_level}` {reason}" ,
272
+ IM_A_TEAPOT . name
273
+ ) ;
244
274
245
275
let key_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , false ) . unwrap ( ) ;
246
276
let value_span = get_span ( manifest. document ( ) , & [ "package" , "im-a-teapot" ] , true ) . unwrap ( ) ;
@@ -300,7 +330,7 @@ pub fn check_implicit_features(
300
330
return Ok ( ( ) ) ;
301
331
}
302
332
303
- let lint_level = IMPLICIT_FEATURES . level ( pkg_lints, ws_lints, edition) ;
333
+ let ( lint_level, reason ) = IMPLICIT_FEATURES . level ( pkg_lints, ws_lints, edition) ;
304
334
if lint_level == LintLevel :: Allow {
305
335
return Ok ( ( ) ) ;
306
336
}
@@ -345,7 +375,7 @@ pub fn check_implicit_features(
345
375
) ;
346
376
if emitted_source. is_none ( ) {
347
377
emitted_source = Some ( format ! (
348
- "`cargo::{}` is set to `{lint_level}`" ,
378
+ "`cargo::{}` is set to `{lint_level}` {reason} " ,
349
379
IMPLICIT_FEATURES . name
350
380
) ) ;
351
381
message = message. footer ( Level :: Note . title ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
@@ -383,7 +413,7 @@ pub fn unused_dependencies(
383
413
return Ok ( ( ) ) ;
384
414
}
385
415
386
- let lint_level = UNUSED_OPTIONAL_DEPENDENCY . level ( pkg_lints, ws_lints, edition) ;
416
+ let ( lint_level, reason ) = UNUSED_OPTIONAL_DEPENDENCY . level ( pkg_lints, ws_lints, edition) ;
387
417
if lint_level == LintLevel :: Allow {
388
418
return Ok ( ( ) ) ;
389
419
}
@@ -449,7 +479,7 @@ pub fn unused_dependencies(
449
479
) ;
450
480
if emitted_source. is_none ( ) {
451
481
emitted_source = Some ( format ! (
452
- "`cargo::{}` is set to `{lint_level}`" ,
482
+ "`cargo::{}` is set to `{lint_level}` {reason} " ,
453
483
UNUSED_OPTIONAL_DEPENDENCY . name
454
484
) ) ;
455
485
message =
0 commit comments