Skip to content

Commit 93c0223

Browse files
committed
partly disable unneeded_wildcard_pattern when rest_pattern_accessible_field is enabled
1 parent 3f58335 commit 93c0223

3 files changed

Lines changed: 5 additions & 3 deletions

File tree

clippy_lints/src/misc_early/unneeded_wildcard_pattern.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use rustc_ast::ast::{Pat, PatFieldsRest, PatKind};
33
use rustc_errors::Applicability;
4-
use rustc_lint::EarlyContext;
4+
use rustc_lint::{EarlyContext, LintContext as _};
55
use rustc_span::Span;
66

77
use super::UNNEEDED_WILDCARD_PATTERN;
@@ -40,6 +40,8 @@ pub(super) fn check(cx: &EarlyContext<'_>, pat: &Pat) {
4040
.take_while(|patfield| matches!(patfield.pat.kind, PatKind::Wild))
4141
.enumerate()
4242
.last()
43+
// Only run if `rest_pattern_accessible_field` is Allow, as they otherwise will contradict each other.
44+
&& cx.get_lint_level_spec(crate::rest_when_destructuring_struct::REST_PATTERN_ACCESSIBLE_FIELD).is_allow()
4345
{
4446
// Unlike the tuples above, structs have patfields rather than patterns, and separate out the
4547
// `..` into a separate parameter. Also, the `..` can only be at the end of the pattern.

tests/ui/rest_pattern_accessible_field.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macros.rs
22
//@aux-build:non-exhaustive-struct.rs
33
#![warn(clippy::rest_pattern_accessible_field)]
4-
#![allow(clippy::unneeded_wildcard_pattern)]
4+
#![warn(clippy::unneeded_wildcard_pattern)]
55

66
use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields};
77

tests/ui/rest_pattern_accessible_field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@aux-build:proc_macros.rs
22
//@aux-build:non-exhaustive-struct.rs
33
#![warn(clippy::rest_pattern_accessible_field)]
4-
#![allow(clippy::unneeded_wildcard_pattern)]
4+
#![warn(clippy::unneeded_wildcard_pattern)]
55

66
use non_exhaustive_struct::{NonExhaustiveStruct, NonExhaustiveStructNoPrivateFields};
77

0 commit comments

Comments
 (0)