Auto merge of #11107 - Centri3:error_impl_error, r=Jarcho

New lint [`error_impl_error`]

Closes #11101

changelog: New lint [`error_impl_error`]
This commit is contained in:
bors 2023-07-20 02:07:27 +00:00
commit d71fbb9db2
6 changed files with 226 additions and 0 deletions

View file

@ -0,0 +1,90 @@
#![allow(unused)]
#![warn(clippy::error_impl_error)]
#![no_main]
pub mod a {
#[derive(Debug)]
pub struct Error;
impl std::fmt::Display for Error {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::error::Error for Error {}
}
mod b {
#[derive(Debug)]
pub(super) enum Error {}
impl std::fmt::Display for Error {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::error::Error for Error {}
}
pub mod c {
pub union Error {
a: u32,
b: u32,
}
impl std::fmt::Debug for Error {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::fmt::Display for Error {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::error::Error for Error {}
}
pub mod d {
pub type Error = std::fmt::Error;
}
mod e {
#[derive(Debug)]
pub(super) struct MyError;
impl std::fmt::Display for MyError {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::error::Error for MyError {}
}
pub mod f {
pub type MyError = std::fmt::Error;
}
// Do not lint module-private types
mod g {
#[derive(Debug)]
enum Error {}
impl std::fmt::Display for Error {
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
todo!()
}
}
impl std::error::Error for Error {}
}
mod h {
type Error = std::fmt::Error;
}

View file

@ -0,0 +1,45 @@
error: exported type named `Error` that implements `Error`
--> $DIR/error_impl_error.rs:7:16
|
LL | pub struct Error;
| ^^^^^
|
note: `Error` was implemented here
--> $DIR/error_impl_error.rs:15:5
|
LL | impl std::error::Error for Error {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `-D clippy::error-impl-error` implied by `-D warnings`
error: exported type named `Error` that implements `Error`
--> $DIR/error_impl_error.rs:20:21
|
LL | pub(super) enum Error {}
| ^^^^^
|
note: `Error` was implemented here
--> $DIR/error_impl_error.rs:28:5
|
LL | impl std::error::Error for Error {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: exported type named `Error` that implements `Error`
--> $DIR/error_impl_error.rs:32:15
|
LL | pub union Error {
| ^^^^^
|
note: `Error` was implemented here
--> $DIR/error_impl_error.rs:49:5
|
LL | impl std::error::Error for Error {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: exported type alias named `Error` that implements `Error`
--> $DIR/error_impl_error.rs:53:14
|
LL | pub type Error = std::fmt::Error;
| ^^^^^
error: aborting due to 4 previous errors