1
- //! Read configurations files.
2
-
3
- #! [ allow ( clippy :: module_name_repetitions ) ]
4
-
1
+ use crate :: msrvs :: Msrv ;
2
+ use crate :: types :: { DisallowedPath , MacroMatcher , MatchLintBehaviour , Rename } ;
3
+ use crate :: ClippyConfiguration ;
4
+ use rustc_data_structures :: fx :: FxHashSet ;
5
5
use rustc_session:: Session ;
6
6
use rustc_span:: { BytePos , Pos , SourceFile , Span , SyntaxContext } ;
7
7
use serde:: de:: { Deserializer , IgnoredAny , IntoDeserializer , MapAccess , Visitor } ;
@@ -38,37 +38,6 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
38
38
const DEFAULT_DISALLOWED_NAMES : & [ & str ] = & [ "foo" , "baz" , "quux" ] ;
39
39
const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS : & [ & str ] = & [ "i" , "j" , "x" , "y" , "z" , "w" , "n" ] ;
40
40
41
- /// Holds information used by `MISSING_ENFORCED_IMPORT_RENAMES` lint.
42
- #[ derive( Clone , Debug , Deserialize ) ]
43
- pub struct Rename {
44
- pub path : String ,
45
- pub rename : String ,
46
- }
47
-
48
- #[ derive( Clone , Debug , Deserialize ) ]
49
- #[ serde( untagged) ]
50
- pub enum DisallowedPath {
51
- Simple ( String ) ,
52
- WithReason { path : String , reason : Option < String > } ,
53
- }
54
-
55
- impl DisallowedPath {
56
- pub fn path ( & self ) -> & str {
57
- let ( Self :: Simple ( path) | Self :: WithReason { path, .. } ) = self ;
58
-
59
- path
60
- }
61
-
62
- pub fn reason ( & self ) -> Option < String > {
63
- match self {
64
- Self :: WithReason {
65
- reason : Some ( reason) , ..
66
- } => Some ( format ! ( "{reason} (from clippy.toml)" ) ) ,
67
- _ => None ,
68
- }
69
- }
70
- }
71
-
72
41
/// Conf with parse errors
73
42
#[ derive( Default ) ]
74
43
pub struct TryConf {
@@ -124,6 +93,7 @@ macro_rules! define_Conf {
124
93
}
125
94
126
95
mod defaults {
96
+ use super :: * ;
127
97
$( pub fn $name( ) -> $ty { $default } ) *
128
98
}
129
99
@@ -190,31 +160,27 @@ macro_rules! define_Conf {
190
160
}
191
161
}
192
162
193
- pub mod metadata {
194
- use crate :: utils:: ClippyConfiguration ;
195
-
196
- macro_rules! wrap_option {
197
- ( ) => ( None ) ;
198
- ( $x: literal) => ( Some ( $x) ) ;
199
- }
163
+ macro_rules! wrap_option {
164
+ ( ) => ( None ) ;
165
+ ( $x: literal) => ( Some ( $x) ) ;
166
+ }
200
167
201
- pub fn get_configuration_metadata( ) -> Vec <ClippyConfiguration > {
202
- vec![
203
- $(
204
- {
205
- let deprecation_reason = wrap_option!( $( $dep) ?) ;
206
-
207
- ClippyConfiguration :: new(
208
- stringify!( $name) ,
209
- stringify!( $ty) ,
210
- format!( "{:?}" , super :: defaults:: $name( ) ) ,
211
- concat!( $( $doc, '\n' , ) * ) ,
212
- deprecation_reason,
213
- )
214
- } ,
215
- ) +
216
- ]
217
- }
168
+ pub fn get_configuration_metadata( ) -> Vec <ClippyConfiguration > {
169
+ vec![
170
+ $(
171
+ {
172
+ let deprecation_reason = wrap_option!( $( $dep) ?) ;
173
+
174
+ ClippyConfiguration :: new(
175
+ stringify!( $name) ,
176
+ stringify!( $ty) ,
177
+ format!( "{:?}" , defaults:: $name( ) ) ,
178
+ concat!( $( $doc, '\n' , ) * ) ,
179
+ deprecation_reason,
180
+ )
181
+ } ,
182
+ ) +
183
+ ]
218
184
}
219
185
} ;
220
186
}
@@ -236,7 +202,7 @@ define_Conf! {
236
202
///
237
203
/// A type, say `SomeType`, listed in this configuration has the same behavior of
238
204
/// `["SomeType" , "*"], ["*", "SomeType"]` in `arithmetic_side_effects_allowed_binary`.
239
- ( arithmetic_side_effects_allowed: rustc_data_structures :: fx :: FxHashSet <String > = <_>:: default ( ) ) ,
205
+ ( arithmetic_side_effects_allowed: FxHashSet <String > = <_>:: default ( ) ) ,
240
206
/// Lint: ARITHMETIC_SIDE_EFFECTS.
241
207
///
242
208
/// Suppress checking of the passed type pair names in binary operations like addition or
@@ -263,15 +229,15 @@ define_Conf! {
263
229
/// ```toml
264
230
/// arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
265
231
/// ```
266
- ( arithmetic_side_effects_allowed_unary: rustc_data_structures :: fx :: FxHashSet <String > = <_>:: default ( ) ) ,
232
+ ( arithmetic_side_effects_allowed_unary: FxHashSet <String > = <_>:: default ( ) ) ,
267
233
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UNUSED_SELF, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION, BOX_COLLECTION, REDUNDANT_ALLOCATION, RC_BUFFER, VEC_BOX, OPTION_OPTION, LINKEDLIST, RC_MUTEX, UNNECESSARY_BOX_RETURNS, SINGLE_CALL_FN.
268
234
///
269
235
/// Suppress lints whenever the suggested change would cause breakage for other crates.
270
236
( avoid_breaking_exported_api: bool = true ) ,
271
237
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE.
272
238
///
273
239
/// The minimum rust version that the project supports
274
- ( msrv: crate :: Msrv = crate :: Msrv :: empty( ) ) ,
240
+ ( msrv: Msrv = Msrv :: empty( ) ) ,
275
241
/// DEPRECATED LINT: BLACKLISTED_NAME.
276
242
///
277
243
/// Use the Disallowed Names lint instead
@@ -295,7 +261,7 @@ define_Conf! {
295
261
/// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
296
262
/// `".."` can be used as part of the list to indicate that the configured values should be appended to the
297
263
/// default configuration of Clippy. By default, any configuration will replace the default value.
298
- ( disallowed_names: Vec <String > = super :: DEFAULT_DISALLOWED_NAMES . iter( ) . map( ToString :: to_string) . collect( ) ) ,
264
+ ( disallowed_names: Vec <String > = DEFAULT_DISALLOWED_NAMES . iter( ) . map( ToString :: to_string) . collect( ) ) ,
299
265
/// Lint: SEMICOLON_INSIDE_BLOCK.
300
266
///
301
267
/// Whether to lint only if it's multiline.
@@ -313,7 +279,7 @@ define_Conf! {
313
279
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
314
280
///
315
281
/// Default list:
316
- ( doc_valid_idents: Vec <String > = super :: DEFAULT_DOC_VALID_IDENTS . iter( ) . map( ToString :: to_string) . collect( ) ) ,
282
+ ( doc_valid_idents: Vec <String > = DEFAULT_DOC_VALID_IDENTS . iter( ) . map( ToString :: to_string) . collect( ) ) ,
317
283
/// Lint: TOO_MANY_ARGUMENTS.
318
284
///
319
285
/// The maximum number of argument a function or method can have
@@ -393,15 +359,15 @@ define_Conf! {
393
359
/// Lint: DISALLOWED_MACROS.
394
360
///
395
361
/// The list of disallowed macros, written as fully qualified paths.
396
- ( disallowed_macros: Vec <crate :: utils :: conf :: DisallowedPath > = Vec :: new( ) ) ,
362
+ ( disallowed_macros: Vec <DisallowedPath > = Vec :: new( ) ) ,
397
363
/// Lint: DISALLOWED_METHODS.
398
364
///
399
365
/// The list of disallowed methods, written as fully qualified paths.
400
- ( disallowed_methods: Vec <crate :: utils :: conf :: DisallowedPath > = Vec :: new( ) ) ,
366
+ ( disallowed_methods: Vec <DisallowedPath > = Vec :: new( ) ) ,
401
367
/// Lint: DISALLOWED_TYPES.
402
368
///
403
369
/// The list of disallowed types, written as fully qualified paths.
404
- ( disallowed_types: Vec <crate :: utils :: conf :: DisallowedPath > = Vec :: new( ) ) ,
370
+ ( disallowed_types: Vec <DisallowedPath > = Vec :: new( ) ) ,
405
371
/// Lint: UNREADABLE_LITERAL.
406
372
///
407
373
/// Should the fraction of a decimal be linted to include separators.
@@ -414,8 +380,7 @@ define_Conf! {
414
380
///
415
381
/// Whether the matches should be considered by the lint, and whether there should
416
382
/// be filtering for common types.
417
- ( matches_for_let_else: crate :: manual_let_else:: MatchLintBehaviour =
418
- crate :: manual_let_else:: MatchLintBehaviour :: WellKnownTypes ) ,
383
+ ( matches_for_let_else: MatchLintBehaviour = MatchLintBehaviour :: WellKnownTypes ) ,
419
384
/// Lint: _CARGO_COMMON_METADATA.
420
385
///
421
386
/// For internal testing only, ignores the current `publish` settings in the Cargo manifest.
@@ -427,11 +392,11 @@ define_Conf! {
427
392
/// A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro
428
393
/// could be used with a full path two `MacroMatcher`s have to be added one with the full path
429
394
/// `crate_name::macro_name` and one with just the macro name.
430
- ( standard_macro_braces: Vec <crate :: nonstandard_macro_braces :: MacroMatcher > = Vec :: new( ) ) ,
395
+ ( standard_macro_braces: Vec <MacroMatcher > = Vec :: new( ) ) ,
431
396
/// Lint: MISSING_ENFORCED_IMPORT_RENAMES.
432
397
///
433
398
/// The list of imports to always rename, a fully qualified path followed by the rename.
434
- ( enforced_import_renames: Vec <crate :: utils :: conf :: Rename > = Vec :: new( ) ) ,
399
+ ( enforced_import_renames: Vec <Rename > = Vec :: new( ) ) ,
435
400
/// Lint: DISALLOWED_SCRIPT_IDENTS.
436
401
///
437
402
/// The list of unicode scripts allowed to be used in the scope.
@@ -447,7 +412,7 @@ define_Conf! {
447
412
/// For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements.
448
413
( max_suggested_slice_pattern_length: u64 = 3 ) ,
449
414
/// Lint: AWAIT_HOLDING_INVALID_TYPE.
450
- ( await_holding_invalid_types: Vec <crate :: utils :: conf :: DisallowedPath > = Vec :: new( ) ) ,
415
+ ( await_holding_invalid_types: Vec <DisallowedPath > = Vec :: new( ) ) ,
451
416
/// Lint: LARGE_INCLUDE_FILE.
452
417
///
453
418
/// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes
@@ -511,8 +476,8 @@ define_Conf! {
511
476
/// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
512
477
/// the list to indicate, that the configured values should be appended to the default
513
478
/// configuration of Clippy. By default, any configuration will replace the default value.
514
- ( allowed_idents_below_min_chars: rustc_data_structures :: fx :: FxHashSet <String > =
515
- super :: DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS . iter( ) . map( ToString :: to_string) . collect( ) ) ,
479
+ ( allowed_idents_below_min_chars: FxHashSet <String > =
480
+ DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS . iter( ) . map( ToString :: to_string) . collect( ) ) ,
516
481
/// Lint: MIN_IDENT_CHARS.
517
482
///
518
483
/// Minimum chars an ident can have, anything below or equal to this will be linted.
@@ -537,13 +502,11 @@ define_Conf! {
537
502
/// Lint: ABSOLUTE_PATHS.
538
503
///
539
504
/// Which crates to allow absolute paths from
540
- ( absolute_paths_allowed_crates: rustc_data_structures:: fx:: FxHashSet <String > =
541
- rustc_data_structures:: fx:: FxHashSet :: default ( ) ) ,
505
+ ( absolute_paths_allowed_crates: FxHashSet <String > = FxHashSet :: default ( ) ) ,
542
506
/// Lint: PATH_ENDS_WITH_EXT.
543
507
///
544
508
/// Additional dotfiles (files or directories starting with a dot) to allow
545
- ( allowed_dotfiles: rustc_data_structures:: fx:: FxHashSet <String > =
546
- rustc_data_structures:: fx:: FxHashSet :: default ( ) ) ,
509
+ ( allowed_dotfiles: FxHashSet <String > = FxHashSet :: default ( ) ) ,
547
510
/// Lint: EXPLICIT_ITER_LOOP
548
511
///
549
512
/// Whether to recommend using implicit into iter for reborrowed values.
0 commit comments