Add pretty-printing for const generics

Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
This commit is contained in:
varkor 2019-02-05 16:50:16 +01:00
parent d7695abb76
commit b4ef753e8f
2 changed files with 16 additions and 1 deletions

View File

@ -646,6 +646,11 @@ impl Sig for ast::Generics {
param_text.push_str(&pprust::bounds_to_string(&param.bounds));
// FIXME descend properly into bounds.
}
ast::GenericParamKind::Const { ref ty } => {
param_text.push_str(&pprust::bounds_to_string(&param.bounds));
param_text.push_str("= ");
param_text.push_str(&pprust::ty_to_string(&ty));
}
}
}
text.push_str(&param_text);

View File

@ -1025,6 +1025,7 @@ impl<'a> State<'a> {
match generic_arg {
GenericArg::Lifetime(lt) => self.print_lifetime(*lt),
GenericArg::Type(ty) => self.print_type(ty),
GenericArg::Const(ct) => self.print_expr(&ct.value),
}
}
@ -2929,7 +2930,7 @@ impl<'a> State<'a> {
s.print_outer_attributes_inline(&param.attrs)?;
let lt = ast::Lifetime { id: param.id, ident: param.ident };
s.print_lifetime_bounds(lt, &param.bounds)
},
}
ast::GenericParamKind::Type { ref default } => {
s.print_outer_attributes_inline(&param.attrs)?;
s.print_ident(param.ident)?;
@ -2943,6 +2944,15 @@ impl<'a> State<'a> {
_ => Ok(())
}
}
ast::GenericParamKind::Const { ref ty } => {
s.print_outer_attributes_inline(&param.attrs)?;
s.word_space("const")?;
s.print_ident(param.ident)?;
s.s.space()?;
s.word_space(":")?;
s.print_type(ty)?;
s.print_type_bounds(":", &param.bounds)
}
}
})?;