Skip to content

Commit 4524d7d

Browse files
committed
Add allow-invalid configuration option for disallowed_* to the documentation
1 parent 689e62b commit 4524d7d

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

book/src/lint_configuration.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,11 @@ The maximum cognitive complexity a function can have
477477

478478
## `disallowed-macros`
479479
The list of disallowed macros, written as fully qualified paths.
480+
Fields:
481+
path (required): the fully qualified path to the macro that should be disallowed;
482+
reason (optional): explanation why this macro is disallowed;
483+
replacement (optional): suggested alternative macro;
484+
allow-invalid (optional, false by default): when set to true, it will ignore this entry if the path doesn't exist, instead of emitting an error.
480485

481486
**Default Value:** `[]`
482487

@@ -487,6 +492,11 @@ The list of disallowed macros, written as fully qualified paths.
487492

488493
## `disallowed-methods`
489494
The list of disallowed methods, written as fully qualified paths.
495+
Fields:
496+
path (required): the fully qualified path to the method that should be disallowed;
497+
reason (optional): explanation why this method is disallowed;
498+
replacement (optional): suggested alternative method;
499+
allow-invalid (optional, false by default): when set to true, it will ignore this entry if the path doesn't exist, instead of emitting an error.
490500

491501
**Default Value:** `[]`
492502

@@ -509,6 +519,11 @@ default configuration of Clippy. By default, any configuration will replace the
509519

510520
## `disallowed-types`
511521
The list of disallowed types, written as fully qualified paths.
522+
Fields:
523+
path (required): the fully qualified path to the type that should be disallowed;
524+
reason (optional): explanation why this type is disallowed;
525+
replacement (optional): suggested alternative type;
526+
allow-invalid (optional, false by default): when set to true, it will ignore this entry if the path doesn't exist, instead of emitting an error.
512527

513528
**Default Value:** `[]`
514529

clippy_config/src/conf.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,22 @@ define_Conf! {
572572
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead", cognitive_complexity_threshold)]
573573
cyclomatic_complexity_threshold: u64 = 25,
574574
/// The list of disallowed macros, written as fully qualified paths.
575+
/// Fields:
576+
/// path (required): the fully qualified path to the macro that should be disallowed;
577+
/// reason (optional): explanation why this macro is disallowed;
578+
/// replacement (optional): suggested alternative macro;
579+
/// allow-invalid (optional, false by default): when set to true, it will ignore this entry
580+
/// if the path doesn't exist, instead of emitting an error.
575581
#[disallowed_paths_allow_replacements = true]
576582
#[lints(disallowed_macros)]
577583
disallowed_macros: Vec<DisallowedPath> = Vec::new(),
578584
/// The list of disallowed methods, written as fully qualified paths.
585+
/// Fields:
586+
/// path (required): the fully qualified path to the method that should be disallowed;
587+
/// reason (optional): explanation why this method is disallowed;
588+
/// replacement (optional): suggested alternative method;
589+
/// allow-invalid (optional, false by default): when set to true, it will ignore this entry
590+
/// if the path doesn't exist, instead of emitting an error.
579591
#[disallowed_paths_allow_replacements = true]
580592
#[lints(disallowed_methods)]
581593
disallowed_methods: Vec<DisallowedPath> = Vec::new(),
@@ -585,6 +597,12 @@ define_Conf! {
585597
#[lints(disallowed_names)]
586598
disallowed_names: Vec<String> = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect(),
587599
/// The list of disallowed types, written as fully qualified paths.
600+
/// Fields:
601+
/// path (required): the fully qualified path to the type that should be disallowed;
602+
/// reason (optional): explanation why this type is disallowed;
603+
/// replacement (optional): suggested alternative type;
604+
/// allow-invalid (optional, false by default): when set to true, it will ignore this entry
605+
/// if the path doesn't exist, instead of emitting an error.
588606
#[disallowed_paths_allow_replacements = true]
589607
#[lints(disallowed_types)]
590608
disallowed_types: Vec<DisallowedPath> = Vec::new(),

clippy_lints/src/disallowed_macros.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ declare_clippy_lint! {
3838
/// # When using an inline table, can add a `reason` for why the macro
3939
/// # is disallowed.
4040
/// { path = "serde::Serialize", reason = "no serializing" },
41+
/// # This would normally error if the path is incorrect, but with allow-invalid = true,
42+
/// # it will be silently ignored
43+
/// { path = "std::invalid_macro", reason = "use alternative instead", allow-invalid = true }
4144
/// ]
4245
/// ```
4346
/// ```no_run

clippy_lints/src/disallowed_methods.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ declare_clippy_lint! {
3333
/// { path = "std::vec::Vec::leak", reason = "no leaking memory" },
3434
/// # Can also add a `replacement` that will be offered as a suggestion.
3535
/// { path = "std::sync::Mutex::new", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex::new" },
36+
/// # This would normally error if the path is incorrect, but with allow-invalid = true,
37+
/// # it will be silently ignored
38+
/// { path = "std::fs::InvalidPath", reason = "use alternative instead", allow-invalid = true },
3639
/// ]
3740
/// ```
3841
///

clippy_lints/src/disallowed_types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ declare_clippy_lint! {
3434
/// { path = "std::net::Ipv4Addr", reason = "no IPv4 allowed" },
3535
/// # Can also add a `replacement` that will be offered as a suggestion.
3636
/// { path = "std::sync::Mutex", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex" },
37+
/// # This would normally error if the path is incorrect, but with allow-invalid = true,
38+
/// # it will be silently ignored
39+
/// { path = "std::invalid::Type", reason = "use alternative instead", allow-invalid = true }
3740
/// ]
3841
/// ```
3942
///

0 commit comments

Comments
 (0)