Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6540,6 +6540,7 @@ Released 2018-09-13
[`disallowed_methods`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods
[`disallowed_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names
[`disallowed_script_idents`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents
[`disallowed_trait_usage`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_trait_usage
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
Expand Down Expand Up @@ -7363,6 +7364,7 @@ Released 2018-09-13
[`disallowed-macros`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-macros
[`disallowed-methods`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-methods
[`disallowed-names`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-names
[`disallowed-trait-usage`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-trait-usage
[`disallowed-types`]: https://doc.rust-lang.org/clippy/lint_configuration.html#disallowed-types
[`doc-valid-idents`]: https://doc.rust-lang.org/clippy/lint_configuration.html#doc-valid-idents
[`enable-raw-pointer-heuristic-for-send`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enable-raw-pointer-heuristic-for-send
Expand Down
27 changes: 27 additions & 0 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,33 @@ default configuration of Clippy. By default, any configuration will replace the
* [`disallowed_names`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names)


## `disallowed-trait-usage`
The list of disallowed trait usages. Each entry forbids using a type via a specific
trait interface.

**Fields:**
- `type` (optional): the fully qualified path to a concrete type (e.g. `"i32"`, `"std::path::PathBuf"`)
- `implements` (optional): the fully qualified path to a trait; matches any type implementing it
- `trait` (required): the fully qualified path to the disallowed trait (e.g. `"std::fmt::Debug"`)
- `reason` (optional): explanation why this trait usage is disallowed

Exactly one of `type` or `implements` must be specified.

### Example
```toml
disallowed-trait-usage = [
{ type = "std::path::PathBuf", trait = "std::fmt::Debug", reason = "Use path.display() instead" },
{ implements = "std::error::Error", trait = "std::fmt::Debug", reason = "Use Display instead" },
]
```

**Default Value:** `[]`

---
**Affected lints:**
* [`disallowed_trait_usage`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_trait_usage)


## `disallowed-types`
The list of disallowed types, written as fully qualified paths.

Expand Down
20 changes: 20 additions & 0 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,26 @@ define_Conf! {
/// default configuration of Clippy. By default, any configuration will replace the default value.
#[lints(disallowed_names)]
disallowed_names: Vec<String> = DEFAULT_DISALLOWED_NAMES.iter().map(ToString::to_string).collect(),
/// The list of disallowed trait usages. Each entry forbids using a type via a specific
/// trait interface.
///
/// **Fields:**
/// - `type` (optional): the fully qualified path to a concrete type (e.g. `"i32"`, `"std::path::PathBuf"`)
/// - `implements` (optional): the fully qualified path to a trait; matches any type implementing it
/// - `trait` (required): the fully qualified path to the disallowed trait (e.g. `"std::fmt::Debug"`)
/// - `reason` (optional): explanation why this trait usage is disallowed
///
/// Exactly one of `type` or `implements` must be specified.
///
/// ### Example
/// ```toml
/// disallowed-trait-usage = [
/// { type = "std::path::PathBuf", trait = "std::fmt::Debug", reason = "Use path.display() instead" },
/// { implements = "std::error::Error", trait = "std::fmt::Debug", reason = "Use Display instead" },
/// ]
/// ```
#[lints(disallowed_trait_usage)]
disallowed_trait_usage: Vec<crate::types::DisallowedTraitUsage> = Vec::new(),
/// The list of disallowed types, written as fully qualified paths.
///
/// **Fields:**
Expand Down
23 changes: 23 additions & 0 deletions clippy_config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,28 @@ impl Serialize for SourceItemOrderingWithinModuleItemGroupings {
}
}

/// An entry in the `disallowed-trait-usage` configuration.
///
/// Forbids using a type via a specific trait interface. The type can be specified
/// either as a concrete type (`type`) or as a trait bound (`implements`), but not both.
#[derive(Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DisallowedTraitUsage {
/// The fully qualified path to a concrete type (e.g. `"i32"`, `"std::path::PathBuf"`).
/// Mutually exclusive with `implements`.
#[serde(rename = "type")]
pub type_path: Option<String>,
/// The fully qualified path to a trait (e.g. `"std::error::Error"`).
/// When set, the rule applies to any type that implements this trait.
/// Mutually exclusive with `type`.
pub implements: Option<String>,
/// The fully qualified path to the trait being disallowed (e.g. `"std::fmt::Debug"`).
#[serde(rename = "trait")]
pub trait_path: String,
/// Optional reason explaining why this usage is disallowed.
pub reason: Option<String>,
}

// these impls are never actually called but are used by the various config options that default to
// empty lists
macro_rules! unimplemented_serialize {
Expand All @@ -689,6 +711,7 @@ macro_rules! unimplemented_serialize {
}

unimplemented_serialize! {
DisallowedTraitUsage,
Rename,
MacroMatcher,
}
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/declared_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
crate::disallowed_methods::DISALLOWED_METHODS_INFO,
crate::disallowed_names::DISALLOWED_NAMES_INFO,
crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO,
crate::disallowed_trait_usage::DISALLOWED_TRAIT_USAGE_INFO,
crate::disallowed_types::DISALLOWED_TYPES_INFO,
crate::doc::DOC_BROKEN_LINK_INFO,
crate::doc::DOC_COMMENT_DOUBLE_SPACE_LINEBREAKS_INFO,
Expand Down
Loading
Loading