Skip to content

Commit

Permalink
Add pretty-printing for const generics
Browse files Browse the repository at this point in the history
Co-Authored-By: Gabriel Smith <yodaldevoid@users.noreply.github.com>
  • Loading branch information
varkor and yodaldevoid committed Feb 7, 2019
1 parent d7695ab commit b4ef753
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/librustc_save_analysis/sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 11 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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)?;
Expand All @@ -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)
}
}
})?;

Expand Down

0 comments on commit b4ef753

Please sign in to comment.