Skip to content

Commit 48dec84

Browse files
JulianKnodtlqd
authored andcommitted
first pass at default values for const generics
- Adds optional default values to const generic parameters in the AST and HIR - Parses these optional default values - Adds a `const_generics_defaults` feature gate
1 parent 7f44f1d commit 48dec84

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

clippy_lints/src/utils/ast_utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
407407
}
408408
}
409409

410+
pub fn eq_anon_const(l: &AnonConst, r: &AnonConst) -> bool {
411+
eq_expr(&l.value, &r.value)
412+
}
413+
410414
pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
411415
matches!(
412416
(l, r),
@@ -497,7 +501,8 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
497501
&& match (&l.kind, &r.kind) {
498502
(Lifetime, Lifetime) => true,
499503
(Type { default: l }, Type { default: r }) => both(l, r, |l, r| eq_ty(l, r)),
500-
(Const { ty: l, kw_span: _ }, Const { ty: r, kw_span: _ }) => eq_ty(l, r),
504+
(Const { ty: lt, kw_span: _ , default: ld}, Const { ty: rt, kw_span: _, default: rd }) =>
505+
eq_ty(lt, rt) && both(ld, rd, |ld, rd| eq_anon_const(ld, rd)),
501506
_ => false,
502507
}
503508
&& over(&l.attrs, &r.attrs, |l, r| eq_attr(l, r))

0 commit comments

Comments
 (0)