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 ;
55use rustc_session:: Session ;
66use rustc_span:: { BytePos , Pos , SourceFile , Span , SyntaxContext } ;
77use serde:: de:: { Deserializer , IgnoredAny , IntoDeserializer , MapAccess , Visitor } ;
@@ -38,37 +38,6 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
3838const DEFAULT_DISALLOWED_NAMES : & [ & str ] = & [ "foo" , "baz" , "quux" ] ;
3939const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS : & [ & str ] = & [ "i" , "j" , "x" , "y" , "z" , "w" , "n" ] ;
4040
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-
7241/// Conf with parse errors
7342#[ derive( Default ) ]
7443pub struct TryConf {
@@ -124,6 +93,7 @@ macro_rules! define_Conf {
12493 }
12594
12695 mod defaults {
96+ use super :: * ;
12797 $( pub fn $name( ) -> $ty { $default } ) *
12898 }
12999
@@ -190,31 +160,27 @@ macro_rules! define_Conf {
190160 }
191161 }
192162
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+ }
200167
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+ ]
218184 }
219185 } ;
220186}
@@ -236,7 +202,7 @@ define_Conf! {
236202 ///
237203 /// A type, say `SomeType`, listed in this configuration has the same behavior of
238204 /// `["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 ( ) ) ,
240206 /// Lint: ARITHMETIC_SIDE_EFFECTS.
241207 ///
242208 /// Suppress checking of the passed type pair names in binary operations like addition or
@@ -263,15 +229,15 @@ define_Conf! {
263229 /// ```toml
264230 /// arithmetic-side-effects-allowed-unary = ["SomeType", "AnotherType"]
265231 /// ```
266- ( arithmetic_side_effects_allowed_unary: rustc_data_structures :: fx :: FxHashSet <String > = <_>:: default ( ) ) ,
232+ ( arithmetic_side_effects_allowed_unary: FxHashSet <String > = <_>:: default ( ) ) ,
267233 /// 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.
268234 ///
269235 /// Suppress lints whenever the suggested change would cause breakage for other crates.
270236 ( avoid_breaking_exported_api: bool = true ) ,
271237 /// 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.
272238 ///
273239 /// The minimum rust version that the project supports
274- ( msrv: crate :: Msrv = crate :: Msrv :: empty( ) ) ,
240+ ( msrv: Msrv = Msrv :: empty( ) ) ,
275241 /// DEPRECATED LINT: BLACKLISTED_NAME.
276242 ///
277243 /// Use the Disallowed Names lint instead
@@ -295,7 +261,7 @@ define_Conf! {
295261 /// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
296262 /// `".."` can be used as part of the list to indicate that the configured values should be appended to the
297263 /// 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( ) ) ,
299265 /// Lint: SEMICOLON_INSIDE_BLOCK.
300266 ///
301267 /// Whether to lint only if it's multiline.
@@ -313,7 +279,7 @@ define_Conf! {
313279 /// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
314280 ///
315281 /// 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( ) ) ,
317283 /// Lint: TOO_MANY_ARGUMENTS.
318284 ///
319285 /// The maximum number of argument a function or method can have
@@ -393,15 +359,15 @@ define_Conf! {
393359 /// Lint: DISALLOWED_MACROS.
394360 ///
395361 /// 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( ) ) ,
397363 /// Lint: DISALLOWED_METHODS.
398364 ///
399365 /// 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( ) ) ,
401367 /// Lint: DISALLOWED_TYPES.
402368 ///
403369 /// 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( ) ) ,
405371 /// Lint: UNREADABLE_LITERAL.
406372 ///
407373 /// Should the fraction of a decimal be linted to include separators.
@@ -414,8 +380,7 @@ define_Conf! {
414380 ///
415381 /// Whether the matches should be considered by the lint, and whether there should
416382 /// 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 ) ,
419384 /// Lint: _CARGO_COMMON_METADATA.
420385 ///
421386 /// For internal testing only, ignores the current `publish` settings in the Cargo manifest.
@@ -427,11 +392,11 @@ define_Conf! {
427392 /// A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro
428393 /// could be used with a full path two `MacroMatcher`s have to be added one with the full path
429394 /// `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( ) ) ,
431396 /// Lint: MISSING_ENFORCED_IMPORT_RENAMES.
432397 ///
433398 /// 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( ) ) ,
435400 /// Lint: DISALLOWED_SCRIPT_IDENTS.
436401 ///
437402 /// The list of unicode scripts allowed to be used in the scope.
@@ -447,7 +412,7 @@ define_Conf! {
447412 /// For example, `[_, _, _, e, ..]` is a slice pattern with 4 elements.
448413 ( max_suggested_slice_pattern_length: u64 = 3 ) ,
449414 /// 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( ) ) ,
451416 /// Lint: LARGE_INCLUDE_FILE.
452417 ///
453418 /// The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes
@@ -511,8 +476,8 @@ define_Conf! {
511476 /// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
512477 /// the list to indicate, that the configured values should be appended to the default
513478 /// 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( ) ) ,
516481 /// Lint: MIN_IDENT_CHARS.
517482 ///
518483 /// Minimum chars an ident can have, anything below or equal to this will be linted.
@@ -537,13 +502,11 @@ define_Conf! {
537502 /// Lint: ABSOLUTE_PATHS.
538503 ///
539504 /// 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 ( ) ) ,
542506 /// Lint: PATH_ENDS_WITH_EXT.
543507 ///
544508 /// 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 ( ) ) ,
547510 /// Lint: EXPLICIT_ITER_LOOP
548511 ///
549512 /// Whether to recommend using implicit into iter for reborrowed values.
0 commit comments