Skip to content

Commit 9ecfae4

Browse files
committed
builtin derive macros: fix error with const generics default
1 parent d4bc912 commit 9ecfae4

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<'a> TraitDef<'a> {
541541
self.generics.to_generics(cx, self.span, type_ident, generics);
542542

543543
// Create the generic parameters
544-
params.extend(generics.params.iter().map(|param| match param.kind {
544+
params.extend(generics.params.iter().map(|param| match &param.kind {
545545
GenericParamKind::Lifetime { .. } => param.clone(),
546546
GenericParamKind::Type { .. } => {
547547
// I don't think this can be moved out of the loop, since
@@ -561,7 +561,18 @@ impl<'a> TraitDef<'a> {
561561

562562
cx.typaram(self.span, param.ident, vec![], bounds, None)
563563
}
564-
GenericParamKind::Const { .. } => param.clone(),
564+
GenericParamKind::Const { ty, kw_span, .. } => {
565+
let const_nodefault_kind = GenericParamKind::Const {
566+
ty: ty.clone(),
567+
kw_span: kw_span.clone(),
568+
569+
// We can't have default values inside impl block
570+
default: None,
571+
};
572+
let mut param_clone = param.clone();
573+
param_clone.kind = const_nodefault_kind;
574+
param_clone
575+
}
565576
}));
566577

567578
// and similarly for where clauses
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// check-pass
2+
#![allow(incomplete_features)]
3+
#![feature(const_generics_defaults)]
4+
5+
#[derive(Clone, PartialEq, Debug)]
6+
struct Example<T, const N: usize = 1usize>([T; N]);
7+
8+
fn main() {
9+
let a = Example([(); 16]);
10+
let b = a.clone();
11+
if a != b {
12+
let _c = format!("{:?}", a);
13+
}
14+
}

0 commit comments

Comments
 (0)