Do not ICE on unnamed future

This commit is contained in:
Esteban Küber 2019-12-13 15:27:55 -08:00
parent de0abf7599
commit e08944fdaf
4 changed files with 57 additions and 4 deletions

View file

@ -1016,8 +1016,8 @@ impl<'hir> Map<'hir> {
}
}
pub fn name(&self, id: HirId) -> Name {
match self.get(id) {
pub fn opt_name(&self, id: HirId) -> Option<Name> {
Some(match self.get(id) {
Node::Item(i) => i.ident.name,
Node::ForeignItem(fi) => fi.ident.name,
Node::ImplItem(ii) => ii.ident.name,
@ -1028,7 +1028,14 @@ impl<'hir> Map<'hir> {
Node::GenericParam(param) => param.name.ident().name,
Node::Binding(&Pat { kind: PatKind::Binding(_, _, l, _), .. }) => l.name,
Node::Ctor(..) => self.name(self.get_parent_item(id)),
_ => bug!("no name for {}", self.node_to_string(id))
_ => return None,
})
}
pub fn name(&self, id: HirId) -> Name {
match self.opt_name(id) {
Some(name) => name,
None => bug!("no name for {}", self.node_to_string(id)),
}
}

View file

@ -2353,7 +2353,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let message = if let Some(name) = last_generator
.and_then(|generator_did| self.tcx.parent(generator_did))
.and_then(|parent_did| self.tcx.hir().as_local_hir_id(parent_did))
.map(|parent_hir_id| self.tcx.hir().name(parent_hir_id))
.and_then(|parent_hir_id| self.tcx.hir().opt_name(parent_hir_id))
{
format!("future returned by `{}` is not {}", name, trait_name)
} else {