2020-04-30 18:44:17 -05:00
|
|
|
#![warn(clippy::manual_non_exhaustive)]
|
|
|
|
#![allow(unused)]
|
2023-07-27 06:40:22 -05:00
|
|
|
//@no-rustfix
|
2024-09-04 16:22:28 -05:00
|
|
|
pub mod structs {
|
|
|
|
pub struct S {
|
|
|
|
//~^ manual_non_exhaustive
|
2020-04-30 18:44:17 -05:00
|
|
|
pub a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
_c: (),
|
|
|
|
}
|
|
|
|
|
2020-05-01 15:37:14 -05:00
|
|
|
// user forgot to remove the private field
|
|
|
|
#[non_exhaustive]
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct Sp {
|
|
|
|
//~^ manual_non_exhaustive
|
2020-05-01 15:37:14 -05:00
|
|
|
pub a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
_c: (),
|
|
|
|
}
|
|
|
|
|
2020-04-30 18:44:17 -05:00
|
|
|
// some other fields are private, should be ignored
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct PrivateFields {
|
2020-04-30 18:44:17 -05:00
|
|
|
a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
_c: (),
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct NoUnderscore {
|
|
|
|
//~^ manual_non_exhaustive
|
2020-04-30 18:44:17 -05:00
|
|
|
pub a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
c: (),
|
|
|
|
}
|
|
|
|
|
|
|
|
// private field is not unit type, should be ignored
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct NotUnit {
|
2020-04-30 18:44:17 -05:00
|
|
|
pub a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
_c: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// private field is the only field, should be ignored
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct OnlyMarker {
|
2020-04-30 18:44:17 -05:00
|
|
|
_a: (),
|
|
|
|
}
|
|
|
|
|
2020-05-01 15:37:14 -05:00
|
|
|
// already non exhaustive and no private fields, should be ignored
|
2020-04-30 18:44:17 -05:00
|
|
|
#[non_exhaustive]
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct NonExhaustive {
|
2020-04-30 18:44:17 -05:00
|
|
|
pub a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-04 16:22:28 -05:00
|
|
|
pub mod tuple_structs {
|
|
|
|
pub struct T(pub i32, pub i32, ());
|
|
|
|
//~^ manual_non_exhaustive
|
2020-04-30 18:44:17 -05:00
|
|
|
|
2020-05-01 15:37:14 -05:00
|
|
|
// user forgot to remove the private field
|
|
|
|
#[non_exhaustive]
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct Tp(pub i32, pub i32, ());
|
|
|
|
//~^ manual_non_exhaustive
|
2020-05-01 15:37:14 -05:00
|
|
|
|
2020-04-30 18:44:17 -05:00
|
|
|
// some other fields are private, should be ignored
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct PrivateFields(pub i32, i32, ());
|
2020-04-30 18:44:17 -05:00
|
|
|
|
|
|
|
// private field is not unit type, should be ignored
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct NotUnit(pub i32, pub i32, i32);
|
2020-04-30 18:44:17 -05:00
|
|
|
|
|
|
|
// private field is the only field, should be ignored
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct OnlyMarker(());
|
2020-04-30 18:44:17 -05:00
|
|
|
|
2020-05-01 15:37:14 -05:00
|
|
|
// already non exhaustive and no private fields, should be ignored
|
2020-04-30 18:44:17 -05:00
|
|
|
#[non_exhaustive]
|
2024-09-04 16:22:28 -05:00
|
|
|
pub struct NonExhaustive(pub i32, pub i32);
|
2020-04-30 18:44:17 -05:00
|
|
|
}
|
|
|
|
|
2024-09-04 16:22:28 -05:00
|
|
|
mod private {
|
|
|
|
// Don't lint structs that are not actually public as `#[non_exhaustive]` only applies to
|
|
|
|
// external crates. The manual pattern can still be used to get module local non exhaustiveness
|
|
|
|
pub struct NotPublic {
|
|
|
|
pub a: i32,
|
|
|
|
pub b: i32,
|
|
|
|
_c: (),
|
|
|
|
}
|
|
|
|
}
|