Skip to content

Commit 1a14315

Browse files
committed
Don't concatenate binders across types
1 parent 4fdac23 commit 1a14315

File tree

4 files changed

+215
-86
lines changed

4 files changed

+215
-86
lines changed

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

+87-22
Original file line numberDiff line numberDiff line change
@@ -1802,29 +1802,94 @@ impl<F: fmt::Write> FmtPrinter<'_, 'tcx, F> {
18021802
define_scoped_cx!(self);
18031803

18041804
let mut region_index = self.region_index;
1805-
let new_value = self.tcx.replace_late_bound_regions(value.clone(), |br| {
1806-
let _ = start_or_continue(&mut self, "for<", ", ");
1807-
let kind = match br.kind {
1808-
ty::BrNamed(_, name) => {
1809-
let _ = write!(self, "{}", name);
1810-
br.kind
1811-
}
1812-
ty::BrAnon(_) | ty::BrEnv => {
1813-
let name = loop {
1814-
let name = name_by_region_index(region_index);
1815-
region_index += 1;
1816-
if !self.used_region_names.contains(&name) {
1817-
break name;
1818-
}
1819-
};
1820-
let _ = write!(self, "{}", name);
1821-
ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name)
1805+
// If we want to print verbosly, then print *all* binders, even if they
1806+
// aren't named. Eventually, we might just want this as the default, but
1807+
// this is not *quite* right and changes the ordering of some output
1808+
// anyways.
1809+
let new_value = if self.tcx().sess.verbose() {
1810+
// anon index + 1 (BrEnv takes 0) -> name
1811+
let mut region_map: BTreeMap<u32, Symbol> = BTreeMap::default();
1812+
let bound_vars = value.bound_vars();
1813+
for var in bound_vars {
1814+
match var {
1815+
ty::BoundVariableKind::Region(ty::BrNamed(_, name)) => {
1816+
let _ = start_or_continue(&mut self, "for<", ", ");
1817+
let _ = write!(self, "{}", name);
1818+
}
1819+
ty::BoundVariableKind::Region(ty::BrAnon(i)) => {
1820+
let _ = start_or_continue(&mut self, "for<", ", ");
1821+
let name = loop {
1822+
let name = name_by_region_index(region_index);
1823+
region_index += 1;
1824+
if !self.used_region_names.contains(&name) {
1825+
break name;
1826+
}
1827+
};
1828+
let _ = write!(self, "{}", name);
1829+
region_map.insert(i + 1, name);
1830+
}
1831+
ty::BoundVariableKind::Region(ty::BrEnv) => {
1832+
let _ = start_or_continue(&mut self, "for<", ", ");
1833+
let name = loop {
1834+
let name = name_by_region_index(region_index);
1835+
region_index += 1;
1836+
if !self.used_region_names.contains(&name) {
1837+
break name;
1838+
}
1839+
};
1840+
let _ = write!(self, "{}", name);
1841+
region_map.insert(0, name);
1842+
}
1843+
_ => continue,
18221844
}
1823-
};
1824-
self.tcx
1825-
.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { var: br.var, kind }))
1826-
});
1827-
start_or_continue(&mut self, "", "> ")?;
1845+
}
1846+
start_or_continue(&mut self, "", "> ")?;
1847+
1848+
self.tcx.replace_late_bound_regions(value.clone(), |br| {
1849+
let kind = match br.kind {
1850+
ty::BrNamed(_, _) => br.kind,
1851+
ty::BrAnon(i) => {
1852+
let name = region_map[&(i + 1)];
1853+
ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name)
1854+
}
1855+
ty::BrEnv => {
1856+
let name = region_map[&0];
1857+
ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name)
1858+
}
1859+
};
1860+
self.tcx.mk_region(ty::ReLateBound(
1861+
ty::INNERMOST,
1862+
ty::BoundRegion { var: br.var, kind },
1863+
))
1864+
})
1865+
} else {
1866+
let new_value = self.tcx.replace_late_bound_regions(value.clone(), |br| {
1867+
let _ = start_or_continue(&mut self, "for<", ", ");
1868+
let kind = match br.kind {
1869+
ty::BrNamed(_, name) => {
1870+
let _ = write!(self, "{}", name);
1871+
br.kind
1872+
}
1873+
ty::BrAnon(_) | ty::BrEnv => {
1874+
let name = loop {
1875+
let name = name_by_region_index(region_index);
1876+
region_index += 1;
1877+
if !self.used_region_names.contains(&name) {
1878+
break name;
1879+
}
1880+
};
1881+
let _ = write!(self, "{}", name);
1882+
ty::BrNamed(DefId::local(CRATE_DEF_INDEX), name)
1883+
}
1884+
};
1885+
self.tcx.mk_region(ty::ReLateBound(
1886+
ty::INNERMOST,
1887+
ty::BoundRegion { var: br.var, kind },
1888+
))
1889+
});
1890+
start_or_continue(&mut self, "", "> ")?;
1891+
new_value
1892+
};
18281893

18291894
self.binder_depth += 1;
18301895
self.region_index = region_index;

compiler/rustc_mir/src/transform/generator.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,10 @@ fn sanitize_witness<'tcx>(
751751
span_bug!(
752752
body.span,
753753
"Broken MIR: generator contains type {} in MIR, \
754-
but typeck only knows about {}",
755-
decl.ty,
756-
witness,
754+
but typeck only knows about {} and {:?}",
755+
decl_ty,
756+
allowed,
757+
allowed_upvars
757758
);
758759
}
759760
}

0 commit comments

Comments
 (0)