Skip to content

Commit b4ef753

Browse files
varkoryodaldevoid
andcommitted
Add pretty-printing for const generics
Co-Authored-By: Gabriel Smith <[email protected]>
1 parent d7695ab commit b4ef753

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/librustc_save_analysis/sig.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ impl Sig for ast::Generics {
646646
param_text.push_str(&pprust::bounds_to_string(&param.bounds));
647647
// FIXME descend properly into bounds.
648648
}
649+
ast::GenericParamKind::Const { ref ty } => {
650+
param_text.push_str(&pprust::bounds_to_string(&param.bounds));
651+
param_text.push_str("= ");
652+
param_text.push_str(&pprust::ty_to_string(&ty));
653+
}
649654
}
650655
}
651656
text.push_str(&param_text);

src/libsyntax/print/pprust.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ impl<'a> State<'a> {
10251025
match generic_arg {
10261026
GenericArg::Lifetime(lt) => self.print_lifetime(*lt),
10271027
GenericArg::Type(ty) => self.print_type(ty),
1028+
GenericArg::Const(ct) => self.print_expr(&ct.value),
10281029
}
10291030
}
10301031

@@ -2929,7 +2930,7 @@ impl<'a> State<'a> {
29292930
s.print_outer_attributes_inline(&param.attrs)?;
29302931
let lt = ast::Lifetime { id: param.id, ident: param.ident };
29312932
s.print_lifetime_bounds(lt, &param.bounds)
2932-
},
2933+
}
29332934
ast::GenericParamKind::Type { ref default } => {
29342935
s.print_outer_attributes_inline(&param.attrs)?;
29352936
s.print_ident(param.ident)?;
@@ -2943,6 +2944,15 @@ impl<'a> State<'a> {
29432944
_ => Ok(())
29442945
}
29452946
}
2947+
ast::GenericParamKind::Const { ref ty } => {
2948+
s.print_outer_attributes_inline(&param.attrs)?;
2949+
s.word_space("const")?;
2950+
s.print_ident(param.ident)?;
2951+
s.s.space()?;
2952+
s.word_space(":")?;
2953+
s.print_type(ty)?;
2954+
s.print_type_bounds(":", &param.bounds)
2955+
}
29462956
}
29472957
})?;
29482958

0 commit comments

Comments
 (0)