use std::borrow::Cow;
use std::cell::Cell;
-use std::collections::BTreeMap;
use std::vec;
pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: hir::HirId) -> String {
pub struct State<'a> {
pub s: pp::Printer,
comments: Option<Comments<'a>>,
- attrs: &'a BTreeMap<hir::HirId, &'a [ast::Attribute]>,
+ attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
ann: &'a (dyn PpAnn + 'a),
}
/// it can scan the input text for comments to copy forward.
pub fn print_crate<'a>(
sm: &'a SourceMap,
- krate: &hir::Crate<'_>,
+ krate: &hir::Mod<'_>,
filename: FileName,
input: String,
+ attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
ann: &'a dyn PpAnn,
) -> String {
- let mut s = State::new_from_input(sm, filename, input, &krate.attrs, ann);
+ let mut s = State::new_from_input(sm, filename, input, attrs, ann);
// 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.module(), s.attrs(hir::CRATE_HIR_ID));
+ s.print_mod(krate, (*attrs)(hir::CRATE_HIR_ID));
s.print_remaining_comments();
s.s.eof()
}
sm: &'a SourceMap,
filename: FileName,
input: String,
- attrs: &'a BTreeMap<hir::HirId, &[ast::Attribute]>,
+ attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute],
ann: &'a dyn PpAnn,
) -> State<'a> {
State {
}
fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] {
- self.attrs.get(&id).map_or(&[], |la| *la)
+ (self.attrs)(id)
}
}
where
F: FnOnce(&mut State<'_>),
{
- let mut printer =
- State { s: pp::mk_printer(), comments: None, attrs: &BTreeMap::default(), ann };
+ let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann };
f(&mut printer);
printer.s.eof()
}
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr) || npals())
}
- // Does `expr` need parenthesis when printed in a condition position?
+ // Does `expr` need parentheses when printed in a condition position?
//
// These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.