Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not trigger `[rest_pat_in_fully_bound_structs] on #[non_exhaustive]` structs #8690

Merged
merged 1 commit into from Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_lints/src/matches/rest_pat_in_fully_bound_struct.rs
Expand Up @@ -14,6 +14,7 @@ pub(crate) fn check(cx: &LateContext<'_>, pat: &Pat<'_>) {
if let ty::Adt(def, _) = ty.kind();
if def.is_struct() || def.is_union();
if fields.len() == def.non_enum_variant().fields.len();
if !def.non_enum_variant().is_field_list_non_exhaustive();

then {
span_lint_and_help(
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/rest_pat_in_fully_bound_structs.rs
Expand Up @@ -39,4 +39,19 @@ fn main() {

// No lint
foo!(a_struct);

#[non_exhaustive]
struct B {
a: u32,
b: u32,
c: u64,
}

let b_struct = B { a: 5, b: 42, c: 342 };

match b_struct {
B { a: 5, b: 42, .. } => {},
B { a: 0, b: 0, c: 128, .. } => {}, // No Lint
_ => {},
}
}