1 // Type resolution: the phase that finds all the types in the AST with
2 // unresolved type variables and replaces "ty_var" types with their
5 use crate::check::FnCtxt;
6 use errors::DiagnosticBuilder;
8 use rustc::hir::def_id::{DefId, DefIndex};
9 use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
10 use rustc::infer::InferCtxt;
11 use rustc::ty::adjustment::{Adjust, Adjustment};
12 use rustc::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder};
13 use rustc::ty::subst::UnpackedKind;
14 use rustc::ty::{self, Ty, TyCtxt};
15 use rustc::util::nodemap::DefIdSet;
16 use rustc_data_structures::sync::Lrc;
21 ///////////////////////////////////////////////////////////////////////////
24 // During type inference, partially inferred types are
25 // represented using Type variables (ty::Infer). These don't appear in
26 // the final TypeckTables since all of the types should have been
27 // inferred once typeck_tables_of is done.
28 // When type inference is running however, having to update the typeck
29 // tables every time a new type is inferred would be unreasonably slow,
30 // so instead all of the replacement happens at the end in
31 // resolve_type_vars_in_body, which creates a new TypeTables which
32 // doesn't contain any inference types.
33 impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
34 pub fn resolve_type_vars_in_body(&self, body: &'gcx hir::Body) -> &'gcx ty::TypeckTables<'gcx> {
35 let item_id = self.tcx.hir().body_owner(body.id());
36 let item_def_id = self.tcx.hir().local_def_id(item_id);
38 // This attribute causes us to dump some writeback information
39 // in the form of errors, which is used for unit tests.
40 let rustc_dump_user_substs = self.tcx.has_attr(item_def_id, "rustc_dump_user_substs");
42 let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_substs);
43 for arg in &body.arguments {
44 wbcx.visit_node_id(arg.pat.span, arg.hir_id);
46 wbcx.visit_body(body);
47 wbcx.visit_upvar_capture_map();
48 wbcx.visit_upvar_list_map();
49 wbcx.visit_closures();
50 wbcx.visit_liberated_fn_sigs();
51 wbcx.visit_fru_field_types();
52 wbcx.visit_opaque_types(body.value.span);
53 wbcx.visit_cast_types();
54 wbcx.visit_free_region_map();
55 wbcx.visit_user_provided_tys();
56 wbcx.visit_user_provided_sigs();
58 let used_trait_imports = mem::replace(
59 &mut self.tables.borrow_mut().used_trait_imports,
60 Lrc::new(DefIdSet::default()),
63 "used_trait_imports({:?}) = {:?}",
64 item_def_id, used_trait_imports
66 wbcx.tables.used_trait_imports = used_trait_imports;
68 wbcx.tables.tainted_by_errors = self.is_tainted_by_errors();
71 "writeback: tables for {:?} are {:#?}",
72 item_def_id, wbcx.tables
75 self.tcx.alloc_tables(wbcx.tables)
79 ///////////////////////////////////////////////////////////////////////////
80 // The Writeback context. This visitor walks the AST, checking the
81 // fn-specific tables to find references to types or regions. It
82 // resolves those regions to remove inference variables and writes the
83 // final result back into the master tables in the tcx. Here and
84 // there, it applies a few ad-hoc checks that were not convenient to
87 struct WritebackCx<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
88 fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
90 tables: ty::TypeckTables<'gcx>,
92 body: &'gcx hir::Body,
94 rustc_dump_user_substs: bool,
97 impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
99 fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
100 body: &'gcx hir::Body,
101 rustc_dump_user_substs: bool,
102 ) -> WritebackCx<'cx, 'gcx, 'tcx> {
103 let owner = fcx.tcx.hir().definitions().node_to_hir_id(body.id().node_id);
107 tables: ty::TypeckTables::empty(Some(DefId::local(owner.owner))),
109 rustc_dump_user_substs,
113 fn tcx(&self) -> TyCtxt<'cx, 'gcx, 'tcx> {
117 fn write_ty_to_tables(&mut self, hir_id: hir::HirId, ty: Ty<'gcx>) {
118 debug!("write_ty_to_tables({:?}, {:?})", hir_id, ty);
119 assert!(!ty.needs_infer() && !ty.has_placeholders());
120 self.tables.node_types_mut().insert(hir_id, ty);
123 // Hacky hack: During type-checking, we treat *all* operators
124 // as potentially overloaded. But then, during writeback, if
125 // we observe that something like `a+b` is (known to be)
126 // operating on scalars, we clear the overload.
127 fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr) {
129 hir::ExprKind::Unary(hir::UnNeg, ref inner)
130 | hir::ExprKind::Unary(hir::UnNot, ref inner) => {
131 let inner_ty = self.fcx.node_ty(inner.hir_id);
132 let inner_ty = self.fcx.resolve_type_vars_if_possible(&inner_ty);
134 if inner_ty.is_scalar() {
135 let mut tables = self.fcx.tables.borrow_mut();
136 tables.type_dependent_defs_mut().remove(e.hir_id);
137 tables.node_substs_mut().remove(e.hir_id);
140 hir::ExprKind::Binary(ref op, ref lhs, ref rhs)
141 | hir::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => {
142 let lhs_ty = self.fcx.node_ty(lhs.hir_id);
143 let lhs_ty = self.fcx.resolve_type_vars_if_possible(&lhs_ty);
145 let rhs_ty = self.fcx.node_ty(rhs.hir_id);
146 let rhs_ty = self.fcx.resolve_type_vars_if_possible(&rhs_ty);
148 if lhs_ty.is_scalar() && rhs_ty.is_scalar() {
149 let mut tables = self.fcx.tables.borrow_mut();
150 tables.type_dependent_defs_mut().remove(e.hir_id);
151 tables.node_substs_mut().remove(e.hir_id);
154 hir::ExprKind::Binary(..) => {
155 if !op.node.is_by_value() {
156 let mut adjustments = tables.adjustments_mut();
157 adjustments.get_mut(lhs.hir_id).map(|a| a.pop());
158 adjustments.get_mut(rhs.hir_id).map(|a| a.pop());
161 hir::ExprKind::AssignOp(..) => {
175 // Similar to operators, indexing is always assumed to be overloaded
176 // Here, correct cases where an indexing expression can be simplified
177 // to use builtin indexing because the index type is known to be
179 fn fix_index_builtin_expr(&mut self, e: &hir::Expr) {
180 if let hir::ExprKind::Index(ref base, ref index) = e.node {
181 let mut tables = self.fcx.tables.borrow_mut();
183 // All valid indexing looks like this; might encounter non-valid indexes at this point
184 if let ty::Ref(_, base_ty, _) = tables.expr_ty_adjusted(&base).sty {
185 let index_ty = tables.expr_ty_adjusted(&index);
186 let index_ty = self.fcx.resolve_type_vars_if_possible(&index_ty);
188 if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize {
189 // Remove the method call record
190 tables.type_dependent_defs_mut().remove(e.hir_id);
191 tables.node_substs_mut().remove(e.hir_id);
193 tables.adjustments_mut().get_mut(base.hir_id).map(|a| {
194 // Discard the need for a mutable borrow
196 // Extra adjustment made when indexing causes a drop
197 // of size information - we need to get rid of it
198 // Since this is "after" the other adjustment to be
199 // discarded, we do an extra `pop()`
201 kind: Adjust::Unsize,
204 // So the borrow discard actually happens here
216 ///////////////////////////////////////////////////////////////////////////
217 // Impl of Visitor for Resolver
219 // This is the master code which walks the AST. It delegates most of
220 // the heavy lifting to the generic visit and resolve functions
221 // below. In general, a function is made into a `visitor` if it must
222 // traffic in node-ids or update tables in the type context etc.
224 impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
225 fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
226 NestedVisitorMap::None
229 fn visit_expr(&mut self, e: &'gcx hir::Expr) {
230 self.fix_scalar_builtin_expr(e);
231 self.fix_index_builtin_expr(e);
233 self.visit_node_id(e.span, e.hir_id);
236 hir::ExprKind::Closure(_, _, body, _, _) => {
237 let body = self.fcx.tcx.hir().body(body);
238 for arg in &body.arguments {
239 self.visit_node_id(e.span, arg.hir_id);
242 self.visit_body(body);
244 hir::ExprKind::Struct(_, ref fields, _) => {
245 for field in fields {
246 self.visit_field_id(field.id);
249 hir::ExprKind::Field(..) => {
250 self.visit_field_id(e.id);
255 intravisit::walk_expr(self, e);
258 fn visit_block(&mut self, b: &'gcx hir::Block) {
259 self.visit_node_id(b.span, b.hir_id);
260 intravisit::walk_block(self, b);
263 fn visit_pat(&mut self, p: &'gcx hir::Pat) {
265 hir::PatKind::Binding(..) => {
266 if let Some(&bm) = self.fcx.tables.borrow().pat_binding_modes().get(p.hir_id) {
267 self.tables.pat_binding_modes_mut().insert(p.hir_id, bm);
271 .delay_span_bug(p.span, "missing binding mode");
274 hir::PatKind::Struct(_, ref fields, _) => {
275 for field in fields {
276 self.visit_field_id(field.node.id);
282 self.visit_pat_adjustments(p.span, p.hir_id);
284 self.visit_node_id(p.span, p.hir_id);
285 intravisit::walk_pat(self, p);
288 fn visit_local(&mut self, l: &'gcx hir::Local) {
289 intravisit::walk_local(self, l);
290 let var_ty = self.fcx.local_ty(l.span, l.id).decl_ty;
291 let var_ty = self.resolve(&var_ty, &l.span);
292 self.write_ty_to_tables(l.hir_id, var_ty);
295 fn visit_ty(&mut self, hir_ty: &'gcx hir::Ty) {
296 intravisit::walk_ty(self, hir_ty);
297 let ty = self.fcx.node_ty(hir_ty.hir_id);
298 let ty = self.resolve(&ty, &hir_ty.span);
299 self.write_ty_to_tables(hir_ty.hir_id, ty);
303 impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
304 fn visit_upvar_capture_map(&mut self) {
305 for (upvar_id, upvar_capture) in self.fcx.tables.borrow().upvar_capture_map.iter() {
306 let new_upvar_capture = match *upvar_capture {
307 ty::UpvarCapture::ByValue => ty::UpvarCapture::ByValue,
308 ty::UpvarCapture::ByRef(ref upvar_borrow) => {
309 let r = upvar_borrow.region;
310 let r = self.resolve(&r, &upvar_id.var_path.hir_id);
311 ty::UpvarCapture::ByRef(ty::UpvarBorrow {
312 kind: upvar_borrow.kind,
318 "Upvar capture for {:?} resolved to {:?}",
319 upvar_id, new_upvar_capture
323 .insert(*upvar_id, new_upvar_capture);
327 /// Runs through the function context's upvar list map and adds the same to
328 /// the TypeckTables. upvarlist is a hashmap of the list of upvars referred
329 /// to in a closure..
330 fn visit_upvar_list_map(&mut self) {
331 for (closure_def_id, upvar_list) in self.fcx.tables.borrow().upvar_list.iter() {
333 "UpvarIDs captured by closure {:?} are: {:?}",
334 closure_def_id, upvar_list
338 .insert(*closure_def_id, upvar_list.to_vec());
342 fn visit_closures(&mut self) {
343 let fcx_tables = self.fcx.tables.borrow();
344 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
345 let common_local_id_root = fcx_tables.local_id_root.unwrap();
347 for (&id, &origin) in fcx_tables.closure_kind_origins().iter() {
348 let hir_id = hir::HirId {
349 owner: common_local_id_root.index,
353 .closure_kind_origins_mut()
354 .insert(hir_id, origin);
358 fn visit_cast_types(&mut self) {
359 let fcx_tables = self.fcx.tables.borrow();
360 let fcx_cast_kinds = fcx_tables.cast_kinds();
361 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
362 let mut self_cast_kinds = self.tables.cast_kinds_mut();
363 let common_local_id_root = fcx_tables.local_id_root.unwrap();
365 for (&local_id, &cast_kind) in fcx_cast_kinds.iter() {
366 let hir_id = hir::HirId {
367 owner: common_local_id_root.index,
370 self_cast_kinds.insert(hir_id, cast_kind);
374 fn visit_free_region_map(&mut self) {
375 let free_region_map = self.tcx()
376 .lift_to_global(&self.fcx.tables.borrow().free_region_map);
377 let free_region_map = free_region_map.expect("all regions in free-region-map are global");
378 self.tables.free_region_map = free_region_map;
381 fn visit_user_provided_tys(&mut self) {
382 let fcx_tables = self.fcx.tables.borrow();
383 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
384 let common_local_id_root = fcx_tables.local_id_root.unwrap();
386 let mut errors_buffer = Vec::new();
387 for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() {
388 let hir_id = hir::HirId {
389 owner: common_local_id_root.index,
393 let c_ty = if let Some(c_ty) = self.tcx().lift_to_global(c_ty) {
397 hir_id.to_span(&self.fcx.tcx),
398 "writeback: `{:?}` missing from the global type context",
404 .user_provided_types_mut()
405 .insert(hir_id, c_ty.clone());
407 if let ty::UserType::TypeOf(_, user_substs) = c_ty.value {
408 if self.rustc_dump_user_substs {
409 // This is a unit-testing mechanism.
410 let span = self.tcx().hir().span_by_hir_id(hir_id);
411 // We need to buffer the errors in order to guarantee a consistent
412 // order when emitting them.
413 let err = self.tcx().sess.struct_span_err(
415 &format!("user substs: {:?}", user_substs)
417 err.buffer(&mut errors_buffer);
422 if !errors_buffer.is_empty() {
423 errors_buffer.sort_by_key(|diag| diag.span.primary_span());
424 for diag in errors_buffer.drain(..) {
425 DiagnosticBuilder::new_diagnostic(self.tcx().sess.diagnostic(), diag).emit();
430 fn visit_user_provided_sigs(&mut self) {
431 let fcx_tables = self.fcx.tables.borrow();
432 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
434 for (&def_id, c_sig) in fcx_tables.user_provided_sigs.iter() {
435 let c_sig = if let Some(c_sig) = self.tcx().lift_to_global(c_sig) {
439 self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
440 "writeback: `{:?}` missing from the global type context",
447 .insert(def_id, c_sig.clone());
451 fn visit_opaque_types(&mut self, span: Span) {
452 for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
453 let node_id = self.tcx().hir().as_local_node_id(def_id).unwrap();
454 let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &node_id);
456 let generics = self.tcx().generics_of(def_id);
458 let definition_ty = if generics.parent.is_some() {
460 self.fcx.infer_opaque_definition_from_instantiation(
467 // * `fn foo<T>() -> Foo<T>`
468 // * `fn foo<T: Bound + Other>() -> Foo<T>`
469 // from being defining
471 // Also replace all generic params with the ones from the existential type
474 // existential type Foo<T>: 'static;
475 // fn foo<U>() -> Foo<U> { .. }
477 // figures out the concrete type with `U`, but the stored type is with `T`
478 instantiated_ty.fold_with(&mut BottomUpFolder {
479 tcx: self.tcx().global_tcx(),
481 trace!("checking type {:?}: {:#?}", ty, ty.sty);
482 // find a type parameter
483 if let ty::Param(..) = ty.sty {
484 // look it up in the substitution list
485 assert_eq!(opaque_defn.substs.len(), generics.params.len());
486 for (subst, param) in opaque_defn.substs.iter().zip(&generics.params) {
487 if let UnpackedKind::Type(subst) = subst.unpack() {
489 // found it in the substitution list, replace with the
490 // parameter from the existential type
493 .mk_ty_param(param.index, param.name);
502 "type parameter `{}` is part of concrete type but not used \
503 in parameter list for existential type",
508 return self.tcx().types.err;
514 // ignore static regions
515 ty::ReStatic => region,
517 trace!("checking {:?}", region);
518 for (subst, p) in opaque_defn.substs.iter().zip(&generics.params) {
519 if let UnpackedKind::Lifetime(subst) = subst.unpack() {
521 // found it in the substitution list, replace with the
522 // parameter from the existential type
523 let reg = ty::EarlyBoundRegion {
528 trace!("replace {:?} with {:?}", region, reg);
531 .mk_region(ty::ReEarlyBound(reg));
535 trace!("opaque_defn: {:#?}", opaque_defn);
536 trace!("generics: {:#?}", generics);
541 "non-defining existential type use in defining scope",
546 "lifetime `{}` is part of concrete type but not used \
547 in parameter list of existential type",
552 self.tcx().global_tcx().mk_region(ty::ReStatic)
559 if let ty::Opaque(defin_ty_def_id, _substs) = definition_ty.sty {
560 if def_id == defin_ty_def_id {
561 // Concrete type resolved to the existential type itself
562 // Force a cycle error
563 self.tcx().at(span).type_of(defin_ty_def_id);
567 let old = self.tables
568 .concrete_existential_types
569 .insert(def_id, definition_ty);
570 if let Some(old) = old {
571 if old != definition_ty {
574 "visit_opaque_types tried to write \
575 different types for the same existential type: {:?}, {:?}, {:?}",
585 fn visit_field_id(&mut self, node_id: ast::NodeId) {
586 let hir_id = self.tcx().hir().node_to_hir_id(node_id);
587 if let Some(index) = self.fcx
593 self.tables.field_indices_mut().insert(hir_id, index);
597 fn visit_node_id(&mut self, span: Span, hir_id: hir::HirId) {
598 // Export associated path extensions and method resolutions.
599 if let Some(def) = self.fcx
602 .type_dependent_defs_mut()
605 self.tables.type_dependent_defs_mut().insert(hir_id, def);
608 // Resolve any borrowings for the node with id `node_id`
609 self.visit_adjustments(span, hir_id);
611 // Resolve the type of the node with id `node_id`
612 let n_ty = self.fcx.node_ty(hir_id);
613 let n_ty = self.resolve(&n_ty, &span);
614 self.write_ty_to_tables(hir_id, n_ty);
615 debug!("Node {:?} has type {:?}", hir_id, n_ty);
617 // Resolve any substitutions
618 if let Some(substs) = self.fcx.tables.borrow().node_substs_opt(hir_id) {
619 let substs = self.resolve(&substs, &span);
620 debug!("write_substs_to_tcx({:?}, {:?})", hir_id, substs);
621 assert!(!substs.needs_infer() && !substs.has_placeholders());
622 self.tables.node_substs_mut().insert(hir_id, substs);
626 fn visit_adjustments(&mut self, span: Span, hir_id: hir::HirId) {
627 let adjustment = self.fcx
634 debug!("No adjustments for node {:?}", hir_id);
637 Some(adjustment) => {
638 let resolved_adjustment = self.resolve(&adjustment, &span);
640 "Adjustments for node {:?}: {:?}",
641 hir_id, resolved_adjustment
645 .insert(hir_id, resolved_adjustment);
650 fn visit_pat_adjustments(&mut self, span: Span, hir_id: hir::HirId) {
651 let adjustment = self.fcx
654 .pat_adjustments_mut()
658 debug!("No pat_adjustments for node {:?}", hir_id);
661 Some(adjustment) => {
662 let resolved_adjustment = self.resolve(&adjustment, &span);
664 "pat_adjustments for node {:?}: {:?}",
665 hir_id, resolved_adjustment
668 .pat_adjustments_mut()
669 .insert(hir_id, resolved_adjustment);
674 fn visit_liberated_fn_sigs(&mut self) {
675 let fcx_tables = self.fcx.tables.borrow();
676 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
677 let common_local_id_root = fcx_tables.local_id_root.unwrap();
679 for (&local_id, fn_sig) in fcx_tables.liberated_fn_sigs().iter() {
680 let hir_id = hir::HirId {
681 owner: common_local_id_root.index,
684 let fn_sig = self.resolve(fn_sig, &hir_id);
686 .liberated_fn_sigs_mut()
687 .insert(hir_id, fn_sig.clone());
691 fn visit_fru_field_types(&mut self) {
692 let fcx_tables = self.fcx.tables.borrow();
693 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
694 let common_local_id_root = fcx_tables.local_id_root.unwrap();
696 for (&local_id, ftys) in fcx_tables.fru_field_types().iter() {
697 let hir_id = hir::HirId {
698 owner: common_local_id_root.index,
701 let ftys = self.resolve(ftys, &hir_id);
702 self.tables.fru_field_types_mut().insert(hir_id, ftys);
706 fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T::Lifted
708 T: TypeFoldable<'tcx> + ty::Lift<'gcx>,
710 let x = x.fold_with(&mut Resolver::new(self.fcx, span, self.body));
711 if let Some(lifted) = self.tcx().lift_to_global(&x) {
715 span.to_span(&self.fcx.tcx),
716 "writeback: `{:?}` missing from the global type context",
724 fn to_span(&self, tcx: &TyCtxt) -> Span;
727 impl Locatable for Span {
728 fn to_span(&self, _: &TyCtxt) -> Span {
733 impl Locatable for ast::NodeId {
734 fn to_span(&self, tcx: &TyCtxt) -> Span {
735 tcx.hir().span(*self)
739 impl Locatable for DefIndex {
740 fn to_span(&self, tcx: &TyCtxt) -> Span {
741 let hir_id = tcx.hir().def_index_to_hir_id(*self);
742 tcx.hir().span_by_hir_id(hir_id)
746 impl Locatable for hir::HirId {
747 fn to_span(&self, tcx: &TyCtxt) -> Span {
748 tcx.hir().span_by_hir_id(*self)
752 ///////////////////////////////////////////////////////////////////////////
753 // The Resolver. This is the type folding engine that detects
754 // unresolved types and so forth.
756 struct Resolver<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
757 tcx: TyCtxt<'cx, 'gcx, 'tcx>,
758 infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
759 span: &'cx dyn Locatable,
760 body: &'gcx hir::Body,
763 impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
765 fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
766 span: &'cx dyn Locatable,
767 body: &'gcx hir::Body,
768 ) -> Resolver<'cx, 'gcx, 'tcx> {
777 fn report_error(&self, t: Ty<'tcx>) {
778 if !self.tcx.sess.has_errors() {
780 .need_type_info_err(Some(self.body.id()), self.span.to_span(&self.tcx), t)
786 impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Resolver<'cx, 'gcx, 'tcx> {
787 fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx> {
791 fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
792 match self.infcx.fully_resolve(&t) {
796 "Resolver::fold_ty: input type `{:?}` not fully resolvable",
799 self.report_error(t);
805 // FIXME This should be carefully checked
806 // We could use `self.report_error` but it doesn't accept a ty::Region, right now.
807 fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
808 self.infcx.fully_resolve(&r).unwrap_or(self.tcx.types.re_static)
812 ///////////////////////////////////////////////////////////////////////////
813 // During type check, we store promises with the result of trait
814 // lookup rather than the actual results (because the results are not
815 // necessarily available immediately). These routines unwind the
816 // promises. It is expected that we will have already reported any
817 // errors that may be encountered, so if the promises store an error,
818 // a dummy result is returned.