Properly handle disallowed_types

This commit is contained in:
Samuel Moelius 2024-11-13 10:16:59 -05:00
parent f159a3eb1d
commit d0f3577720
6 changed files with 58 additions and 15 deletions

View file

@ -0,0 +1,3 @@
disallowed-types = [
{ path = "std::string::String", replacement = "wrapper::String" },
]

View file

@ -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");
}

View file

@ -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");
}

View file

@ -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