Skip to content

Commit

Permalink
Rollup merge of rust-lang#97737 - jackh726:verbose-pretty-printing-fi…
Browse files Browse the repository at this point in the history
…x, r=compiler-errors

Fix pretty printing named bound regions under -Zverbose

Fixed regression introduced in rust-lang#97023

r? `@compiler-errors`

cc `@cjgillot`
  • Loading branch information
matthiaskrgr authored Jun 4, 2022
2 parents 8d0de3a + dd38fec commit 1794309
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2190,34 +2190,40 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
// this is not *quite* right and changes the ordering of some output
// anyways.
let (new_value, map) = if self.tcx().sess.verbose() {
// anon index + 1 (BrEnv takes 0) -> name
let mut region_map: FxHashMap<_, _> = Default::default();
let bound_vars = value.bound_vars();
for var in bound_vars {
let ty::BoundVariableKind::Region(var) = var else { continue };
match var {
ty::BrAnon(_) | ty::BrEnv => {
start_or_continue(&mut self, "for<", ", ");
let name = next_name(&self);
do_continue(&mut self, name);
region_map.insert(var, ty::BrNamed(CRATE_DEF_ID.to_def_id(), name));
}
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
start_or_continue(&mut self, "for<", ", ");
let name = next_name(&self);
do_continue(&mut self, name);
region_map.insert(var, ty::BrNamed(def_id, name));
}
ty::BrNamed(_, name) => {
start_or_continue(&mut self, "for<", ", ");
do_continue(&mut self, name);
let regions: Vec<_> = value
.bound_vars()
.into_iter()
.map(|var| {
let ty::BoundVariableKind::Region(var) = var else {
// This doesn't really matter because it doesn't get used,
// it's just an empty value
return ty::BrAnon(0);
};
match var {
ty::BrAnon(_) | ty::BrEnv => {
start_or_continue(&mut self, "for<", ", ");
let name = next_name(&self);
do_continue(&mut self, name);
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
}
ty::BrNamed(def_id, kw::UnderscoreLifetime) => {
start_or_continue(&mut self, "for<", ", ");
let name = next_name(&self);
do_continue(&mut self, name);
ty::BrNamed(def_id, name)
}
ty::BrNamed(def_id, name) => {
start_or_continue(&mut self, "for<", ", ");
do_continue(&mut self, name);
ty::BrNamed(def_id, name)
}
}
}
}
})
.collect();
start_or_continue(&mut self, "", "> ");

self.tcx.replace_late_bound_regions(value.clone(), |br| {
let kind = region_map[&br.kind];
let kind = regions[br.var.as_usize()];
self.tcx.mk_region(ty::ReLateBound(
ty::INNERMOST,
ty::BoundRegion { var: br.var, kind },
Expand Down

0 comments on commit 1794309

Please sign in to comment.