Skip to content

Commit 21edfe2

Browse files
committed
handle other review notes
1 parent 997f4d2 commit 21edfe2

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

clippy_lints/src/rest_when_destructuring_struct.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::is_from_proc_macro;
3+
use rustc_errors::Applicability;
34
use rustc_lint::LateLintPass;
45
use rustc_middle::ty;
56
use rustc_session::declare_lint_pass;
@@ -10,7 +11,7 @@ declare_clippy_lint! {
1011
/// ### What it does
1112
/// Disallow the use of rest patterns for accesible fields
1213
///
13-
/// ### Why is this bad?
14+
/// ### Why restrict this?
1415
/// It might lead to unhandled fields when the struct changes.
1516
///
1617
/// ### Example
@@ -37,17 +38,17 @@ declare_clippy_lint! {
3738
///
3839
/// let S { a, b, c: _ } = s;
3940
/// ```
40-
#[clippy::version = "1.94.0"]
41+
#[clippy::version = "1.98.0"]
4142
pub REST_PATTERN_ACCESSIBLE_FIELD,
4243
restriction,
43-
"rest (..) used for accessible field"
44+
"rest pattern (`..`) used for accessible field"
4445
}
4546

4647
declare_clippy_lint! {
4748
/// ### What it does
48-
/// Disallow the use of rest patterns that are unnecessary.
49+
/// Disallow the use of rest patterns that don't capture any fields.
4950
///
50-
/// ### Why is this bad?
51+
/// ### Why restrict this?
5152
/// It might lead to unhandled fields when the struct changes.
5253
///
5354
/// ### Example
@@ -74,10 +75,10 @@ declare_clippy_lint! {
7475
///
7576
/// let S { a, b, c } = s;
7677
/// ```
77-
#[clippy::version = "1.94.0"]
78+
#[clippy::version = "1.98.0"]
7879
pub UNNECESSARY_REST_PATTERN,
7980
restriction,
80-
"unnecessary rest (..) in destructuring expression"
81+
"unnecessary rest pattern (`..`) in destructuring expression"
8182
}
8283

8384
declare_lint_pass!(RestWhenDestructuringStruct => [
@@ -116,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct {
116117
}
117118

118119
// Filter out results from macros
119-
if ((missing_suggestions.is_empty() && !needs_dotdot) || !missing_suggestions.is_empty())
120+
if (!needs_dotdot || !missing_suggestions.is_empty())
120121
&& pat.span.in_external_macro(cx.tcx.sess.source_map())
121122
|| is_from_proc_macro(cx, pat)
122123
{
@@ -147,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct {
147148
suggestion_span,
148149
message,
149150
&missing_suggestions,
150-
rustc_errors::Applicability::MachineApplicable,
151+
Applicability::MachineApplicable,
151152
);
152153
},
153154
);
@@ -161,12 +162,7 @@ impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct {
161162
pat.span,
162163
"unnecessary rest pattern (`..`)",
163164
|diag| {
164-
diag.span_suggestion_verbose(
165-
dotdot,
166-
message,
167-
"",
168-
rustc_errors::Applicability::MachineApplicable,
169-
);
165+
diag.span_suggestion_verbose(dotdot, message, "", Applicability::MachineApplicable);
170166
},
171167
);
172168
}

clippy_utils/src/check_proc_macro.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,8 @@ fn ident_search_pat(ident: Ident) -> (Pat, Pat) {
591591

592592
fn pat_search_pat(tcx: TyCtxt<'_>, pat: &rustc_hir::Pat<'_>) -> (Pat, Pat) {
593593
match pat.kind {
594-
PatKind::Missing | PatKind::Err(_) => (Pat::Str(""), Pat::Str("")),
594+
// Tuple patterns cannot show up in proc-macro checks
595+
PatKind::Missing | PatKind::Err(_) | PatKind::Tuple(_, _) => (Pat::Str(""), Pat::Str("")),
595596
PatKind::Wild => (Pat::Sym(kw::Underscore), Pat::Sym(kw::Underscore)),
596597
PatKind::Binding(binding_mode, _, ident, Some(end_pat)) => {
597598
let start = if binding_mode == BindingMode::NONE {
@@ -619,7 +620,8 @@ fn pat_search_pat(tcx: TyCtxt<'_>, pat: &rustc_hir::Pat<'_>) -> (Pat, Pat) {
619620
},
620621
PatKind::TupleStruct(path, _, _) => {
621622
let (start, _) = qpath_search_pat(&path);
622-
(start, Pat::Str(")"))
623+
// This pattern cannot show up in proc-macro checks
624+
(start, Pat::Str(""))
623625
},
624626
PatKind::Or(plist) => {
625627
// documented invariant
@@ -629,7 +631,6 @@ fn pat_search_pat(tcx: TyCtxt<'_>, pat: &rustc_hir::Pat<'_>) -> (Pat, Pat) {
629631
(start, end)
630632
},
631633
PatKind::Never => (Pat::Str("!"), Pat::Str("")),
632-
PatKind::Tuple(_, _) => (Pat::Str("("), Pat::Str(")")),
633634
PatKind::Box(p) => {
634635
let (_, end) = pat_search_pat(tcx, p);
635636
(Pat::Str("box"), end)

0 commit comments

Comments
 (0)