Skip to content

Commit 8614f44

Browse files
varkorfanzier
authored andcommitted
Add support for StructRest in clippy
1 parent 60552c7 commit 8614f44

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/tools/clippy/clippy_lints/src/utils/ast_utils.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ pub fn eq_expr_opt(l: &Option<P<Expr>>, r: &Option<P<Expr>>) -> bool {
107107
both(l, r, |l, r| eq_expr(l, r))
108108
}
109109

110+
pub fn eq_struct_rest(l: &StructRest, r: &StructRest) -> bool {
111+
match (l, r) {
112+
(StructRest::Base(lb), StructRest::Base(rb)) => eq_expr(lb, rb),
113+
(StructRest::Rest(_), StructRest::Rest(_)) => true,
114+
(StructRest::None, StructRest::None) => true,
115+
_ => false,
116+
}
117+
}
118+
110119
pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
111120
use ExprKind::*;
112121
if !over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r)) {
@@ -150,7 +159,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
150159
(Path(lq, lp), Path(rq, rp)) => both(lq, rq, |l, r| eq_qself(l, r)) && eq_path(lp, rp),
151160
(MacCall(l), MacCall(r)) => eq_mac_call(l, r),
152161
(Struct(lp, lfs, lb), Struct(rp, rfs, rb)) => {
153-
eq_path(lp, rp) && eq_expr_opt(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r))
162+
eq_path(lp, rp) && eq_struct_rest(lb, rb) && unordered_over(lfs, rfs, |l, r| eq_field(l, r))
154163
},
155164
_ => false,
156165
}

src/tools/clippy/clippy_lints/src/utils/sugg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl<'a> Sugg<'a> {
170170
| ast::ExprKind::MacCall(..)
171171
| ast::ExprKind::MethodCall(..)
172172
| ast::ExprKind::Paren(..)
173+
| ast::ExprKind::Underscore
173174
| ast::ExprKind::Path(..)
174175
| ast::ExprKind::Repeat(..)
175176
| ast::ExprKind::Ret(..)

0 commit comments

Comments
 (0)