type Output = ();
type Error = fmt::Error;
fn print(&$self, $cx: &mut PrintCx<'_, '_, 'tcx, P>) -> fmt::Result {
- define_scoped_cx!($cx);
- if $cx.config.is_debug $dbg
- else $disp
+ Ok({
+ define_scoped_cx!($cx);
+ if $cx.config.is_debug $dbg
+ else $disp
+ })
}
}
};
type Output = ();
type Error = fmt::Error;
fn print(&$self, $cx: &mut PrintCx<'_, '_, 'tcx, P>) -> fmt::Result {
- define_scoped_cx!($cx);
- if $cx.config.is_debug $dbg
- else $disp
+ Ok({
+ define_scoped_cx!($cx);
+ if $cx.config.is_debug $dbg
+ else $disp
+ })
}
}
};
( $generic:tt $target:ty,
($self:ident, $cx:ident) { display $disp:block } ) => {
gen_print_impl! { $generic $target, ($self, $cx) yes $disp no {
- write!($cx.printer, "{:?}", $self)
+ write!($cx.printer, "{:?}", $self)?
} }
};
}
}
macro_rules! p {
($($kind:ident $data:tt),+) => {
- (|| -> fmt::Result {
- $(print_inner!($kind $data)?;)+
- Ok(())
- })()
+ {
+ $(print_inner!($kind $data)?);+
+ }
};
}
macro_rules! define_scoped_cx {
) -> fmt::Result {
define_scoped_cx!(self);
- p!(write("("))?;
+ p!(write("("));
let mut inputs = inputs.iter();
if let Some(&ty) = inputs.next() {
- p!(print_display(ty))?;
+ p!(print_display(ty));
for &ty in inputs {
- p!(write(", "), print_display(ty))?;
+ p!(write(", "), print_display(ty));
}
if c_variadic {
- p!(write(", ..."))?;
+ p!(write(", ..."));
}
}
- p!(write(")"))?;
+ p!(write(")"));
if !output.is_unit() {
- p!(write(" -> "), print_display(output))?;
+ p!(write(" -> "), print_display(output));
}
Ok(())
let mut empty = true;
let mut start_or_continue = |cx: &mut Self, start: &str, cont: &str| {
- define_scoped_cx!(cx);
-
- if empty {
+ write!(cx.printer, "{}", if empty {
empty = false;
- p!(write("{}", start))
+ start
} else {
- p!(write("{}", cont))
- }
+ cont
+ })
};
// NOTE(eddyb) this must be below `start_or_continue`'s definition
let _ = start_or_continue(self, "for<", ", ");
let br = match br {
ty::BrNamed(_, name) => {
- let _ = p!(write("{}", name));
+ let _ = write!(self.printer, "{}", name);
br
}
ty::BrAnon(_) |
break name;
}
};
- let _ = p!(write("{}", name));
+ let _ = write!(self.printer, "{}", name);
ty::BrNamed(self.tcx.hir().local_def_id(CRATE_NODE_ID), name)
}
};
for (_, def_id) in auto_traits {
if !first {
- p!(write(" + "))?;
+ p!(write(" + "));
}
first = false;
iter::empty(),
)?;
}
-
- Ok(())
}
}
}
p!(write("UpvarId({:?};`{}`;{:?})",
self.var_path.hir_id,
cx.tcx.hir().name_by_hir_id(self.var_path.hir_id),
- self.closure_expr_id))
+ self.closure_expr_id));
+ Ok(())
})
}
}
define_print! {
('tcx) &'tcx ty::List<Ty<'tcx>>, (self, cx) {
display {
- p!(write("{{"))?;
+ p!(write("{{"));
let mut tys = self.iter();
if let Some(&ty) = tys.next() {
- p!(print(ty))?;
+ p!(print(ty));
for &ty in tys {
- p!(write(", "), print(ty))?;
+ p!(write(", "), print(ty));
}
}
p!(write("}}"))
display {
let dummy_self = cx.tcx.mk_infer(ty::FreshTy(0));
- ty::Binder::bind(*self)
+ p!(print_display(ty::Binder::bind(*self)
.with_self_ty(cx.tcx, dummy_self)
- .skip_binder()
- .print_display(cx)
+ .skip_binder()))
}
debug {
- self.print_display(cx)
+ p!(print_display(self))
}
}
}
if let BrNamed(_, name) = *self {
if name != "" && name != "'_" {
- return p!(write("{}", name));
+ p!(write("{}", name));
+ return Ok(());
}
}
let highlight = RegionHighlightMode::get();
if let Some((region, counter)) = highlight.highlight_bound_region {
if *self == region {
- return p!(write("'{}", counter));
+ p!(write("'{}", counter));
}
}
-
- Ok(())
}
debug {
- return match *self {
+ match *self {
BrAnon(n) => p!(write("BrAnon({:?})", n)),
BrFresh(n) => p!(write("BrFresh({:?})", n)),
BrNamed(did, name) => {
did.krate, did.index, name))
}
BrEnv => p!(write("BrEnv")),
- };
+ }
}
}
}
let highlight = RegionHighlightMode::get();
if let Some(counter) = highlight.placeholder_highlight(*self) {
- return p!(write("'{}", counter));
+ p!(write("'{}", counter));
+ } else {
+ p!(print_display(self.name));
}
-
- p!(print_display(self.name))
}
}
}
// Watch out for region highlights.
if let Some(n) = RegionHighlightMode::get().region_highlighted(self) {
- return p!(write("'{:?}", n));
+ p!(write("'{:?}", n));
+ return Ok(());
}
// These printouts are concise. They do not contain all the information
ty::ReEarlyBound(ref data) => {
if data.name != "'_" {
p!(write("{}", data.name))
- } else {
- Ok(())
}
}
ty::ReLateBound(_, br) |
p!(print_display(region_vid))
}
ty::ReScope(_) |
- ty::ReErased => Ok(()),
+ ty::ReErased => {}
ty::ReStatic => p!(write("'static")),
ty::ReEmpty => p!(write("'<empty>")),
ty::Contravariant => "-",
ty::Invariant => "o",
ty::Bivariant => "*",
- })
+ })?
}
}
}
('tcx) ty::FnSig<'tcx>, (self, cx) {
display {
if self.unsafety == hir::Unsafety::Unsafe {
- p!(write("unsafe "))?;
+ p!(write("unsafe "));
}
if self.abi != Abi::Rust {
- p!(write("extern {} ", self.abi))?;
+ p!(write("extern {} ", self.abi));
}
- p!(write("fn"))?;
- cx.fn_sig(self.inputs(), self.c_variadic, self.output())
+ p!(write("fn"));
+ cx.fn_sig(self.inputs(), self.c_variadic, self.output())?
}
debug {
p!(write("({:?}; c_variadic: {})->{:?}",
let highlight = RegionHighlightMode::get();
if let Some(counter) = highlight.region_highlighted(&ty::ReVar(*self)) {
- return p!(write("'{:?}", counter));
+ p!(write("'{:?}", counter));
}
-
- Ok(())
}
debug {
// HACK(eddyb) this is duplicated from `display` printing,
// to keep NLL borrowck working even with `-Zverbose`.
let highlight = RegionHighlightMode::get();
if let Some(counter) = highlight.region_highlighted(&ty::ReVar(*self)) {
- return p!(write("'{:?}", counter));
+ p!(write("'{:?}", counter));
+ } else {
+ p!(write("'_#{}r", self.index()));
}
-
- p!(write("'_#{}r", self.index()))
}
}
}
]
(self, cx) {
display {
- cx.in_binder(self)
+ cx.in_binder(self)?
}
}
}
Namespace::TypeNS,
iter::empty(),
)?;
- Ok(())
}
debug {
let _ = cx.path_qualified(None, self.self_ty(), Some(*self), Namespace::TypeNS)?;
- Ok(())
}
}
}
p!(write("*{} ", match tm.mutbl {
hir::MutMutable => "mut",
hir::MutImmutable => "const",
- }))?;
- tm.ty.print(cx)
+ }));
+ p!(print(tm.ty))
}
Ref(r, ty, mutbl) => {
- p!(write("&"))?;
+ p!(write("&"));
if r.display_outputs_anything(cx) {
- p!(print_display(r), write(" "))?;
+ p!(print_display(r), write(" "));
}
- ty::TypeAndMut { ty, mutbl }.print(cx)
+ p!(print(ty::TypeAndMut { ty, mutbl }))
}
Never => p!(write("!")),
Tuple(ref tys) => {
- p!(write("("))?;
+ p!(write("("));
let mut tys = tys.iter();
if let Some(&ty) = tys.next() {
- p!(print(ty), write(","))?;
+ p!(print(ty), write(","));
if let Some(&ty) = tys.next() {
- p!(write(" "), print(ty))?;
+ p!(write(" "), print(ty));
for &ty in tys {
- p!(write(", "), print(ty))?;
+ p!(write(", "), print(ty));
}
}
}
}
FnDef(def_id, substs) => {
let sig = cx.tcx.fn_sig(def_id).subst(cx.tcx, substs);
- p!(print(sig), write(" {{"))?;
+ p!(print(sig), write(" {{"));
let _ = cx.print_def_path(
def_id,
Some(substs),
p!(write("}}"))
}
FnPtr(ref bare_fn) => {
- bare_fn.print(cx)
+ p!(print(bare_fn))
}
Infer(infer_ty) => p!(write("{}", infer_ty)),
Error => p!(write("[type error]")),
Namespace::TypeNS,
iter::empty(),
)?;
- Ok(())
}
Dynamic(data, r) => {
let print_r = r.display_outputs_anything(cx);
if print_r {
- p!(write("("))?;
+ p!(write("("));
}
- p!(write("dyn "))?;
- data.print(cx)?;
+ p!(write("dyn "), print(data));
if print_r {
- p!(write(" + "), print_display(r), write(")"))?;
+ p!(write(" + "), print_display(r), write(")"));
}
- Ok(())
}
Foreign(def_id) => {
let _ = cx.print_def_path(
Namespace::TypeNS,
iter::empty(),
)?;
- Ok(())
}
- Projection(ref data) => data.print(cx),
+ Projection(ref data) => p!(print(data)),
UnnormalizedProjection(ref data) => {
- p!(write("Unnormalized("))?;
+ p!(write("Unnormalized("));
data.print(cx)?;
p!(write(")"))
}
}
Opaque(def_id, substs) => {
if cx.config.is_verbose {
- return p!(write("Opaque({:?}, {:?})", def_id, substs));
+ p!(write("Opaque({:?}, {:?})", def_id, substs));
+ return Ok(());
}
let def_key = cx.tcx.def_key(def_id);
if let Some(name) = def_key.disambiguated_data.data.get_opt_name() {
- p!(write("{}", name))?;
+ p!(write("{}", name));
let mut substs = substs.iter();
// FIXME(eddyb) print this with `print_def_path`.
if let Some(first) = substs.next() {
- p!(write("::<"))?;
- p!(write("{}", first))?;
+ p!(write("::<"));
+ p!(write("{}", first));
for subst in substs {
- p!(write(", {}", subst))?;
+ p!(write(", {}", subst));
}
- p!(write(">"))?;
+ p!(write(">"));
}
return Ok(());
}
let mut first = true;
let mut is_sized = false;
- p!(write("impl"))?;
+ p!(write("impl"));
for predicate in bounds.predicates {
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
// Don't print +Sized, but rather +?Sized if absent.
p!(
write("{}", if first { " " } else { "+" }),
- print(trait_ref))?;
+ print(trait_ref));
first = false;
}
}
if !is_sized {
- p!(write("{}?Sized", if first { " " } else { "+" }))?;
+ p!(write("{}?Sized", if first { " " } else { "+" }));
} else if first {
- p!(write(" Sized"))?;
+ p!(write(" Sized"));
}
- Ok(())
}
Str => p!(write("str")),
Generator(did, substs, movability) => {
let upvar_tys = substs.upvar_tys(did, cx.tcx);
let witness = substs.witness(did, cx.tcx);
if movability == hir::GeneratorMovability::Movable {
- p!(write("[generator"))?;
+ p!(write("[generator"));
} else {
- p!(write("[static generator"))?;
+ p!(write("[static generator"));
}
// FIXME(eddyb) should use `def_span`.
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(did) {
- p!(write("@{:?}", cx.tcx.hir().span_by_hir_id(hir_id)))?;
+ p!(write("@{:?}", cx.tcx.hir().span_by_hir_id(hir_id)));
let mut sep = " ";
cx.tcx.with_freevars(hir_id, |freevars| {
for (freevar, upvar_ty) in freevars.iter().zip(upvar_tys) {
write("{}{}:",
sep,
cx.tcx.hir().name(freevar.var_id())),
- print(upvar_ty))?;
+ print(upvar_ty));
sep = ", ";
}
Ok(())
} else {
// cross-crate closure types should only be
// visible in codegen bug reports, I imagine.
- p!(write("@{:?}", did))?;
+ p!(write("@{:?}", did));
let mut sep = " ";
for (index, upvar_ty) in upvar_tys.enumerate() {
p!(
write("{}{}:", sep, index),
- print(upvar_ty))?;
+ print(upvar_ty));
sep = ", ";
}
}
p!(write(" "), print(witness), write("]"))
},
GeneratorWitness(types) => {
- cx.in_binder(&types)
+ cx.in_binder(&types)?
}
Closure(did, substs) => {
let upvar_tys = substs.upvar_tys(did, cx.tcx);
- p!(write("[closure"))?;
+ p!(write("[closure"));
// FIXME(eddyb) should use `def_span`.
if let Some(hir_id) = cx.tcx.hir().as_local_hir_id(did) {
if cx.tcx.sess.opts.debugging_opts.span_free_formats {
- p!(write("@{:?}", hir_id))?;
+ p!(write("@{:?}", hir_id));
} else {
- p!(write("@{:?}", cx.tcx.hir().span_by_hir_id(hir_id)))?;
+ p!(write("@{:?}", cx.tcx.hir().span_by_hir_id(hir_id)));
}
let mut sep = " ";
cx.tcx.with_freevars(hir_id, |freevars| {
write("{}{}:",
sep,
cx.tcx.hir().name(freevar.var_id())),
- print(upvar_ty))?;
+ print(upvar_ty));
sep = ", ";
}
Ok(())
} else {
// cross-crate closure types should only be
// visible in codegen bug reports, I imagine.
- p!(write("@{:?}", did))?;
+ p!(write("@{:?}", did));
let mut sep = " ";
for (index, upvar_ty) in upvar_tys.enumerate() {
p!(
write("{}{}:", sep, index),
- print(upvar_ty))?;
+ print(upvar_ty));
sep = ", ";
}
}
- if cx.is_verbose {
+ if cx.config.is_verbose {
p!(write(
" closure_kind_ty={:?} closure_sig_ty={:?}",
substs.closure_kind_ty(did, cx.tcx),
substs.closure_sig_ty(did, cx.tcx)
- ))?;
+ ));
}
p!(write("]"))
},
Array(ty, sz) => {
- p!(write("["), print(ty), write("; "))?;
+ p!(write("["), print(ty), write("; "));
match sz {
ty::LazyConst::Unevaluated(_def_id, _substs) => {
- p!(write("_"))?;
+ p!(write("_"));
}
ty::LazyConst::Evaluated(c) => {
match c.val {
- ConstValue::Infer(..) => p!(write("_"))?,
+ ConstValue::Infer(..) => p!(write("_")),
ConstValue::Param(ParamConst { name, .. }) =>
- p!(write("{}", name))?,
- _ => p!(write("{}", c.unwrap_usize(cx.tcx)))?,
+ p!(write("{}", name)),
+ _ => p!(write("{}", c.unwrap_usize(cx.tcx))),
}
}
}
}
}
debug {
- self.print_display(cx)
+ p!(print_display(self))
}
}
}
Namespace::TypeNS,
iter::empty(),
)?;
- Ok(())
}
}
}
('tcx) ty::Predicate<'tcx>, (self, cx) {
display {
match *self {
- ty::Predicate::Trait(ref data) => data.print(cx),
- ty::Predicate::Subtype(ref predicate) => predicate.print(cx),
- ty::Predicate::RegionOutlives(ref predicate) => predicate.print(cx),
- ty::Predicate::TypeOutlives(ref predicate) => predicate.print(cx),
- ty::Predicate::Projection(ref predicate) => predicate.print(cx),
+ ty::Predicate::Trait(ref data) => p!(print(data)),
+ ty::Predicate::Subtype(ref predicate) => p!(print(predicate)),
+ ty::Predicate::RegionOutlives(ref predicate) => p!(print(predicate)),
+ ty::Predicate::TypeOutlives(ref predicate) => p!(print(predicate)),
+ ty::Predicate::Projection(ref predicate) => p!(print(predicate)),
ty::Predicate::WellFormed(ty) => p!(print(ty), write(" well-formed")),
ty::Predicate::ObjectSafe(trait_def_id) => {
- p!(write("the trait `"))?;
+ p!(write("the trait `"));
let _ = cx.print_def_path(
trait_def_id,
None,
p!(write("` is object-safe"))
}
ty::Predicate::ClosureKind(closure_def_id, _closure_substs, kind) => {
- p!(write("the closure `"))?;
+ p!(write("the closure `"));
let _ = cx.print_def_path(
closure_def_id,
None,
p!(write("` implements the trait `{}`", kind))
}
ty::Predicate::ConstEvaluatable(def_id, substs) => {
- p!(write("the constant `"))?;
+ p!(write("the constant `"));
let _ = cx.print_def_path(
def_id,
Some(substs),
}
debug {
match *self {
- ty::Predicate::Trait(ref a) => a.print(cx),
- ty::Predicate::Subtype(ref pair) => pair.print(cx),
- ty::Predicate::RegionOutlives(ref pair) => pair.print(cx),
- ty::Predicate::TypeOutlives(ref pair) => pair.print(cx),
- ty::Predicate::Projection(ref pair) => pair.print(cx),
- ty::Predicate::WellFormed(ty) => ty.print(cx),
+ ty::Predicate::Trait(ref a) => p!(print(a)),
+ ty::Predicate::Subtype(ref pair) => p!(print(pair)),
+ ty::Predicate::RegionOutlives(ref pair) => p!(print(pair)),
+ ty::Predicate::TypeOutlives(ref pair) => p!(print(pair)),
+ ty::Predicate::Projection(ref pair) => p!(print(pair)),
+ ty::Predicate::WellFormed(ty) => p!(print(ty)),
ty::Predicate::ObjectSafe(trait_def_id) => {
p!(write("ObjectSafe({:?})", trait_def_id))
}