Add an optional Span to BrAnon and use it to print better error for HRTB error from generator interior
This commit is contained in:
parent
1e1e5b8d98
commit
00e314d5ed
23 changed files with 251 additions and 63 deletions
|
@ -728,7 +728,7 @@ fn bound_vars_for_item<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx
|
|||
ty::GenericParamDefKind::Lifetime => {
|
||||
let br = ty::BoundRegion {
|
||||
var: ty::BoundVar::from_usize(substs.len()),
|
||||
kind: ty::BrAnon(substs.len() as u32),
|
||||
kind: ty::BrAnon(substs.len() as u32, None),
|
||||
};
|
||||
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
|
||||
}
|
||||
|
|
|
@ -498,13 +498,13 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime<RustInterner<'t
|
|||
ty::DebruijnIndex::from_u32(var.debruijn.depth()),
|
||||
ty::BoundRegion {
|
||||
var: ty::BoundVar::from_usize(var.index),
|
||||
kind: ty::BrAnon(var.index as u32),
|
||||
kind: ty::BrAnon(var.index as u32, None),
|
||||
},
|
||||
),
|
||||
chalk_ir::LifetimeData::InferenceVar(_var) => unimplemented!(),
|
||||
chalk_ir::LifetimeData::Placeholder(p) => ty::RePlaceholder(ty::Placeholder {
|
||||
universe: ty::UniverseIndex::from_usize(p.ui.counter),
|
||||
name: ty::BoundRegionKind::BrAnon(p.idx as u32),
|
||||
name: ty::BoundRegionKind::BrAnon(p.idx as u32, None),
|
||||
}),
|
||||
chalk_ir::LifetimeData::Static => return interner.tcx.lifetimes.re_static,
|
||||
chalk_ir::LifetimeData::Empty(_) => {
|
||||
|
@ -933,7 +933,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ty::BoundRegionKind::BrAnon(var) => match self.parameters.entry(var) {
|
||||
ty::BoundRegionKind::BrAnon(var, _) => match self.parameters.entry(var) {
|
||||
Entry::Vacant(entry) => {
|
||||
entry.insert(chalk_ir::VariableKind::Lifetime);
|
||||
}
|
||||
|
@ -991,13 +991,13 @@ impl<'a, 'tcx> TypeFolder<'tcx> for NamedBoundVarSubstitutor<'a, 'tcx> {
|
|||
ty::ReLateBound(index, br) if index == self.binder_index => match br.kind {
|
||||
ty::BrNamed(def_id, _name) => match self.named_parameters.get(&def_id) {
|
||||
Some(idx) => {
|
||||
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx) };
|
||||
let new_br = ty::BoundRegion { var: br.var, kind: ty::BrAnon(*idx, None) };
|
||||
return self.tcx.mk_region(ty::ReLateBound(index, new_br));
|
||||
}
|
||||
None => panic!("Missing `BrNamed`."),
|
||||
},
|
||||
ty::BrEnv => unimplemented!(),
|
||||
ty::BrAnon(_) => {}
|
||||
ty::BrAnon(..) => {}
|
||||
},
|
||||
_ => (),
|
||||
};
|
||||
|
@ -1072,14 +1072,16 @@ impl<'tcx> TypeFolder<'tcx> for ParamsSubstitutor<'tcx> {
|
|||
Some(idx) => {
|
||||
let br = ty::BoundRegion {
|
||||
var: ty::BoundVar::from_u32(*idx),
|
||||
kind: ty::BrAnon(*idx),
|
||||
kind: ty::BrAnon(*idx, None),
|
||||
};
|
||||
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
|
||||
}
|
||||
None => {
|
||||
let idx = self.named_regions.len() as u32;
|
||||
let br =
|
||||
ty::BoundRegion { var: ty::BoundVar::from_u32(idx), kind: ty::BrAnon(idx) };
|
||||
let br = ty::BoundRegion {
|
||||
var: ty::BoundVar::from_u32(idx),
|
||||
kind: ty::BrAnon(idx, None),
|
||||
};
|
||||
self.named_regions.insert(_re.def_id, idx);
|
||||
self.tcx.mk_region(ty::ReLateBound(self.binder_index, br))
|
||||
}
|
||||
|
@ -1156,7 +1158,7 @@ impl<'tcx> TypeVisitor<'tcx> for PlaceholdersCollector {
|
|||
fn visit_region(&mut self, r: Region<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
match *r {
|
||||
ty::RePlaceholder(p) if p.universe == self.universe_index => {
|
||||
if let ty::BoundRegionKind::BrAnon(anon) = p.name {
|
||||
if let ty::BoundRegionKind::BrAnon(anon, _) = p.name {
|
||||
self.next_anon_region_placeholder = self.next_anon_region_placeholder.max(anon);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue