Properly handle disallowed_types
This commit is contained in:
parent
f159a3eb1d
commit
d0f3577720
6 changed files with 58 additions and 15 deletions
3
tests/ui-toml/replaceable_disallowed_types/clippy.toml
Normal file
3
tests/ui-toml/replaceable_disallowed_types/clippy.toml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
disallowed-types = [
|
||||
{ path = "std::string::String", replacement = "wrapper::String" },
|
||||
]
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#![warn(clippy::disallowed_types)]
|
||||
|
||||
#[allow(clippy::disallowed_types)]
|
||||
mod wrapper {
|
||||
pub struct String(std::string::String);
|
||||
|
||||
impl From<&str> for String {
|
||||
fn from(value: &str) -> Self {
|
||||
Self(std::string::String::from(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = wrapper::String::from("x");
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#![warn(clippy::disallowed_types)]
|
||||
|
||||
#[allow(clippy::disallowed_types)]
|
||||
mod wrapper {
|
||||
pub struct String(std::string::String);
|
||||
|
||||
impl From<&str> for String {
|
||||
fn from(value: &str) -> Self {
|
||||
Self(std::string::String::from(value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = String::from("x");
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error: use of a disallowed type `std::string::String`
|
||||
--> tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs:15:13
|
||||
|
|
||||
LL | let _ = String::from("x");
|
||||
| ^^^^^^ help: use: `wrapper::String`
|
||||
|
|
||||
= note: `-D clippy::disallowed-types` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue