mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
builtin derive macros: fix error with const generics default
This commit is contained in:
parent
d4bc912c48
commit
9ecfae44d7
@ -541,7 +541,7 @@ impl<'a> TraitDef<'a> {
|
||||
self.generics.to_generics(cx, self.span, type_ident, generics);
|
||||
|
||||
// Create the generic parameters
|
||||
params.extend(generics.params.iter().map(|param| match param.kind {
|
||||
params.extend(generics.params.iter().map(|param| match ¶m.kind {
|
||||
GenericParamKind::Lifetime { .. } => param.clone(),
|
||||
GenericParamKind::Type { .. } => {
|
||||
// I don't think this can be moved out of the loop, since
|
||||
@ -561,7 +561,18 @@ impl<'a> TraitDef<'a> {
|
||||
|
||||
cx.typaram(self.span, param.ident, vec![], bounds, None)
|
||||
}
|
||||
GenericParamKind::Const { .. } => param.clone(),
|
||||
GenericParamKind::Const { ty, kw_span, .. } => {
|
||||
let const_nodefault_kind = GenericParamKind::Const {
|
||||
ty: ty.clone(),
|
||||
kw_span: kw_span.clone(),
|
||||
|
||||
// We can't have default values inside impl block
|
||||
default: None,
|
||||
};
|
||||
let mut param_clone = param.clone();
|
||||
param_clone.kind = const_nodefault_kind;
|
||||
param_clone
|
||||
}
|
||||
}));
|
||||
|
||||
// and similarly for where clauses
|
||||
|
14
src/test/ui/derives/derive-macro-const-default.rs
Normal file
14
src/test/ui/derives/derive-macro-const-default.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// check-pass
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(const_generics_defaults)]
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
struct Example<T, const N: usize = 1usize>([T; N]);
|
||||
|
||||
fn main() {
|
||||
let a = Example([(); 16]);
|
||||
let b = a.clone();
|
||||
if a != b {
|
||||
let _c = format!("{:?}", a);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user