Nested::ImplItem(id) => state.print_impl_item(self.impl_item(id)),
Nested::ForeignItem(id) => state.print_foreign_item(self.foreign_item(id)),
Nested::Body(id) => state.print_expr(&self.body(id).value),
- Nested::BodyParamPat(id, i) => state.print_pat(&self.body(id).params[i].pat),
+ Nested::BodyParamPat(id, i) => state.print_pat(self.body(id).params[i].pat),
}
}
}
impl<'a> State<'a> {
pub fn print_node(&mut self, node: Node<'_>) {
match node {
- Node::Param(a) => self.print_param(&a),
- Node::Item(a) => self.print_item(&a),
- Node::ForeignItem(a) => self.print_foreign_item(&a),
+ Node::Param(a) => self.print_param(a),
+ Node::Item(a) => self.print_item(a),
+ Node::ForeignItem(a) => self.print_foreign_item(a),
Node::TraitItem(a) => self.print_trait_item(a),
Node::ImplItem(a) => self.print_impl_item(a),
- Node::Variant(a) => self.print_variant(&a),
- Node::AnonConst(a) => self.print_anon_const(&a),
- Node::Expr(a) => self.print_expr(&a),
- Node::Stmt(a) => self.print_stmt(&a),
- Node::PathSegment(a) => self.print_path_segment(&a),
- Node::Ty(a) => self.print_type(&a),
- Node::TypeBinding(a) => self.print_type_binding(&a),
- Node::TraitRef(a) => self.print_trait_ref(&a),
- Node::Pat(a) => self.print_pat(&a),
- Node::Arm(a) => self.print_arm(&a),
+ Node::Variant(a) => self.print_variant(a),
+ Node::AnonConst(a) => self.print_anon_const(a),
+ Node::Expr(a) => self.print_expr(a),
+ Node::Stmt(a) => self.print_stmt(a),
+ Node::PathSegment(a) => self.print_path_segment(a),
+ Node::Ty(a) => self.print_type(a),
+ Node::TypeBinding(a) => self.print_type_binding(a),
+ Node::TraitRef(a) => self.print_trait_ref(a),
+ Node::Pat(a) => self.print_pat(a),
+ Node::Arm(a) => self.print_arm(a),
Node::Infer(_) => self.word("_"),
Node::Block(a) => {
// Containing cbox, will be closed by print-block at `}`.
self.cbox(INDENT_UNIT);
// Head-ibox, will be closed by print-block after `{`.
self.ibox(0);
- self.print_block(&a)
+ self.print_block(a);
}
- Node::Lifetime(a) => self.print_lifetime(&a),
+ Node::Lifetime(a) => self.print_lifetime(a),
Node::GenericParam(_) => panic!("cannot print Node::GenericParam"),
Node::Field(_) => panic!("cannot print Node::Field"),
// These cases do not carry enough information in the
// `hir_map` to reconstruct their full structure for pretty
// printing.
Node::Ctor(..) => panic!("cannot print isolated Ctor"),
- Node::Local(a) => self.print_local_decl(&a),
+ Node::Local(a) => self.print_local_decl(a),
Node::Crate(..) => panic!("cannot print Crate"),
}
}
}
pub fn commasep_exprs(&mut self, b: Breaks, exprs: &[hir::Expr<'_>]) {
- self.commasep_cmnt(b, exprs, |s, e| s.print_expr(&e), |e| e.span)
+ self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e), |e| e.span);
}
pub fn print_mod(&mut self, _mod: &hir::Mod<'_>, attrs: &[ast::Attribute]) {
self.maybe_print_comment(ty.span.lo());
self.ibox(0);
match ty.kind {
- hir::TyKind::Slice(ref ty) => {
+ hir::TyKind::Slice(ty) => {
self.word("[");
- self.print_type(&ty);
+ self.print_type(ty);
self.word("]");
}
hir::TyKind::Ptr(ref mt) => {
hir::TyKind::Never => {
self.word("!");
}
- hir::TyKind::Tup(ref elts) => {
+ hir::TyKind::Tup(elts) => {
self.popen();
- self.commasep(Inconsistent, &elts, |s, ty| s.print_type(&ty));
+ self.commasep(Inconsistent, elts, |s, ty| s.print_type(ty));
if elts.len() == 1 {
self.word(",");
}
self.pclose();
}
- hir::TyKind::BareFn(ref f) => {
- self.print_ty_fn(
- f.abi,
- f.unsafety,
- &f.decl,
- None,
- &f.generic_params,
- f.param_names,
- );
+ hir::TyKind::BareFn(f) => {
+ self.print_ty_fn(f.abi, f.unsafety, f.decl, None, f.generic_params, f.param_names);
}
hir::TyKind::OpaqueDef(..) => self.word("/*impl Trait*/"),
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
self.print_lifetime(lifetime);
}
}
- hir::TyKind::Array(ref ty, ref length) => {
+ hir::TyKind::Array(ty, ref length) => {
self.word("[");
- self.print_type(&ty);
+ self.print_type(ty);
self.word("; ");
self.print_array_length(length);
self.word("]");
self.maybe_print_comment(item.span.lo());
self.print_outer_attributes(self.attrs(item.hir_id()));
match item.kind {
- hir::ForeignItemKind::Fn(ref decl, ref arg_names, ref generics) => {
+ hir::ForeignItemKind::Fn(decl, arg_names, generics) => {
self.head("");
self.print_fn(
decl,
self.word(";");
self.end() // end the outer fn box
}
- hir::ForeignItemKind::Static(ref t, m) => {
+ hir::ForeignItemKind::Static(t, m) => {
self.head("static");
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
self.word_space(":");
- self.print_type(&t);
+ self.print_type(t);
self.word(";");
self.end(); // end the head-ibox
self.end() // end the outer cbox
) {
self.word_space("type");
self.print_ident(ident);
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
if let Some(bounds) = bounds {
self.print_bounds(":", bounds);
}
) {
self.head("type");
self.print_ident(item.ident);
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
self.end(); // end the inner ibox
self.print_where_clause(generics);
self.end(); // end inner head-block
self.end(); // end outer head-block
}
- hir::ItemKind::Use(ref path, kind) => {
+ hir::ItemKind::Use(path, kind) => {
self.head("use");
self.print_path(path, false);
self.end(); // end inner head-block
self.end(); // end outer head-block
}
- hir::ItemKind::Static(ref ty, m, expr) => {
+ hir::ItemKind::Static(ty, m, expr) => {
self.head("static");
if m == hir::Mutability::Mut {
self.word_space("mut");
}
self.print_ident(item.ident);
self.word_space(":");
- self.print_type(&ty);
+ self.print_type(ty);
self.space();
self.end(); // end the head-ibox
self.word(";");
self.end(); // end the outer cbox
}
- hir::ItemKind::Const(ref ty, expr) => {
+ hir::ItemKind::Const(ty, expr) => {
self.head("const");
self.print_ident(item.ident);
self.word_space(":");
- self.print_type(&ty);
+ self.print_type(ty);
self.space();
self.end(); // end the head-ibox
self.word(";");
self.end(); // end the outer cbox
}
- hir::ItemKind::Fn(ref sig, ref param_names, body) => {
+ hir::ItemKind::Fn(ref sig, param_names, body) => {
self.head("");
self.print_fn(
- &sig.decl,
+ sig.decl,
sig.header,
Some(item.ident.name),
param_names,
}
self.bclose(item.span);
}
- hir::ItemKind::GlobalAsm(ref asm) => {
+ hir::ItemKind::GlobalAsm(asm) => {
self.head("global_asm!");
self.print_inline_asm(asm);
self.end()
}
- hir::ItemKind::TyAlias(ref ty, ref generics) => {
- self.print_item_type(item, &generics, |state| {
+ hir::ItemKind::TyAlias(ty, generics) => {
+ self.print_item_type(item, generics, |state| {
state.word_space("=");
- state.print_type(&ty);
+ state.print_type(ty);
});
}
hir::ItemKind::OpaqueTy(ref opaque_ty) => {
- self.print_item_type(item, &opaque_ty.generics, |state| {
+ self.print_item_type(item, opaque_ty.generics, |state| {
let mut real_bounds = Vec::with_capacity(opaque_ty.bounds.len());
- for b in opaque_ty.bounds.iter() {
- if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
+ for b in opaque_ty.bounds {
+ if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b {
state.space();
state.word_space("for ?");
state.print_trait_ref(&ptr.trait_ref);
state.print_bounds("= impl", real_bounds);
});
}
- hir::ItemKind::Enum(ref enum_definition, ref params) => {
+ hir::ItemKind::Enum(ref enum_definition, params) => {
self.print_enum_def(enum_definition, params, item.ident.name, item.span);
}
- hir::ItemKind::Struct(ref struct_def, ref generics) => {
+ hir::ItemKind::Struct(ref struct_def, generics) => {
self.head("struct");
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
}
- hir::ItemKind::Union(ref struct_def, ref generics) => {
+ hir::ItemKind::Union(ref struct_def, generics) => {
self.head("union");
self.print_struct(struct_def, generics, item.ident.name, item.span, true);
}
- hir::ItemKind::Impl(hir::Impl {
+ hir::ItemKind::Impl(&hir::Impl {
unsafety,
polarity,
defaultness,
constness,
defaultness_span: _,
- ref generics,
+ generics,
ref of_trait,
- ref self_ty,
+ self_ty,
items,
}) => {
self.head("");
- self.print_defaultness(*defaultness);
- self.print_unsafety(*unsafety);
+ self.print_defaultness(defaultness);
+ self.print_unsafety(unsafety);
self.word_nbsp("impl");
if !generics.params.is_empty() {
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
self.space();
}
- if *constness == hir::Constness::Const {
+ if constness == hir::Constness::Const {
self.word_nbsp("const");
}
self.word("!");
}
- if let Some(ref t) = of_trait {
+ if let Some(t) = of_trait {
self.print_trait_ref(t);
self.space();
self.word_space("for");
}
- self.print_type(&self_ty);
+ self.print_type(self_ty);
self.print_where_clause(generics);
self.space();
self.bopen();
self.print_inner_attributes(attrs);
- for impl_item in *items {
+ for impl_item in items {
self.ann.nested(self, Nested::ImplItem(impl_item.id));
}
self.bclose(item.span);
}
- hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, trait_items) => {
+ hir::ItemKind::Trait(is_auto, unsafety, generics, bounds, trait_items) => {
self.head("");
self.print_is_auto(is_auto);
self.print_unsafety(unsafety);
self.word_nbsp("trait");
self.print_ident(item.ident);
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
let mut real_bounds = Vec::with_capacity(bounds.len());
- for b in bounds.iter() {
- if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
+ for b in bounds {
+ if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b {
self.space();
self.word_space("for ?");
self.print_trait_ref(&ptr.trait_ref);
}
self.bclose(item.span);
}
- hir::ItemKind::TraitAlias(ref generics, ref bounds) => {
+ hir::ItemKind::TraitAlias(generics, bounds) => {
self.head("trait");
self.print_ident(item.ident);
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
let mut real_bounds = Vec::with_capacity(bounds.len());
// FIXME(durka) this seems to be some quite outdated syntax
- for b in bounds.iter() {
- if let GenericBound::Trait(ref ptr, hir::TraitBoundModifier::Maybe) = *b {
+ for b in bounds {
+ if let GenericBound::Trait(ptr, hir::TraitBoundModifier::Maybe) = b {
self.space();
self.word_space("for ?");
self.print_trait_ref(&ptr.trait_ref);
}
pub fn print_trait_ref(&mut self, t: &hir::TraitRef<'_>) {
- self.print_path(&t.path, false)
+ self.print_path(t.path, false);
}
fn print_formal_generic_params(&mut self, generic_params: &[hir::GenericParam<'_>]) {
}
fn print_poly_trait_ref(&mut self, t: &hir::PolyTraitRef<'_>) {
- self.print_formal_generic_params(&t.bound_generic_params);
- self.print_trait_ref(&t.trait_ref)
+ self.print_formal_generic_params(t.bound_generic_params);
+ self.print_trait_ref(&t.trait_ref);
}
pub fn print_enum_def(
) {
self.head("enum");
self.print_name(name);
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
self.print_where_clause(generics);
self.space();
- self.print_variants(&enum_definition.variants, span)
+ self.print_variants(enum_definition.variants, span);
}
pub fn print_variants(&mut self, variants: &[hir::Variant<'_>], span: rustc_span::Span) {
print_finalizer: bool,
) {
self.print_name(name);
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
match struct_def {
hir::VariantData::Tuple(..) | hir::VariantData::Unit(..) => {
if let hir::VariantData::Tuple(..) = struct_def {
self.commasep(Inconsistent, struct_def.fields(), |s, field| {
s.maybe_print_comment(field.span.lo());
s.print_outer_attributes(s.attrs(field.hir_id));
- s.print_type(&field.ty)
+ s.print_type(field.ty);
});
self.pclose();
}
self.print_outer_attributes(self.attrs(field.hir_id));
self.print_ident(field.ident);
self.word_nbsp(":");
- self.print_type(&field.ty);
+ self.print_type(field.ty);
self.word(",");
}
pub fn print_variant(&mut self, v: &hir::Variant<'_>) {
self.head("");
let generics = hir::Generics::empty();
- self.print_struct(&v.data, &generics, v.ident.name, v.span, false);
+ self.print_struct(&v.data, generics, v.ident.name, v.span, false);
if let Some(ref d) = v.disr_expr {
self.space();
self.word_space("=");
arg_names: &[Ident],
body_id: Option<hir::BodyId>,
) {
- self.print_fn(&m.decl, m.header, Some(ident.name), generics, arg_names, body_id)
+ self.print_fn(m.decl, m.header, Some(ident.name), generics, arg_names, body_id);
}
pub fn print_trait_item(&mut self, ti: &hir::TraitItem<'_>) {
self.maybe_print_comment(ti.span.lo());
self.print_outer_attributes(self.attrs(ti.hir_id()));
match ti.kind {
- hir::TraitItemKind::Const(ref ty, default) => {
- self.print_associated_const(ti.ident, &ty, default);
+ hir::TraitItemKind::Const(ty, default) => {
+ self.print_associated_const(ti.ident, ty, default);
}
- hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref arg_names)) => {
- self.print_method_sig(ti.ident, sig, &ti.generics, arg_names, None);
+ hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(arg_names)) => {
+ self.print_method_sig(ti.ident, sig, ti.generics, arg_names, None);
self.word(";");
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
self.head("");
- self.print_method_sig(ti.ident, sig, &ti.generics, &[], Some(body));
+ self.print_method_sig(ti.ident, sig, ti.generics, &[], Some(body));
self.nbsp();
self.end(); // need to close a box
self.end(); // need to close a box
self.ann.nested(self, Nested::Body(body));
}
- hir::TraitItemKind::Type(ref bounds, ref default) => {
- self.print_associated_type(
- ti.ident,
- &ti.generics,
- Some(bounds),
- default.as_ref().map(|ty| &**ty),
- );
+ hir::TraitItemKind::Type(bounds, default) => {
+ self.print_associated_type(ti.ident, ti.generics, Some(bounds), default);
}
}
self.ann.post(self, AnnNode::SubItem(ti.hir_id()))
self.print_outer_attributes(self.attrs(ii.hir_id()));
match ii.kind {
- hir::ImplItemKind::Const(ref ty, expr) => {
- self.print_associated_const(ii.ident, &ty, Some(expr));
+ hir::ImplItemKind::Const(ty, expr) => {
+ self.print_associated_const(ii.ident, ty, Some(expr));
}
hir::ImplItemKind::Fn(ref sig, body) => {
self.head("");
- self.print_method_sig(ii.ident, sig, &ii.generics, &[], Some(body));
+ self.print_method_sig(ii.ident, sig, ii.generics, &[], Some(body));
self.nbsp();
self.end(); // need to close a box
self.end(); // need to close a box
self.ann.nested(self, Nested::Body(body));
}
- hir::ImplItemKind::TyAlias(ref ty) => {
- self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
+ hir::ImplItemKind::TyAlias(ty) => {
+ self.print_associated_type(ii.ident, ii.generics, None, Some(ty));
}
}
self.ann.post(self, AnnNode::SubItem(ii.hir_id()))
decl(self);
self.end();
- if let Some(ref init) = init {
+ if let Some(init) = init {
self.nbsp();
self.word_space("=");
- self.print_expr(&init);
+ self.print_expr(init);
}
self.end()
}
pub fn print_stmt(&mut self, st: &hir::Stmt<'_>) {
self.maybe_print_comment(st.span.lo());
match st.kind {
- hir::StmtKind::Local(ref loc) => {
- self.print_local(loc.init, |this| this.print_local_decl(&loc));
+ hir::StmtKind::Local(loc) => {
+ self.print_local(loc.init, |this| this.print_local_decl(loc));
}
hir::StmtKind::Item(item) => self.ann.nested(self, Nested::Item(item)),
- hir::StmtKind::Expr(ref expr) => {
+ hir::StmtKind::Expr(expr) => {
self.space_if_not_bol();
- self.print_expr(&expr);
+ self.print_expr(expr);
}
- hir::StmtKind::Semi(ref expr) => {
+ hir::StmtKind::Semi(expr) => {
self.space_if_not_bol();
- self.print_expr(&expr);
+ self.print_expr(expr);
self.word(";");
}
}
for st in blk.stmts {
self.print_stmt(st);
}
- if let Some(ref expr) = blk.expr {
+ if let Some(expr) = blk.expr {
self.space_if_not_bol();
- self.print_expr(&expr);
+ self.print_expr(expr);
self.maybe_print_trailing_comment(expr.span, Some(blk.span.hi()));
}
self.bclose_maybe_open(blk.span, close_box);
if let Some(els_inner) = els {
match els_inner.kind {
// Another `else if` block.
- hir::ExprKind::If(ref i, ref then, ref e) => {
+ hir::ExprKind::If(i, then, e) => {
self.cbox(INDENT_UNIT - 1);
self.ibox(0);
self.word(" else if ");
- self.print_expr_as_cond(&i);
+ self.print_expr_as_cond(i);
self.space();
- self.print_expr(&then);
- self.print_else(e.as_ref().map(|e| &**e))
+ self.print_expr(then);
+ self.print_else(e);
}
// Final `else` block.
- hir::ExprKind::Block(ref b, _) => {
+ hir::ExprKind::Block(b, _) => {
self.cbox(INDENT_UNIT - 1);
self.ibox(0);
self.word(" else ");
- self.print_block(&b)
+ self.print_block(b);
}
// Constraints would be great here!
_ => {
if needs_par {
self.popen();
}
- if let hir::ExprKind::DropTemps(ref actual_expr) = expr.kind {
+ if let hir::ExprKind::DropTemps(actual_expr) = expr.kind {
self.print_expr(actual_expr);
} else {
self.print_expr(expr);
&mut self,
qpath: &hir::QPath<'_>,
fields: &[hir::ExprField<'_>],
- wth: &Option<&hir::Expr<'_>>,
+ wth: Option<&hir::Expr<'_>>,
) {
self.print_qpath(qpath, true);
self.word("{");
s.print_ident(field.ident);
s.word_space(":");
}
- s.print_expr(&field.expr);
+ s.print_expr(field.expr);
s.end()
},
|f| f.span,
);
- match *wth {
- Some(ref expr) => {
- self.ibox(INDENT_UNIT);
- if !fields.is_empty() {
- self.word(",");
- self.space();
- }
- self.word("..");
- self.print_expr(&expr);
- self.end();
- }
- _ => {
- if !fields.is_empty() {
- self.word(",")
- }
+ if let Some(expr) = wth {
+ self.ibox(INDENT_UNIT);
+ if !fields.is_empty() {
+ self.word(",");
+ self.space();
}
+ self.word("..");
+ self.print_expr(expr);
+ self.end();
+ } else if !fields.is_empty() {
+ self.word(",");
}
+
self.word("}");
}
Options(ast::InlineAsmOptions),
}
- let mut args =
- vec![AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(&asm.template))];
+ let mut args = vec![AsmArg::Template(ast::InlineAsmTemplatePiece::to_string(asm.template))];
args.extend(asm.operands.iter().map(|(o, _)| AsmArg::Operand(o)));
if !asm.options.is_empty() {
args.push(AsmArg::Options(asm.options));
}
self.popen();
- self.commasep(Consistent, &args, |s, arg| match arg {
- AsmArg::Template(template) => s.print_string(&template, ast::StrStyle::Cooked),
- AsmArg::Operand(op) => match op {
- hir::InlineAsmOperand::In { reg, expr } => {
+ self.commasep(Consistent, &args, |s, arg| match *arg {
+ AsmArg::Template(ref template) => s.print_string(template, ast::StrStyle::Cooked),
+ AsmArg::Operand(op) => match *op {
+ hir::InlineAsmOperand::In { reg, ref expr } => {
s.word("in");
s.popen();
s.word(format!("{}", reg));
s.space();
s.print_expr(expr);
}
- hir::InlineAsmOperand::Out { reg, late, expr } => {
- s.word(if *late { "lateout" } else { "out" });
+ hir::InlineAsmOperand::Out { reg, late, ref expr } => {
+ s.word(if late { "lateout" } else { "out" });
s.popen();
s.word(format!("{}", reg));
s.pclose();
None => s.word("_"),
}
}
- hir::InlineAsmOperand::InOut { reg, late, expr } => {
- s.word(if *late { "inlateout" } else { "inout" });
+ hir::InlineAsmOperand::InOut { reg, late, ref expr } => {
+ s.word(if late { "inlateout" } else { "inout" });
s.popen();
s.word(format!("{}", reg));
s.pclose();
s.space();
s.print_expr(expr);
}
- hir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => {
- s.word(if *late { "inlateout" } else { "inout" });
+ hir::InlineAsmOperand::SplitInOut { reg, late, ref in_expr, ref out_expr } => {
+ s.word(if late { "inlateout" } else { "inout" });
s.popen();
s.word(format!("{}", reg));
s.pclose();
None => s.word("_"),
}
}
- hir::InlineAsmOperand::Const { anon_const } => {
+ hir::InlineAsmOperand::Const { ref anon_const } => {
s.word("const");
s.space();
s.print_anon_const(anon_const);
}
- hir::InlineAsmOperand::SymFn { anon_const } => {
+ hir::InlineAsmOperand::SymFn { ref anon_const } => {
s.word("sym_fn");
s.space();
s.print_anon_const(anon_const);
}
- hir::InlineAsmOperand::SymStatic { path, def_id: _ } => {
+ hir::InlineAsmOperand::SymStatic { ref path, def_id: _ } => {
s.word("sym_static");
s.space();
s.print_qpath(path, true);
self.ibox(INDENT_UNIT);
self.ann.pre(self, AnnNode::Expr(expr));
match expr.kind {
- hir::ExprKind::Box(ref expr) => {
+ hir::ExprKind::Box(expr) => {
self.word_space("box");
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX);
}
- hir::ExprKind::Array(ref exprs) => {
+ hir::ExprKind::Array(exprs) => {
self.print_expr_vec(exprs);
}
hir::ExprKind::ConstBlock(ref anon_const) => {
self.print_expr_anon_const(anon_const);
}
- hir::ExprKind::Repeat(ref element, ref count) => {
- self.print_expr_repeat(&element, count);
+ hir::ExprKind::Repeat(element, ref count) => {
+ self.print_expr_repeat(element, count);
}
- hir::ExprKind::Struct(ref qpath, fields, ref wth) => {
+ hir::ExprKind::Struct(qpath, fields, wth) => {
self.print_expr_struct(qpath, fields, wth);
}
- hir::ExprKind::Tup(ref exprs) => {
+ hir::ExprKind::Tup(exprs) => {
self.print_expr_tup(exprs);
}
- hir::ExprKind::Call(ref func, ref args) => {
- self.print_expr_call(&func, args);
+ hir::ExprKind::Call(func, args) => {
+ self.print_expr_call(func, args);
}
- hir::ExprKind::MethodCall(ref segment, ref args, _) => {
+ hir::ExprKind::MethodCall(segment, args, _) => {
self.print_expr_method_call(segment, args);
}
- hir::ExprKind::Binary(op, ref lhs, ref rhs) => {
- self.print_expr_binary(op, &lhs, &rhs);
+ hir::ExprKind::Binary(op, lhs, rhs) => {
+ self.print_expr_binary(op, lhs, rhs);
}
- hir::ExprKind::Unary(op, ref expr) => {
- self.print_expr_unary(op, &expr);
+ hir::ExprKind::Unary(op, expr) => {
+ self.print_expr_unary(op, expr);
}
- hir::ExprKind::AddrOf(k, m, ref expr) => {
- self.print_expr_addr_of(k, m, &expr);
+ hir::ExprKind::AddrOf(k, m, expr) => {
+ self.print_expr_addr_of(k, m, expr);
}
hir::ExprKind::Lit(ref lit) => {
- self.print_literal(&lit);
+ self.print_literal(lit);
}
- hir::ExprKind::Cast(ref expr, ref ty) => {
+ hir::ExprKind::Cast(expr, ty) => {
let prec = AssocOp::As.precedence() as i8;
- self.print_expr_maybe_paren(&expr, prec);
+ self.print_expr_maybe_paren(expr, prec);
self.space();
self.word_space("as");
- self.print_type(&ty);
+ self.print_type(ty);
}
- hir::ExprKind::Type(ref expr, ref ty) => {
+ hir::ExprKind::Type(expr, ty) => {
let prec = AssocOp::Colon.precedence() as i8;
- self.print_expr_maybe_paren(&expr, prec);
+ self.print_expr_maybe_paren(expr, prec);
self.word_space(":");
- self.print_type(&ty);
+ self.print_type(ty);
}
- hir::ExprKind::DropTemps(ref init) => {
+ hir::ExprKind::DropTemps(init) => {
// Print `{`:
self.cbox(INDENT_UNIT);
self.ibox(0);
// Print `}`:
self.bclose_maybe_open(expr.span, true);
}
- hir::ExprKind::Let(hir::Let { pat, ty, init, .. }) => {
- self.print_let(pat, *ty, init);
+ hir::ExprKind::Let(&hir::Let { pat, ty, init, .. }) => {
+ self.print_let(pat, ty, init);
}
- hir::ExprKind::If(ref test, ref blk, ref elseopt) => {
- self.print_if(&test, &blk, elseopt.as_ref().map(|e| &**e));
+ hir::ExprKind::If(test, blk, elseopt) => {
+ self.print_if(test, blk, elseopt);
}
- hir::ExprKind::Loop(ref blk, opt_label, _, _) => {
+ hir::ExprKind::Loop(blk, opt_label, _, _) => {
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.word_space(":");
}
self.head("loop");
- self.print_block(&blk);
+ self.print_block(blk);
}
- hir::ExprKind::Match(ref expr, arms, _) => {
+ hir::ExprKind::Match(expr, arms, _) => {
self.cbox(INDENT_UNIT);
self.ibox(INDENT_UNIT);
self.word_nbsp("match");
- self.print_expr_as_cond(&expr);
+ self.print_expr_as_cond(expr);
self.space();
self.bopen();
for arm in arms {
hir::ExprKind::Closure {
capture_clause,
bound_generic_params,
- ref fn_decl,
+ fn_decl,
body,
fn_decl_span: _,
movability: _,
self.print_formal_generic_params(bound_generic_params);
self.print_capture_clause(capture_clause);
- self.print_closure_params(&fn_decl, body);
+ self.print_closure_params(fn_decl, body);
self.space();
// This is a bare expression.
// empty box to satisfy the close.
self.ibox(0);
}
- hir::ExprKind::Block(ref blk, opt_label) => {
+ hir::ExprKind::Block(blk, opt_label) => {
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.word_space(":");
self.cbox(INDENT_UNIT);
// head-box, will be closed by print-block after `{`
self.ibox(0);
- self.print_block(&blk);
+ self.print_block(blk);
}
- hir::ExprKind::Assign(ref lhs, ref rhs, _) => {
+ hir::ExprKind::Assign(lhs, rhs, _) => {
let prec = AssocOp::Assign.precedence() as i8;
- self.print_expr_maybe_paren(&lhs, prec + 1);
+ self.print_expr_maybe_paren(lhs, prec + 1);
self.space();
self.word_space("=");
- self.print_expr_maybe_paren(&rhs, prec);
+ self.print_expr_maybe_paren(rhs, prec);
}
- hir::ExprKind::AssignOp(op, ref lhs, ref rhs) => {
+ hir::ExprKind::AssignOp(op, lhs, rhs) => {
let prec = AssocOp::Assign.precedence() as i8;
- self.print_expr_maybe_paren(&lhs, prec + 1);
+ self.print_expr_maybe_paren(lhs, prec + 1);
self.space();
self.word(op.node.as_str());
self.word_space("=");
- self.print_expr_maybe_paren(&rhs, prec);
+ self.print_expr_maybe_paren(rhs, prec);
}
- hir::ExprKind::Field(ref expr, ident) => {
+ hir::ExprKind::Field(expr, ident) => {
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
self.word(".");
self.print_ident(ident);
}
- hir::ExprKind::Index(ref expr, ref index) => {
- self.print_expr_maybe_paren(&expr, parser::PREC_POSTFIX);
+ hir::ExprKind::Index(expr, index) => {
+ self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
self.word("[");
- self.print_expr(&index);
+ self.print_expr(index);
self.word("]");
}
hir::ExprKind::Path(ref qpath) => self.print_qpath(qpath, true),
- hir::ExprKind::Break(destination, ref opt_expr) => {
+ hir::ExprKind::Break(destination, opt_expr) => {
self.word("break");
if let Some(label) = destination.label {
self.space();
self.print_ident(label.ident);
}
- if let Some(ref expr) = *opt_expr {
+ if let Some(expr) = opt_expr {
self.space();
self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
self.print_ident(label.ident);
}
}
- hir::ExprKind::Ret(ref result) => {
+ hir::ExprKind::Ret(result) => {
self.word("return");
- if let Some(ref expr) = *result {
+ if let Some(expr) = result {
self.word(" ");
- self.print_expr_maybe_paren(&expr, parser::PREC_JUMP);
+ self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
}
- hir::ExprKind::InlineAsm(ref asm) => {
+ hir::ExprKind::InlineAsm(asm) => {
self.word("asm!");
self.print_inline_asm(asm);
}
- hir::ExprKind::Yield(ref expr, _) => {
+ hir::ExprKind::Yield(expr, _) => {
self.word_space("yield");
- self.print_expr_maybe_paren(&expr, parser::PREC_JUMP);
+ self.print_expr_maybe_paren(expr, parser::PREC_JUMP);
}
hir::ExprKind::Err => {
self.popen();
}
pub fn print_local_decl(&mut self, loc: &hir::Local<'_>) {
- self.print_pat(&loc.pat);
- if let Some(ref ty) = loc.ty {
+ self.print_pat(loc.pat);
+ if let Some(ty) = loc.ty {
self.word_space(":");
- self.print_type(&ty);
+ self.print_type(ty);
}
}
pub fn print_qpath(&mut self, qpath: &hir::QPath<'_>, colons_before_params: bool) {
match *qpath {
- hir::QPath::Resolved(None, ref path) => self.print_path(path, colons_before_params),
- hir::QPath::Resolved(Some(ref qself), ref path) => {
+ hir::QPath::Resolved(None, path) => self.print_path(path, colons_before_params),
+ hir::QPath::Resolved(Some(qself), path) => {
self.word("<");
self.print_type(qself);
self.space();
colons_before_params,
)
}
- hir::QPath::TypeRelative(ref qself, ref item_segment) => {
+ hir::QPath::TypeRelative(qself, item_segment) => {
// If we've got a compound-qualified-path, let's push an additional pair of angle
// brackets, so that we pretty-print `<<A::B>::C>` as `<A::B>::C`, instead of just
// `A::B::C` (since the latter could be ambiguous to the user)
- if let hir::TyKind::Path(hir::QPath::Resolved(None, _)) = &qself.kind {
+ if let hir::TyKind::Path(hir::QPath::Resolved(None, _)) = qself.kind {
self.print_type(qself);
} else {
self.word("<");
) {
if generic_args.parenthesized {
self.word("(");
- self.commasep(Inconsistent, generic_args.inputs(), |s, ty| s.print_type(&ty));
+ self.commasep(Inconsistent, generic_args.inputs(), |s, ty| s.print_type(ty));
self.word(")");
self.space_if_not_bol();
start_or_comma(self);
self.commasep(
Inconsistent,
- &generic_args.args,
+ generic_args.args,
|s, generic_arg| match generic_arg {
GenericArg::Lifetime(lt) if !elide_lifetimes => s.print_lifetime(lt),
GenericArg::Lifetime(_) => {}
self.word("..");
}
- for binding in generic_args.bindings.iter() {
+ for binding in generic_args.bindings {
start_or_comma(self);
self.print_type_binding(binding);
}
hir::TypeBindingKind::Equality { ref term } => {
self.word_space("=");
match term {
- Term::Ty(ref ty) => self.print_type(ty),
+ Term::Ty(ty) => self.print_type(ty),
Term::Const(ref c) => self.print_anon_const(c),
}
}
// is that it doesn't matter
match pat.kind {
PatKind::Wild => self.word("_"),
- PatKind::Binding(binding_mode, _, ident, ref sub) => {
+ PatKind::Binding(binding_mode, _, ident, sub) => {
match binding_mode {
hir::BindingAnnotation::Ref => {
self.word_nbsp("ref");
}
}
self.print_ident(ident);
- if let Some(ref p) = *sub {
+ if let Some(p) = sub {
self.word("@");
- self.print_pat(&p);
+ self.print_pat(p);
}
}
- PatKind::TupleStruct(ref qpath, ref elts, ddpos) => {
+ PatKind::TupleStruct(ref qpath, elts, ddpos) => {
self.print_qpath(qpath, true);
self.popen();
if let Some(ddpos) = ddpos {
- self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p));
if ddpos != 0 {
self.word_space(",");
}
self.word("..");
if ddpos != elts.len() {
self.word(",");
- self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(p));
}
} else {
- self.commasep(Inconsistent, &elts, |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
}
self.pclose();
}
PatKind::Path(ref qpath) => {
self.print_qpath(qpath, true);
}
- PatKind::Struct(ref qpath, ref fields, etc) => {
+ PatKind::Struct(ref qpath, fields, etc) => {
self.print_qpath(qpath, true);
self.nbsp();
self.word("{");
}
self.commasep_cmnt(
Consistent,
- &fields,
+ fields,
|s, f| {
s.cbox(INDENT_UNIT);
if !f.is_shorthand {
s.print_ident(f.ident);
s.word_nbsp(":");
}
- s.print_pat(&f.pat);
+ s.print_pat(f.pat);
s.end()
},
|f| f.pat.span,
}
self.word("}");
}
- PatKind::Or(ref pats) => {
- self.strsep("|", true, Inconsistent, &pats, |s, p| s.print_pat(&p));
+ PatKind::Or(pats) => {
+ self.strsep("|", true, Inconsistent, pats, |s, p| s.print_pat(p));
}
- PatKind::Tuple(ref elts, ddpos) => {
+ PatKind::Tuple(elts, ddpos) => {
self.popen();
if let Some(ddpos) = ddpos {
- self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, &elts[..ddpos], |s, p| s.print_pat(p));
if ddpos != 0 {
self.word_space(",");
}
self.word("..");
if ddpos != elts.len() {
self.word(",");
- self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, &elts[ddpos..], |s, p| s.print_pat(p));
}
} else {
- self.commasep(Inconsistent, &elts[..], |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, elts, |s, p| s.print_pat(p));
if elts.len() == 1 {
self.word(",");
}
}
self.pclose();
}
- PatKind::Box(ref inner) => {
+ PatKind::Box(inner) => {
let is_range_inner = matches!(inner.kind, PatKind::Range(..));
self.word("box ");
if is_range_inner {
self.popen();
}
- self.print_pat(&inner);
+ self.print_pat(inner);
if is_range_inner {
self.pclose();
}
}
- PatKind::Ref(ref inner, mutbl) => {
+ PatKind::Ref(inner, mutbl) => {
let is_range_inner = matches!(inner.kind, PatKind::Range(..));
self.word("&");
self.word(mutbl.prefix_str());
if is_range_inner {
self.popen();
}
- self.print_pat(&inner);
+ self.print_pat(inner);
if is_range_inner {
self.pclose();
}
}
- PatKind::Lit(ref e) => self.print_expr(&e),
- PatKind::Range(ref begin, ref end, ref end_kind) => {
+ PatKind::Lit(e) => self.print_expr(e),
+ PatKind::Range(begin, end, end_kind) => {
if let Some(expr) = begin {
self.print_expr(expr);
}
- match *end_kind {
+ match end_kind {
RangeEnd::Included => self.word("..."),
RangeEnd::Excluded => self.word(".."),
}
self.print_expr(expr);
}
}
- PatKind::Slice(ref before, ref slice, ref after) => {
+ PatKind::Slice(before, slice, after) => {
self.word("[");
- self.commasep(Inconsistent, &before, |s, p| s.print_pat(&p));
- if let Some(ref p) = *slice {
+ self.commasep(Inconsistent, before, |s, p| s.print_pat(p));
+ if let Some(p) = slice {
if !before.is_empty() {
self.word_space(",");
}
if let PatKind::Wild = p.kind {
// Print nothing.
} else {
- self.print_pat(&p);
+ self.print_pat(p);
}
self.word("..");
if !after.is_empty() {
self.word_space(",");
}
}
- self.commasep(Inconsistent, &after, |s, p| s.print_pat(&p));
+ self.commasep(Inconsistent, after, |s, p| s.print_pat(p));
self.word("]");
}
}
pub fn print_param(&mut self, arg: &hir::Param<'_>) {
self.print_outer_attributes(self.attrs(arg.hir_id));
- self.print_pat(&arg.pat);
+ self.print_pat(arg.pat);
}
pub fn print_arm(&mut self, arm: &hir::Arm<'_>) {
self.cbox(INDENT_UNIT);
self.ann.pre(self, AnnNode::Arm(arm));
self.ibox(0);
- self.print_outer_attributes(&self.attrs(arm.hir_id));
- self.print_pat(&arm.pat);
+ self.print_outer_attributes(self.attrs(arm.hir_id));
+ self.print_pat(arm.pat);
self.space();
if let Some(ref g) = arm.guard {
- match g {
+ match *g {
hir::Guard::If(e) => {
self.word_space("if");
- self.print_expr(&e);
+ self.print_expr(e);
self.space();
}
- hir::Guard::IfLet(hir::Let { pat, ty, init, .. }) => {
+ hir::Guard::IfLet(&hir::Let { pat, ty, init, .. }) => {
self.word_nbsp("if");
- self.print_let(pat, *ty, init);
+ self.print_let(pat, ty, init);
}
}
}
self.word_space("=>");
match arm.body.kind {
- hir::ExprKind::Block(ref blk, opt_label) => {
+ hir::ExprKind::Block(blk, opt_label) => {
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.word_space(":");
}
// the block will close the pattern's ibox
- self.print_block_unclosed(&blk);
+ self.print_block_unclosed(blk);
// If it is a user-provided unsafe block, print a comma after it
if let hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided) = blk.rules
}
_ => {
self.end(); // close the ibox for the pattern
- self.print_expr(&arm.body);
+ self.print_expr(arm.body);
self.word(",");
}
}
self.nbsp();
self.print_name(name);
}
- self.print_generic_params(&generics.params);
+ self.print_generic_params(generics.params);
self.popen();
let mut i = 0;
// Make sure we aren't supplied *both* `arg_names` and `body_id`.
assert!(arg_names.is_empty() || body_id.is_none());
- self.commasep(Inconsistent, &decl.inputs, |s, ty| {
+ self.commasep(Inconsistent, decl.inputs, |s, ty| {
s.ibox(INDENT_UNIT);
if let Some(arg_name) = arg_names.get(i) {
s.word(arg_name.to_string());
fn print_closure_params(&mut self, decl: &hir::FnDecl<'_>, body_id: hir::BodyId) {
self.word("|");
let mut i = 0;
- self.commasep(Inconsistent, &decl.inputs, |s, ty| {
+ self.commasep(Inconsistent, decl.inputs, |s, ty| {
s.ibox(INDENT_UNIT);
s.ann.nested(s, Nested::BodyParamPat(body_id, i));
self.space_if_not_bol();
self.word_space("->");
match decl.output {
- hir::FnRetTy::Return(ref ty) => {
- self.print_type(&ty);
+ hir::FnRetTy::Return(ty) => {
+ self.print_type(ty);
self.maybe_print_comment(ty.span.lo());
}
hir::FnRetTy::DefaultReturn(..) => unreachable!(),
match param.kind {
GenericParamKind::Lifetime { .. } => {}
- GenericParamKind::Type { ref default, .. } => {
+ GenericParamKind::Type { default, .. } => {
if let Some(default) = default {
self.space();
self.word_space("=");
- self.print_type(&default)
+ self.print_type(default);
}
}
- GenericParamKind::Const { ref ty, ref default } => {
+ GenericParamKind::Const { ty, ref default } => {
self.word_space(":");
self.print_type(ty);
- if let Some(ref default) = default {
+ if let Some(default) = default {
self.space();
self.word_space("=");
- self.print_anon_const(&default)
+ self.print_anon_const(default);
}
}
}
self.word_space(",");
}
- match predicate {
+ match *predicate {
hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
bound_generic_params,
bounded_ty,
..
}) => {
self.print_formal_generic_params(bound_generic_params);
- self.print_type(&bounded_ty);
- self.print_bounds(":", *bounds);
+ self.print_type(bounded_ty);
+ self.print_bounds(":", bounds);
}
hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
- lifetime,
+ ref lifetime,
bounds,
..
}) => {
pub fn print_mt(&mut self, mt: &hir::MutTy<'_>, print_const: bool) {
self.print_mutability(mt.mutbl, print_const);
- self.print_type(&mt.ty)
+ self.print_type(mt.ty);
}
pub fn print_fn_output(&mut self, decl: &hir::FnDecl<'_>) {
self.word_space("->");
match decl.output {
hir::FnRetTy::DefaultReturn(..) => unreachable!(),
- hir::FnRetTy::Return(ref ty) => self.print_type(&ty),
+ hir::FnRetTy::Return(ty) => self.print_type(ty),
}
self.end();
- if let hir::FnRetTy::Return(ref output) = decl.output {
+ if let hir::FnRetTy::Return(output) = decl.output {
self.maybe_print_comment(output.span.lo());
}
}
asyncness: hir::IsAsync::NotAsync,
},
name,
- &generics,
+ generics,
arg_names,
None,
);
match *stmt {
hir::StmtKind::Local(_) => true,
hir::StmtKind::Item(_) => false,
- hir::StmtKind::Expr(ref e) => expr_requires_semi_to_be_stmt(&e),
+ hir::StmtKind::Expr(e) => expr_requires_semi_to_be_stmt(e),
hir::StmtKind::Semi(..) => false,
}
}
match value.kind {
hir::ExprKind::Struct(..) => true,
- hir::ExprKind::Assign(ref lhs, ref rhs, _)
- | hir::ExprKind::AssignOp(_, ref lhs, ref rhs)
- | hir::ExprKind::Binary(_, ref lhs, ref rhs) => {
+ hir::ExprKind::Assign(lhs, rhs, _)
+ | hir::ExprKind::AssignOp(_, lhs, rhs)
+ | hir::ExprKind::Binary(_, lhs, rhs) => {
// `X { y: 1 } + X { y: 2 }`
- contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
+ contains_exterior_struct_lit(lhs) || contains_exterior_struct_lit(rhs)
}
- hir::ExprKind::Unary(_, ref x)
- | hir::ExprKind::Cast(ref x, _)
- | hir::ExprKind::Type(ref x, _)
- | hir::ExprKind::Field(ref x, _)
- | hir::ExprKind::Index(ref x, _) => {
+ hir::ExprKind::Unary(_, x)
+ | hir::ExprKind::Cast(x, _)
+ | hir::ExprKind::Type(x, _)
+ | hir::ExprKind::Field(x, _)
+ | hir::ExprKind::Index(x, _) => {
// `&X { y: 1 }, X { y: 1 }.y`
- contains_exterior_struct_lit(&x)
+ contains_exterior_struct_lit(x)
}
- hir::ExprKind::MethodCall(.., ref exprs, _) => {
+ hir::ExprKind::MethodCall(.., exprs, _) => {
// `X { y: 1 }.bar(...)`
contains_exterior_struct_lit(&exprs[0])
}