@@ -6,6 +6,7 @@ use annotate_snippets::{Level, Renderer, Snippet};
6
6
use cargo_util_schemas:: manifest:: { TomlLintLevel , TomlToolLints } ;
7
7
use pathdiff:: diff_paths;
8
8
use std:: collections:: HashSet ;
9
+ use std:: fmt:: Display ;
9
10
use std:: ops:: Range ;
10
11
use std:: path:: Path ;
11
12
use toml_edit:: ImDocument ;
@@ -107,6 +108,17 @@ pub enum LintLevel {
107
108
Forbid ,
108
109
}
109
110
111
+ impl Display for LintLevel {
112
+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
113
+ match self {
114
+ LintLevel :: Allow => write ! ( f, "allow" ) ,
115
+ LintLevel :: Warn => write ! ( f, "warn" ) ,
116
+ LintLevel :: Deny => write ! ( f, "deny" ) ,
117
+ LintLevel :: Forbid => write ! ( f, "forbid" ) ,
118
+ }
119
+ }
120
+ }
121
+
110
122
impl LintLevel {
111
123
pub fn to_diagnostic_level ( self ) -> Level {
112
124
match self {
@@ -184,6 +196,7 @@ pub fn check_implicit_features(
184
196
} )
185
197
. unwrap_or_default ( ) ;
186
198
199
+ let mut emitted_source = None ;
187
200
for dep in manifest. dependencies ( ) {
188
201
let dep_name_in_toml = dep. name_in_toml ( ) ;
189
202
if !dep. is_optional ( ) || activated_opt_deps. contains ( dep_name_in_toml. as_str ( ) ) {
@@ -200,12 +213,19 @@ pub fn check_implicit_features(
200
213
}
201
214
let level = lint_level. to_diagnostic_level ( ) ;
202
215
let manifest_path = rel_cwd_manifest_path ( path, gctx) ;
203
- let message = level. title ( IMPLICIT_FEATURES . desc ) . snippet (
216
+ let mut message = level. title ( IMPLICIT_FEATURES . desc ) . snippet (
204
217
Snippet :: source ( manifest. contents ( ) )
205
218
. origin ( & manifest_path)
206
219
. annotation ( level. span ( get_span ( manifest. document ( ) , & toml_path, false ) . unwrap ( ) ) )
207
220
. fold ( true ) ,
208
221
) ;
222
+ if emitted_source. is_none ( ) {
223
+ emitted_source = Some ( format ! (
224
+ "`cargo::{}` is set to `{lint_level}`" ,
225
+ IMPLICIT_FEATURES . name
226
+ ) ) ;
227
+ message = message. footer ( Level :: Note . title ( emitted_source. as_ref ( ) . unwrap ( ) ) ) ;
228
+ }
209
229
let renderer = Renderer :: styled ( ) . term_width (
210
230
gctx. shell ( )
211
231
. err_width ( )
0 commit comments