Use write! instead of p! to avoid having to use weird scoping

This commit is contained in:
Michael Goulet 2022-06-22 10:21:24 -07:00
parent 20cea3ebb4
commit e80ccedbae
2 changed files with 13 additions and 26 deletions

View File

@ -817,25 +817,18 @@ pub trait PrettyPrinter<'tcx>:
}
}
{
define_scoped_cx!(self);
p!("impl ");
}
write!(self, "impl ")?;
let mut first = true;
// Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
let paren_needed = fn_traits.len() > 1 || traits.len() > 0 || !is_sized;
for (fn_once_trait_ref, entry) in fn_traits {
{
define_scoped_cx!(self);
p!(
write("{}", if first { "" } else { " + " }),
write("{}", if paren_needed { "(" } else { "" })
);
}
write!(self, "{}", if first { "" } else { " + " })?;
write!(self, "{}", if paren_needed { "(" } else { "" })?;
self = self.wrap_binder(&fn_once_trait_ref, |trait_ref, mut self_| {
self = self.wrap_binder(&fn_once_trait_ref, |trait_ref, mut cx| {
define_scoped_cx!(cx);
// Get the (single) generic ty (the args) of this FnOnce trait ref.
let generics = tcx.generics_of(trait_ref.def_id);
let args = generics.own_substs_no_defaults(tcx, trait_ref.substs);
@ -852,7 +845,6 @@ pub trait PrettyPrinter<'tcx>:
"FnOnce"
};
define_scoped_cx!(self_);
p!(write("{}(", name));
for (idx, ty) in arg_tys.tuple_fields().iter().enumerate() {
@ -892,19 +884,16 @@ pub trait PrettyPrinter<'tcx>:
}
}
Ok(self_)
Ok(cx)
})?;
}
// Print the rest of the trait types (that aren't Fn* family of traits)
for (trait_ref, assoc_items) in traits {
{
define_scoped_cx!(self);
p!(write("{}", if first { "" } else { " + " }));
}
write!(self, "{}", if first { "" } else { " + " })?;
self = self.wrap_binder(&trait_ref, |trait_ref, mut self_| {
define_scoped_cx!(self_);
self = self.wrap_binder(&trait_ref, |trait_ref, mut cx| {
define_scoped_cx!(cx);
p!(print(trait_ref.print_only_trait_name()));
let generics = tcx.generics_of(trait_ref.def_id);
@ -969,16 +958,14 @@ pub trait PrettyPrinter<'tcx>:
}
first = false;
Ok(self_)
Ok(cx)
})?;
}
define_scoped_cx!(self);
if !is_sized {
p!(write("{}?Sized", if first { "" } else { " + " }));
write!(self, "{}?Sized", if first { "" } else { " + " })?;
} else if first {
p!("Sized");
write!(self, "Sized")?;
}
Ok(self)

View File

@ -22,7 +22,7 @@ LL | async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> {
LL | |
LL | | }
| |_^
= note: required because it captures the following types: `ResumeTy`, `impl Future<Output = ()>`, `()`
= note: required because it captures the following types: `ResumeTy`, `impl for<'r, 's, 't0> Future<Output = ()>`, `()`
note: required because it's used within this `async` block
--> $DIR/issue-70935-complex-spans.rs:23:16
|