-#![feature(or_patterns)]
+#![cfg_attr(bootstrap, feature(or_patterns))]
#![recursion_limit = "256"]
use rustc_ast as ast;
// When printing the AST, we sometimes need to inject `#[no_std]` here.
// Since you can't compile the HIR, it's not necessary.
- s.print_mod(&krate.item.module, s.attrs(hir::CRATE_HIR_ID));
+ s.print_mod(&krate.item, s.attrs(hir::CRATE_HIR_ID));
s.print_remaining_comments();
s.s.eof()
}
to_string(NO_ANN, |s| s.print_bounds("", bounds))
}
-pub fn param_to_string(arg: &hir::Param<'_>) -> String {
- to_string(NO_ANN, |s| s.print_param(arg))
-}
-
pub fn ty_to_string(ty: &hir::Ty<'_>) -> String {
to_string(NO_ANN, |s| s.print_type(ty))
}
fn print_else(&mut self, els: Option<&hir::Expr<'_>>) {
match els {
- Some(_else) => {
- match _else.kind {
+ Some(else_) => {
+ match else_.kind {
// "another else-if"
hir::ExprKind::If(ref i, ref then, ref e) => {
self.cbox(INDENT_UNIT - 1);
self.s.word(" else ");
self.print_block(&b)
}
+ hir::ExprKind::Match(ref expr, arms, _) => {
+ // else if let desugared to match
+ assert!(arms.len() == 2, "if let desugars to match with two arms");
+
+ self.s.word(" else ");
+ self.s.word("{");
+
+ self.cbox(INDENT_UNIT);
+ self.ibox(INDENT_UNIT);
+ self.word_nbsp("match");
+ self.print_expr_as_cond(&expr);
+ self.s.space();
+ self.bopen();
+ for arm in arms {
+ self.print_arm(arm);
+ }
+ self.bclose(expr.span);
+
+ self.s.word("}");
+ }
// BLEAH, constraints would be great here
_ => {
panic!("print_if saw if with weird alternative");
None => s.word("_"),
}
}
- hir::InlineAsmOperand::Const { expr } => {
+ hir::InlineAsmOperand::Const { anon_const } => {
s.word("const");
s.space();
- s.print_expr(expr);
+ s.print_anon_const(anon_const);
}
hir::InlineAsmOperand::Sym { expr } => {
s.word("sym");
}
}
- pub fn print_usize(&mut self, i: usize) {
- self.s.word(i.to_string())
- }
-
pub fn print_name(&mut self, name: Symbol) {
self.print_ident(Ident::with_dummy_span(name))
}
- pub fn print_for_decl(&mut self, loc: &hir::Local<'_>, coll: &hir::Expr<'_>) {
- self.print_local_decl(loc);
- self.s.space();
- self.word_space("in");
- self.print_expr(coll)
- }
-
pub fn print_path(&mut self, path: &hir::Path<'_>, colons_before_params: bool) {
self.maybe_print_comment(path.span.lo());
GenericParamKind::Const { ref ty, ref default } => {
self.word_space(":");
self.print_type(ty);
- if let Some(ref _default) = default {
- // FIXME(const_generics_defaults): print the `default` value here
+ if let Some(ref default) = default {
+ self.s.space();
+ self.word_space("=");
+ self.print_anon_const(&default)
}
}
}
}
}
- pub fn print_opt_abi_and_extern_if_nondefault(&mut self, opt_abi: Option<Abi>) {
- match opt_abi {
- Some(Abi::Rust) => {}
- Some(abi) => {
- self.word_nbsp("extern");
- self.word_nbsp(abi.to_string())
- }
- None => {}
- }
- }
-
- pub fn print_extern_opt_abi(&mut self, opt_abi: Option<Abi>) {
- if let Some(abi) = opt_abi {
- self.word_nbsp("extern");
- self.word_nbsp(abi.to_string())
- }
- }
-
pub fn print_fn_header_info(&mut self, header: hir::FnHeader, vis: &hir::Visibility<'_>) {
self.s.word(visibility_qualified(vis, ""));