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, PointerCast};
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;
20 ///////////////////////////////////////////////////////////////////////////
23 // During type inference, partially inferred types are
24 // represented using Type variables (ty::Infer). These don't appear in
25 // the final TypeckTables since all of the types should have been
26 // inferred once typeck_tables_of is done.
27 // When type inference is running however, having to update the typeck
28 // tables every time a new type is inferred would be unreasonably slow,
29 // so instead all of the replacement happens at the end in
30 // resolve_type_vars_in_body, which creates a new TypeTables which
31 // doesn't contain any inference types.
32 impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
33 pub fn resolve_type_vars_in_body(&self, body: &'gcx hir::Body) -> &'gcx ty::TypeckTables<'gcx> {
34 let item_id = self.tcx.hir().body_owner(body.id());
35 let item_def_id = self.tcx.hir().local_def_id(item_id);
37 // This attribute causes us to dump some writeback information
38 // in the form of errors, which is used for unit tests.
39 let rustc_dump_user_substs = self.tcx.has_attr(item_def_id, "rustc_dump_user_substs");
41 let mut wbcx = WritebackCx::new(self, body, rustc_dump_user_substs);
42 for arg in &body.arguments {
43 wbcx.visit_node_id(arg.pat.span, arg.hir_id);
45 // Type only exists for constants and statics, not functions.
46 match self.tcx.hir().body_owner_kind(item_id) {
47 hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => {
48 let item_hir_id = self.tcx.hir().node_to_hir_id(item_id);
49 wbcx.visit_node_id(body.value.span, item_hir_id);
51 hir::BodyOwnerKind::Closure | hir::BodyOwnerKind::Fn => (),
53 wbcx.visit_body(body);
54 wbcx.visit_upvar_capture_map();
55 wbcx.visit_upvar_list_map();
56 wbcx.visit_closures();
57 wbcx.visit_liberated_fn_sigs();
58 wbcx.visit_fru_field_types();
59 wbcx.visit_opaque_types(body.value.span);
60 wbcx.visit_coercion_casts();
61 wbcx.visit_free_region_map();
62 wbcx.visit_user_provided_tys();
63 wbcx.visit_user_provided_sigs();
65 let used_trait_imports = mem::replace(
66 &mut self.tables.borrow_mut().used_trait_imports,
67 Lrc::new(DefIdSet::default()),
70 "used_trait_imports({:?}) = {:?}",
71 item_def_id, used_trait_imports
73 wbcx.tables.used_trait_imports = used_trait_imports;
75 wbcx.tables.tainted_by_errors = self.is_tainted_by_errors();
78 "writeback: tables for {:?} are {:#?}",
79 item_def_id, wbcx.tables
82 self.tcx.alloc_tables(wbcx.tables)
86 ///////////////////////////////////////////////////////////////////////////
87 // The Writeback context. This visitor walks the AST, checking the
88 // fn-specific tables to find references to types or regions. It
89 // resolves those regions to remove inference variables and writes the
90 // final result back into the master tables in the tcx. Here and
91 // there, it applies a few ad-hoc checks that were not convenient to
94 struct WritebackCx<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
95 fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
97 tables: ty::TypeckTables<'gcx>,
99 body: &'gcx hir::Body,
101 rustc_dump_user_substs: bool,
104 impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
106 fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
107 body: &'gcx hir::Body,
108 rustc_dump_user_substs: bool,
109 ) -> WritebackCx<'cx, 'gcx, 'tcx> {
110 let owner = body.id().hir_id;
114 tables: ty::TypeckTables::empty(Some(DefId::local(owner.owner))),
116 rustc_dump_user_substs,
120 fn tcx(&self) -> TyCtxt<'cx, 'gcx, 'tcx> {
124 fn write_ty_to_tables(&mut self, hir_id: hir::HirId, ty: Ty<'gcx>) {
125 debug!("write_ty_to_tables({:?}, {:?})", hir_id, ty);
126 assert!(!ty.needs_infer() && !ty.has_placeholders());
127 self.tables.node_types_mut().insert(hir_id, ty);
130 // Hacky hack: During type-checking, we treat *all* operators
131 // as potentially overloaded. But then, during writeback, if
132 // we observe that something like `a+b` is (known to be)
133 // operating on scalars, we clear the overload.
134 fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr) {
136 hir::ExprKind::Unary(hir::UnNeg, ref inner)
137 | hir::ExprKind::Unary(hir::UnNot, ref inner) => {
138 let inner_ty = self.fcx.node_ty(inner.hir_id);
139 let inner_ty = self.fcx.resolve_type_vars_if_possible(&inner_ty);
141 if inner_ty.is_scalar() {
142 let mut tables = self.fcx.tables.borrow_mut();
143 tables.type_dependent_defs_mut().remove(e.hir_id);
144 tables.node_substs_mut().remove(e.hir_id);
147 hir::ExprKind::Binary(ref op, ref lhs, ref rhs)
148 | hir::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => {
149 let lhs_ty = self.fcx.node_ty(lhs.hir_id);
150 let lhs_ty = self.fcx.resolve_type_vars_if_possible(&lhs_ty);
152 let rhs_ty = self.fcx.node_ty(rhs.hir_id);
153 let rhs_ty = self.fcx.resolve_type_vars_if_possible(&rhs_ty);
155 if lhs_ty.is_scalar() && rhs_ty.is_scalar() {
156 let mut tables = self.fcx.tables.borrow_mut();
157 tables.type_dependent_defs_mut().remove(e.hir_id);
158 tables.node_substs_mut().remove(e.hir_id);
161 hir::ExprKind::Binary(..) => {
162 if !op.node.is_by_value() {
163 let mut adjustments = tables.adjustments_mut();
164 adjustments.get_mut(lhs.hir_id).map(|a| a.pop());
165 adjustments.get_mut(rhs.hir_id).map(|a| a.pop());
168 hir::ExprKind::AssignOp(..) => {
182 // Similar to operators, indexing is always assumed to be overloaded
183 // Here, correct cases where an indexing expression can be simplified
184 // to use builtin indexing because the index type is known to be
186 fn fix_index_builtin_expr(&mut self, e: &hir::Expr) {
187 if let hir::ExprKind::Index(ref base, ref index) = e.node {
188 let mut tables = self.fcx.tables.borrow_mut();
190 // All valid indexing looks like this; might encounter non-valid indexes at this point
191 if let ty::Ref(_, base_ty, _) = tables.expr_ty_adjusted(&base).sty {
192 let index_ty = tables.expr_ty_adjusted(&index);
193 let index_ty = self.fcx.resolve_type_vars_if_possible(&index_ty);
195 if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize {
196 // Remove the method call record
197 tables.type_dependent_defs_mut().remove(e.hir_id);
198 tables.node_substs_mut().remove(e.hir_id);
200 tables.adjustments_mut().get_mut(base.hir_id).map(|a| {
201 // Discard the need for a mutable borrow
203 // Extra adjustment made when indexing causes a drop
204 // of size information - we need to get rid of it
205 // Since this is "after" the other adjustment to be
206 // discarded, we do an extra `pop()`
208 kind: Adjust::Pointer(PointerCast::Unsize),
211 // So the borrow discard actually happens here
223 ///////////////////////////////////////////////////////////////////////////
224 // Impl of Visitor for Resolver
226 // This is the master code which walks the AST. It delegates most of
227 // the heavy lifting to the generic visit and resolve functions
228 // below. In general, a function is made into a `visitor` if it must
229 // traffic in node-ids or update tables in the type context etc.
231 impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
232 fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'gcx> {
233 NestedVisitorMap::None
236 fn visit_expr(&mut self, e: &'gcx hir::Expr) {
237 self.fix_scalar_builtin_expr(e);
238 self.fix_index_builtin_expr(e);
240 self.visit_node_id(e.span, e.hir_id);
243 hir::ExprKind::Closure(_, _, body, _, _) => {
244 let body = self.fcx.tcx.hir().body(body);
245 for arg in &body.arguments {
246 self.visit_node_id(e.span, arg.hir_id);
249 self.visit_body(body);
251 hir::ExprKind::Struct(_, ref fields, _) => {
252 for field in fields {
253 self.visit_field_id(field.hir_id);
256 hir::ExprKind::Field(..) => {
257 self.visit_field_id(e.hir_id);
262 intravisit::walk_expr(self, e);
265 fn visit_block(&mut self, b: &'gcx hir::Block) {
266 self.visit_node_id(b.span, b.hir_id);
267 intravisit::walk_block(self, b);
270 fn visit_pat(&mut self, p: &'gcx hir::Pat) {
272 hir::PatKind::Binding(..) => {
273 if let Some(&bm) = self.fcx.tables.borrow().pat_binding_modes().get(p.hir_id) {
274 self.tables.pat_binding_modes_mut().insert(p.hir_id, bm);
278 .delay_span_bug(p.span, "missing binding mode");
281 hir::PatKind::Struct(_, ref fields, _) => {
282 for field in fields {
283 self.visit_field_id(field.node.hir_id);
289 self.visit_pat_adjustments(p.span, p.hir_id);
291 self.visit_node_id(p.span, p.hir_id);
292 intravisit::walk_pat(self, p);
295 fn visit_local(&mut self, l: &'gcx hir::Local) {
296 intravisit::walk_local(self, l);
297 let var_ty = self.fcx.local_ty(l.span, l.hir_id).decl_ty;
298 let var_ty = self.resolve(&var_ty, &l.span);
299 self.write_ty_to_tables(l.hir_id, var_ty);
302 fn visit_ty(&mut self, hir_ty: &'gcx hir::Ty) {
303 intravisit::walk_ty(self, hir_ty);
304 let ty = self.fcx.node_ty(hir_ty.hir_id);
305 let ty = self.resolve(&ty, &hir_ty.span);
306 self.write_ty_to_tables(hir_ty.hir_id, ty);
309 fn visit_argument_source(&mut self, s: &'gcx hir::ArgSource) {
311 // Don't visit the pattern in `ArgSource::AsyncFn`, it contains a pattern which has
312 // a `NodeId` w/out a type, as it is only used for getting the name of the original
313 // pattern for diagnostics where only an `hir::Arg` is present.
314 hir::ArgSource::AsyncFn(..) => {},
315 _ => intravisit::walk_argument_source(self, s),
320 impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
321 fn visit_upvar_capture_map(&mut self) {
322 for (upvar_id, upvar_capture) in self.fcx.tables.borrow().upvar_capture_map.iter() {
323 let new_upvar_capture = match *upvar_capture {
324 ty::UpvarCapture::ByValue => ty::UpvarCapture::ByValue,
325 ty::UpvarCapture::ByRef(ref upvar_borrow) => {
326 let r = upvar_borrow.region;
327 let r = self.resolve(&r, &upvar_id.var_path.hir_id);
328 ty::UpvarCapture::ByRef(ty::UpvarBorrow {
329 kind: upvar_borrow.kind,
335 "Upvar capture for {:?} resolved to {:?}",
336 upvar_id, new_upvar_capture
340 .insert(*upvar_id, new_upvar_capture);
344 /// Runs through the function context's upvar list map and adds the same to
345 /// the TypeckTables. upvarlist is a hashmap of the list of upvars referred
346 /// to in a closure..
347 fn visit_upvar_list_map(&mut self) {
348 for (closure_def_id, upvar_list) in self.fcx.tables.borrow().upvar_list.iter() {
350 "UpvarIDs captured by closure {:?} are: {:?}",
351 closure_def_id, upvar_list
355 .insert(*closure_def_id, upvar_list.to_vec());
359 fn visit_closures(&mut self) {
360 let fcx_tables = self.fcx.tables.borrow();
361 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
362 let common_local_id_root = fcx_tables.local_id_root.unwrap();
364 for (&id, &origin) in fcx_tables.closure_kind_origins().iter() {
365 let hir_id = hir::HirId {
366 owner: common_local_id_root.index,
370 .closure_kind_origins_mut()
371 .insert(hir_id, origin);
375 fn visit_coercion_casts(&mut self) {
376 let fcx_tables = self.fcx.tables.borrow();
377 let fcx_coercion_casts = fcx_tables.coercion_casts();
378 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
380 for local_id in fcx_coercion_casts {
381 self.tables.set_coercion_cast(*local_id);
385 fn visit_free_region_map(&mut self) {
386 let free_region_map = self.tcx()
387 .lift_to_global(&self.fcx.tables.borrow().free_region_map);
388 let free_region_map = free_region_map.expect("all regions in free-region-map are global");
389 self.tables.free_region_map = free_region_map;
392 fn visit_user_provided_tys(&mut self) {
393 let fcx_tables = self.fcx.tables.borrow();
394 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
395 let common_local_id_root = fcx_tables.local_id_root.unwrap();
397 let mut errors_buffer = Vec::new();
398 for (&local_id, c_ty) in fcx_tables.user_provided_types().iter() {
399 let hir_id = hir::HirId {
400 owner: common_local_id_root.index,
404 let c_ty = if let Some(c_ty) = self.tcx().lift_to_global(c_ty) {
408 hir_id.to_span(self.fcx.tcx),
409 "writeback: `{:?}` missing from the global type context",
415 .user_provided_types_mut()
416 .insert(hir_id, c_ty.clone());
418 if let ty::UserType::TypeOf(_, user_substs) = c_ty.value {
419 if self.rustc_dump_user_substs {
420 // This is a unit-testing mechanism.
421 let span = self.tcx().hir().span_by_hir_id(hir_id);
422 // We need to buffer the errors in order to guarantee a consistent
423 // order when emitting them.
424 let err = self.tcx().sess.struct_span_err(
426 &format!("user substs: {:?}", user_substs)
428 err.buffer(&mut errors_buffer);
433 if !errors_buffer.is_empty() {
434 errors_buffer.sort_by_key(|diag| diag.span.primary_span());
435 for diag in errors_buffer.drain(..) {
436 DiagnosticBuilder::new_diagnostic(self.tcx().sess.diagnostic(), diag).emit();
441 fn visit_user_provided_sigs(&mut self) {
442 let fcx_tables = self.fcx.tables.borrow();
443 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
445 for (&def_id, c_sig) in fcx_tables.user_provided_sigs.iter() {
446 let c_sig = if let Some(c_sig) = self.tcx().lift_to_global(c_sig) {
450 self.fcx.tcx.hir().span_if_local(def_id).unwrap(),
451 "writeback: `{:?}` missing from the global type context",
458 .insert(def_id, c_sig.clone());
462 fn visit_opaque_types(&mut self, span: Span) {
463 for (&def_id, opaque_defn) in self.fcx.opaque_types.borrow().iter() {
464 let hir_id = self.tcx().hir().as_local_hir_id(def_id).unwrap();
465 let instantiated_ty = self.resolve(&opaque_defn.concrete_ty, &hir_id);
467 let generics = self.tcx().generics_of(def_id);
469 let definition_ty = if generics.parent.is_some() {
471 self.fcx.infer_opaque_definition_from_instantiation(
478 // * `fn foo<T>() -> Foo<T>`
479 // * `fn foo<T: Bound + Other>() -> Foo<T>`
480 // from being defining
482 // Also replace all generic params with the ones from the existential type
485 // existential type Foo<T>: 'static;
486 // fn foo<U>() -> Foo<U> { .. }
488 // figures out the concrete type with `U`, but the stored type is with `T`
489 instantiated_ty.fold_with(&mut BottomUpFolder {
490 tcx: self.tcx().global_tcx(),
492 trace!("checking type {:?}", ty);
493 // find a type parameter
494 if let ty::Param(..) = ty.sty {
495 // look it up in the substitution list
496 assert_eq!(opaque_defn.substs.len(), generics.params.len());
497 for (subst, param) in opaque_defn.substs.iter().zip(&generics.params) {
498 if let UnpackedKind::Type(subst) = subst.unpack() {
500 // found it in the substitution list, replace with the
501 // parameter from the existential type
504 .mk_ty_param(param.index, param.name);
513 "type parameter `{}` is part of concrete type but not used \
514 in parameter list for existential type",
519 return self.tcx().types.err;
525 // ignore static regions
526 ty::ReStatic => region,
528 trace!("checking {:?}", region);
529 for (subst, p) in opaque_defn.substs.iter().zip(&generics.params) {
530 if let UnpackedKind::Lifetime(subst) = subst.unpack() {
532 // found it in the substitution list, replace with the
533 // parameter from the existential type
534 let reg = ty::EarlyBoundRegion {
539 trace!("replace {:?} with {:?}", region, reg);
542 .mk_region(ty::ReEarlyBound(reg));
546 trace!("opaque_defn: {:#?}", opaque_defn);
547 trace!("generics: {:#?}", generics);
552 "non-defining existential type use in defining scope",
557 "lifetime `{}` is part of concrete type but not used \
558 in parameter list of existential type",
563 self.tcx().global_tcx().mk_region(ty::ReStatic)
570 if let ty::Opaque(defin_ty_def_id, _substs) = definition_ty.sty {
571 if def_id == defin_ty_def_id {
572 // Concrete type resolved to the existential type itself
573 // Force a cycle error
574 // FIXME(oli-obk): we could just not insert it into `concrete_existential_types`
575 // which simply would make this use not a defining use.
576 self.tcx().at(span).type_of(defin_ty_def_id);
580 let new = ty::ResolvedOpaqueTy {
581 concrete_type: definition_ty,
582 substs: self.tcx().lift_to_global(&opaque_defn.substs).unwrap(),
585 let old = self.tables
586 .concrete_existential_types
587 .insert(def_id, new);
588 if let Some(old) = old {
589 if old.concrete_type != definition_ty || old.substs != opaque_defn.substs {
592 "visit_opaque_types tried to write \
593 different types for the same existential type: {:?}, {:?}, {:?}, {:?}",
604 fn visit_field_id(&mut self, hir_id: hir::HirId) {
605 if let Some(index) = self.fcx
611 self.tables.field_indices_mut().insert(hir_id, index);
615 fn visit_node_id(&mut self, span: Span, hir_id: hir::HirId) {
616 // Export associated path extensions and method resolutions.
617 if let Some(def) = self.fcx
620 .type_dependent_defs_mut()
623 self.tables.type_dependent_defs_mut().insert(hir_id, def);
626 // Resolve any borrowings for the node with id `node_id`
627 self.visit_adjustments(span, hir_id);
629 // Resolve the type of the node with id `node_id`
630 let n_ty = self.fcx.node_ty(hir_id);
631 let n_ty = self.resolve(&n_ty, &span);
632 self.write_ty_to_tables(hir_id, n_ty);
633 debug!("Node {:?} has type {:?}", hir_id, n_ty);
635 // Resolve any substitutions
636 if let Some(substs) = self.fcx.tables.borrow().node_substs_opt(hir_id) {
637 let substs = self.resolve(&substs, &span);
638 debug!("write_substs_to_tcx({:?}, {:?})", hir_id, substs);
639 assert!(!substs.needs_infer() && !substs.has_placeholders());
640 self.tables.node_substs_mut().insert(hir_id, substs);
644 fn visit_adjustments(&mut self, span: Span, hir_id: hir::HirId) {
645 let adjustment = self.fcx
652 debug!("No adjustments for node {:?}", hir_id);
655 Some(adjustment) => {
656 let resolved_adjustment = self.resolve(&adjustment, &span);
658 "Adjustments for node {:?}: {:?}",
659 hir_id, resolved_adjustment
663 .insert(hir_id, resolved_adjustment);
668 fn visit_pat_adjustments(&mut self, span: Span, hir_id: hir::HirId) {
669 let adjustment = self.fcx
672 .pat_adjustments_mut()
676 debug!("No pat_adjustments for node {:?}", hir_id);
679 Some(adjustment) => {
680 let resolved_adjustment = self.resolve(&adjustment, &span);
682 "pat_adjustments for node {:?}: {:?}",
683 hir_id, resolved_adjustment
686 .pat_adjustments_mut()
687 .insert(hir_id, resolved_adjustment);
692 fn visit_liberated_fn_sigs(&mut self) {
693 let fcx_tables = self.fcx.tables.borrow();
694 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
695 let common_local_id_root = fcx_tables.local_id_root.unwrap();
697 for (&local_id, fn_sig) in fcx_tables.liberated_fn_sigs().iter() {
698 let hir_id = hir::HirId {
699 owner: common_local_id_root.index,
702 let fn_sig = self.resolve(fn_sig, &hir_id);
704 .liberated_fn_sigs_mut()
705 .insert(hir_id, fn_sig.clone());
709 fn visit_fru_field_types(&mut self) {
710 let fcx_tables = self.fcx.tables.borrow();
711 debug_assert_eq!(fcx_tables.local_id_root, self.tables.local_id_root);
712 let common_local_id_root = fcx_tables.local_id_root.unwrap();
714 for (&local_id, ftys) in fcx_tables.fru_field_types().iter() {
715 let hir_id = hir::HirId {
716 owner: common_local_id_root.index,
719 let ftys = self.resolve(ftys, &hir_id);
720 self.tables.fru_field_types_mut().insert(hir_id, ftys);
724 fn resolve<T>(&self, x: &T, span: &dyn Locatable) -> T::Lifted
726 T: TypeFoldable<'tcx> + ty::Lift<'gcx>,
728 let x = x.fold_with(&mut Resolver::new(self.fcx, span, self.body));
729 if let Some(lifted) = self.tcx().lift_to_global(&x) {
733 span.to_span(self.fcx.tcx),
734 "writeback: `{:?}` missing from the global type context",
742 fn to_span(&self, tcx: TyCtxt<'_, '_, '_>) -> Span;
745 impl Locatable for Span {
746 fn to_span(&self, _: TyCtxt<'_, '_, '_>) -> Span {
751 impl Locatable for DefIndex {
752 fn to_span(&self, tcx: TyCtxt<'_, '_, '_>) -> Span {
753 let hir_id = tcx.hir().def_index_to_hir_id(*self);
754 tcx.hir().span_by_hir_id(hir_id)
758 impl Locatable for hir::HirId {
759 fn to_span(&self, tcx: TyCtxt<'_, '_, '_>) -> Span {
760 tcx.hir().span_by_hir_id(*self)
764 ///////////////////////////////////////////////////////////////////////////
765 // The Resolver. This is the type folding engine that detects
766 // unresolved types and so forth.
768 struct Resolver<'cx, 'gcx: 'cx + 'tcx, 'tcx: 'cx> {
769 tcx: TyCtxt<'cx, 'gcx, 'tcx>,
770 infcx: &'cx InferCtxt<'cx, 'gcx, 'tcx>,
771 span: &'cx dyn Locatable,
772 body: &'gcx hir::Body,
775 impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
777 fcx: &'cx FnCtxt<'cx, 'gcx, 'tcx>,
778 span: &'cx dyn Locatable,
779 body: &'gcx hir::Body,
780 ) -> Resolver<'cx, 'gcx, 'tcx> {
789 fn report_error(&self, t: Ty<'tcx>) {
790 if !self.tcx.sess.has_errors() {
792 .need_type_info_err(Some(self.body.id()), self.span.to_span(self.tcx), t)
798 impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Resolver<'cx, 'gcx, 'tcx> {
799 fn tcx<'a>(&'a self) -> TyCtxt<'a, 'gcx, 'tcx> {
803 fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
804 match self.infcx.fully_resolve(&t) {
808 "Resolver::fold_ty: input type `{:?}` not fully resolvable",
811 self.report_error(t);
817 // FIXME This should be carefully checked
818 // We could use `self.report_error` but it doesn't accept a ty::Region, right now.
819 fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
820 self.infcx.fully_resolve(&r).unwrap_or(self.tcx.types.re_static)
824 ///////////////////////////////////////////////////////////////////////////
825 // During type check, we store promises with the result of trait
826 // lookup rather than the actual results (because the results are not
827 // necessarily available immediately). These routines unwind the
828 // promises. It is expected that we will have already reported any
829 // errors that may be encountered, so if the promises store an error,
830 // a dummy result is returned.