Skip to content

Commit e80cced

Browse files
Use write! instead of p! to avoid having to use weird scoping
1 parent 20cea3e commit e80cced

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+12-25
Original file line numberDiff line numberDiff line change
@@ -817,25 +817,18 @@ pub trait PrettyPrinter<'tcx>:
817817
}
818818
}
819819

820-
{
821-
define_scoped_cx!(self);
822-
p!("impl ");
823-
}
820+
write!(self, "impl ")?;
824821

825822
let mut first = true;
826823
// Insert parenthesis around (Fn(A, B) -> C) if the opaque ty has more than one other trait
827824
let paren_needed = fn_traits.len() > 1 || traits.len() > 0 || !is_sized;
828825

829826
for (fn_once_trait_ref, entry) in fn_traits {
830-
{
831-
define_scoped_cx!(self);
832-
p!(
833-
write("{}", if first { "" } else { " + " }),
834-
write("{}", if paren_needed { "(" } else { "" })
835-
);
836-
}
827+
write!(self, "{}", if first { "" } else { " + " })?;
828+
write!(self, "{}", if paren_needed { "(" } else { "" })?;
837829

838-
self = self.wrap_binder(&fn_once_trait_ref, |trait_ref, mut self_| {
830+
self = self.wrap_binder(&fn_once_trait_ref, |trait_ref, mut cx| {
831+
define_scoped_cx!(cx);
839832
// Get the (single) generic ty (the args) of this FnOnce trait ref.
840833
let generics = tcx.generics_of(trait_ref.def_id);
841834
let args = generics.own_substs_no_defaults(tcx, trait_ref.substs);
@@ -852,7 +845,6 @@ pub trait PrettyPrinter<'tcx>:
852845
"FnOnce"
853846
};
854847

855-
define_scoped_cx!(self_);
856848
p!(write("{}(", name));
857849

858850
for (idx, ty) in arg_tys.tuple_fields().iter().enumerate() {
@@ -892,19 +884,16 @@ pub trait PrettyPrinter<'tcx>:
892884
}
893885
}
894886

895-
Ok(self_)
887+
Ok(cx)
896888
})?;
897889
}
898890

899891
// Print the rest of the trait types (that aren't Fn* family of traits)
900892
for (trait_ref, assoc_items) in traits {
901-
{
902-
define_scoped_cx!(self);
903-
p!(write("{}", if first { "" } else { " + " }));
904-
}
893+
write!(self, "{}", if first { "" } else { " + " })?;
905894

906-
self = self.wrap_binder(&trait_ref, |trait_ref, mut self_| {
907-
define_scoped_cx!(self_);
895+
self = self.wrap_binder(&trait_ref, |trait_ref, mut cx| {
896+
define_scoped_cx!(cx);
908897
p!(print(trait_ref.print_only_trait_name()));
909898

910899
let generics = tcx.generics_of(trait_ref.def_id);
@@ -969,16 +958,14 @@ pub trait PrettyPrinter<'tcx>:
969958
}
970959

971960
first = false;
972-
Ok(self_)
961+
Ok(cx)
973962
})?;
974963
}
975964

976-
define_scoped_cx!(self);
977-
978965
if !is_sized {
979-
p!(write("{}?Sized", if first { "" } else { " + " }));
966+
write!(self, "{}?Sized", if first { "" } else { " + " })?;
980967
} else if first {
981-
p!("Sized");
968+
write!(self, "Sized")?;
982969
}
983970

984971
Ok(self)

src/test/ui/async-await/issue-70935-complex-spans.drop_tracking.stderr

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

0 commit comments

Comments
 (0)