1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
12 use rustc::traits::auto_trait as auto;
13 use rustc::ty::{self, TypeFoldable};
16 use self::def_ctor::{get_def_from_def_id, get_def_from_node_id};
20 pub struct AutoTraitFinder<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
21 pub cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>,
22 pub f: auto::AutoTraitFinder<'a, 'tcx>,
25 impl<'a, 'tcx, 'rcx, 'cstore> AutoTraitFinder<'a, 'tcx, 'rcx, 'cstore> {
26 pub fn new(cx: &'a core::DocContext<'a, 'tcx, 'rcx, 'cstore>) -> Self {
27 let f = auto::AutoTraitFinder::new(&cx.tcx);
29 AutoTraitFinder { cx, f }
32 pub fn get_with_def_id(&self, def_id: DefId) -> Vec<Item> {
33 get_def_from_def_id(&self.cx, def_id, &|def_ctor| {
34 self.get_auto_trait_impls(def_id, &def_ctor, None)
38 pub fn get_with_node_id(&self, id: ast::NodeId, name: String) -> Vec<Item> {
39 get_def_from_node_id(&self.cx, id, name, &|def_ctor, name| {
40 let did = self.cx.tcx.hir().local_def_id(id);
41 self.get_auto_trait_impls(did, &def_ctor, Some(name))
45 pub fn get_auto_trait_impls<F>(
51 where F: Fn(DefId) -> Def {
59 "get_auto_trait_impls(def_id={:?}, def_ctor=...): item has doc('hidden'), \
66 let tcx = self.cx.tcx;
67 let generics = self.cx.tcx.generics_of(def_id);
70 "get_auto_trait_impls(def_id={:?}, def_ctor=..., generics={:?}",
73 let auto_traits: Vec<_> = self.cx
75 .and_then(|send_trait| {
76 self.get_auto_trait_impl_for(
85 .chain(self.get_auto_trait_impl_for(
90 tcx.require_lang_item(lang_items::SyncTraitLangItem),
95 "get_auto_traits: type {:?} auto_traits {:?}",
101 fn get_auto_trait_impl_for<F>(
104 name: Option<String>,
105 generics: ty::Generics,
109 where F: Fn(DefId) -> Def {
111 .generated_synthetics
113 .insert((def_id, trait_def_id))
116 "get_auto_trait_impl_for(def_id={:?}, generics={:?}, def_ctor=..., \
117 trait_def_id={:?}): already generated, aborting",
118 def_id, generics, trait_def_id
123 let result = self.find_auto_trait_generics(def_id, trait_def_id, &generics);
125 if result.is_auto() {
126 let trait_ = hir::TraitRef {
127 path: get_path_for_type(self.cx.tcx, trait_def_id, hir::def::Def::Trait),
128 ref_id: ast::DUMMY_NODE_ID,
129 hir_ref_id: hir::DUMMY_HIR_ID,
134 let new_generics = match result {
135 AutoTraitResult::PositiveImpl(new_generics) => {
139 AutoTraitResult::NegativeImpl => {
140 polarity = Some(ImplPolarity::Negative);
142 // For negative impls, we use the generic params, but *not* the predicates,
143 // from the original type. Otherwise, the displayed impl appears to be a
144 // conditional negative impl, when it's really unconditional.
146 // For example, consider the struct Foo<T: Copy>(*mut T). Using
147 // the original predicates in our impl would cause us to generate
148 // `impl !Send for Foo<T: Copy>`, which makes it appear that Foo
149 // implements Send where T is not copy.
151 // Instead, we generate `impl !Send for Foo<T>`, which better
152 // expresses the fact that `Foo<T>` never implements `Send`,
153 // regardless of the choice of `T`.
154 let real_generics = (&generics, &Default::default());
156 // Clean the generics, but ignore the '?Sized' bounds generated
157 // by the `Clean` impl
158 let clean_generics = real_generics.clean(self.cx);
161 params: clean_generics.params,
162 where_predicates: Vec::new(),
167 let real_name = name.map(|name| Ident::from_str(&name));
168 let ty = self.cx.get_real_ty(def_id, def_ctor, &real_name, &generics);
171 source: Span::empty(),
173 attrs: Default::default(),
175 def_id: self.cx.next_def_id(def_id.krate),
178 inner: ImplItem(Impl {
179 unsafety: hir::Unsafety::Normal,
180 generics: new_generics,
181 provided_trait_methods: Default::default(),
182 trait_: Some(trait_.clean(self.cx)),
183 for_: ty.clean(self.cx),
194 fn find_auto_trait_generics(
198 generics: &ty::Generics,
199 ) -> AutoTraitResult {
200 match self.f.find_auto_trait_generics(did, trait_did, generics,
202 let region_data = info.region_data;
206 .map(|name| (name.clone(), Lifetime(name)))
208 let lifetime_predicates =
209 self.handle_lifetimes(®ion_data, &names_map);
210 let new_generics = self.param_env_to_generics(
220 "find_auto_trait_generics(did={:?}, trait_did={:?}, generics={:?}): \
222 did, trait_did, generics, new_generics
227 auto::AutoTraitResult::ExplicitImpl => AutoTraitResult::ExplicitImpl,
228 auto::AutoTraitResult::NegativeImpl => AutoTraitResult::NegativeImpl,
229 auto::AutoTraitResult::PositiveImpl(res) => AutoTraitResult::PositiveImpl(res),
233 fn get_lifetime(&self, region: Region, names_map: &FxHashMap<String, Lifetime>) -> Lifetime {
234 self.region_name(region)
236 names_map.get(&name).unwrap_or_else(|| {
237 panic!("Missing lifetime with name {:?} for {:?}", name, region)
240 .unwrap_or(&Lifetime::statik())
244 fn region_name(&self, region: Region) -> Option<String> {
246 &ty::ReEarlyBound(r) => Some(r.name.to_string()),
251 // This method calculates two things: Lifetime constraints of the form 'a: 'b,
252 // and region constraints of the form ReVar: 'a
254 // This is essentially a simplified version of lexical_region_resolve. However,
255 // handle_lifetimes determines what *needs be* true in order for an impl to hold.
256 // lexical_region_resolve, along with much of the rest of the compiler, is concerned
257 // with determining if a given set up constraints/predicates *are* met, given some
258 // starting conditions (e.g. user-provided code). For this reason, it's easier
259 // to perform the calculations we need on our own, rather than trying to make
260 // existing inference/solver code do what we want.
261 fn handle_lifetimes<'cx>(
263 regions: &RegionConstraintData<'cx>,
264 names_map: &FxHashMap<String, Lifetime>,
265 ) -> Vec<WherePredicate> {
266 // Our goal is to 'flatten' the list of constraints by eliminating
267 // all intermediate RegionVids. At the end, all constraints should
268 // be between Regions (aka region variables). This gives us the information
269 // we need to create the Generics.
270 let mut finished: FxHashMap<_, Vec<_>> = Default::default();
272 let mut vid_map: FxHashMap<RegionTarget, RegionDeps> = Default::default();
274 // Flattening is done in two parts. First, we insert all of the constraints
275 // into a map. Each RegionTarget (either a RegionVid or a Region) maps
276 // to its smaller and larger regions. Note that 'larger' regions correspond
277 // to sub-regions in Rust code (e.g. in 'a: 'b, 'a is the larger region).
278 for constraint in regions.constraints.keys() {
280 &Constraint::VarSubVar(r1, r2) => {
283 .entry(RegionTarget::RegionVid(r1))
285 deps1.larger.insert(RegionTarget::RegionVid(r2));
289 .entry(RegionTarget::RegionVid(r2))
291 deps2.smaller.insert(RegionTarget::RegionVid(r1));
293 &Constraint::RegSubVar(region, vid) => {
295 .entry(RegionTarget::RegionVid(vid))
297 deps.smaller.insert(RegionTarget::Region(region));
299 &Constraint::VarSubReg(vid, region) => {
301 .entry(RegionTarget::RegionVid(vid))
303 deps.larger.insert(RegionTarget::Region(region));
305 &Constraint::RegSubReg(r1, r2) => {
306 // The constraint is already in the form that we want, so we're done with it
307 // Desired order is 'larger, smaller', so flip then
308 if self.region_name(r1) != self.region_name(r2) {
310 .entry(self.region_name(r2).expect("no region_name found"))
318 // Here, we 'flatten' the map one element at a time.
319 // All of the element's sub and super regions are connected
320 // to each other. For example, if we have a graph that looks like this:
322 // (A, B) - C - (D, E)
323 // Where (A, B) are subregions, and (D,E) are super-regions
325 // then after deleting 'C', the graph will look like this:
326 // ... - A - (D, E ...)
327 // ... - B - (D, E, ...)
328 // (A, B, ...) - D - ...
329 // (A, B, ...) - E - ...
331 // where '...' signifies the existing sub and super regions of an entry
332 // When two adjacent ty::Regions are encountered, we've computed a final
333 // constraint, and add it to our list. Since we make sure to never re-add
334 // deleted items, this process will always finish.
335 while !vid_map.is_empty() {
336 let target = vid_map.keys().next().expect("Keys somehow empty").clone();
337 let deps = vid_map.remove(&target).expect("Entry somehow missing");
339 for smaller in deps.smaller.iter() {
340 for larger in deps.larger.iter() {
341 match (smaller, larger) {
342 (&RegionTarget::Region(r1), &RegionTarget::Region(r2)) => {
343 if self.region_name(r1) != self.region_name(r2) {
345 .entry(self.region_name(r2).expect("no region name found"))
347 .push(r1) // Larger, smaller
350 (&RegionTarget::RegionVid(_), &RegionTarget::Region(_)) => {
351 if let Entry::Occupied(v) = vid_map.entry(*smaller) {
352 let smaller_deps = v.into_mut();
353 smaller_deps.larger.insert(*larger);
354 smaller_deps.larger.remove(&target);
357 (&RegionTarget::Region(_), &RegionTarget::RegionVid(_)) => {
358 if let Entry::Occupied(v) = vid_map.entry(*larger) {
359 let deps = v.into_mut();
360 deps.smaller.insert(*smaller);
361 deps.smaller.remove(&target);
364 (&RegionTarget::RegionVid(_), &RegionTarget::RegionVid(_)) => {
365 if let Entry::Occupied(v) = vid_map.entry(*smaller) {
366 let smaller_deps = v.into_mut();
367 smaller_deps.larger.insert(*larger);
368 smaller_deps.larger.remove(&target);
371 if let Entry::Occupied(v) = vid_map.entry(*larger) {
372 let larger_deps = v.into_mut();
373 larger_deps.smaller.insert(*smaller);
374 larger_deps.smaller.remove(&target);
382 let lifetime_predicates = names_map
384 .flat_map(|(name, lifetime)| {
385 let empty = Vec::new();
386 let bounds: FxHashSet<GenericBound> = finished.get(name).unwrap_or(&empty).iter()
387 .map(|region| GenericBound::Outlives(self.get_lifetime(region, names_map)))
390 if bounds.is_empty() {
393 Some(WherePredicate::RegionPredicate {
394 lifetime: lifetime.clone(),
395 bounds: bounds.into_iter().collect(),
403 fn extract_for_generics<'b, 'c, 'd>(
405 tcx: TyCtxt<'b, 'c, 'd>,
406 pred: ty::Predicate<'d>,
407 ) -> FxHashSet<GenericParamDef> {
410 let mut regions = FxHashSet::default();
411 tcx.collect_regions(&t, &mut regions);
413 regions.into_iter().flat_map(|r| {
415 // We only care about late bound regions, as we need to add them
416 // to the 'for<>' section
417 &ty::ReLateBound(_, ty::BoundRegion::BrNamed(_, name)) => {
418 Some(GenericParamDef {
419 name: name.to_string(),
420 kind: GenericParamDefKind::Lifetime,
423 &ty::ReVar(_) | &ty::ReEarlyBound(_) | &ty::ReStatic => None,
424 _ => panic!("Unexpected region type {:?}", r),
431 fn make_final_bounds<'b, 'c, 'cx>(
433 ty_to_bounds: FxHashMap<Type, FxHashSet<GenericBound>>,
434 ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
435 lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<GenericBound>>,
436 ) -> Vec<WherePredicate> {
439 .flat_map(|(ty, mut bounds)| {
440 if let Some(data) = ty_to_fn.get(&ty) {
441 let (poly_trait, output) =
442 (data.0.as_ref().expect("as_ref failed").clone(), data.1.as_ref().cloned());
443 let new_ty = match &poly_trait.trait_ {
444 &Type::ResolvedPath {
450 let mut new_path = path.clone();
451 let last_segment = new_path.segments.pop()
452 .expect("segments were empty");
454 let (old_input, old_output) = match last_segment.args {
455 GenericArgs::AngleBracketed { types, .. } => (types, None),
456 GenericArgs::Parenthesized { inputs, output, .. } => {
461 if old_output.is_some() && old_output != output {
463 "Output mismatch for {:?} {:?} {:?}",
464 ty, old_output, data.1
468 let new_params = GenericArgs::Parenthesized {
473 new_path.segments.push(PathSegment {
474 name: last_segment.name,
480 typarams: typarams.clone(),
482 is_generic: *is_generic,
485 _ => panic!("Unexpected data: {:?}, {:?}", ty, data),
487 bounds.insert(GenericBound::TraitBound(
490 generic_params: poly_trait.generic_params,
492 hir::TraitBoundModifier::None,
495 if bounds.is_empty() {
499 let mut bounds_vec = bounds.into_iter().collect();
500 self.sort_where_bounds(&mut bounds_vec);
502 Some(WherePredicate::BoundPredicate {
510 .filter(|&(_, ref bounds)| !bounds.is_empty())
511 .map(|(lifetime, bounds)| {
512 let mut bounds_vec = bounds.into_iter().collect();
513 self.sort_where_bounds(&mut bounds_vec);
514 WherePredicate::RegionPredicate {
523 // Converts the calculated ParamEnv and lifetime information to a clean::Generics, suitable for
524 // display on the docs page. Cleaning the Predicates produces sub-optimal WherePredicate's,
525 // so we fix them up:
527 // * Multiple bounds for the same type are coalesced into one: e.g. 'T: Copy', 'T: Debug'
528 // becomes 'T: Copy + Debug'
529 // * Fn bounds are handled specially - instead of leaving it as 'T: Fn(), <T as Fn::Output> =
530 // K', we use the dedicated syntax 'T: Fn() -> K'
531 // * We explcitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type
532 fn param_env_to_generics<'b, 'c, 'cx>(
534 tcx: TyCtxt<'b, 'c, 'cx>,
536 param_env: ty::ParamEnv<'cx>,
537 type_generics: ty::Generics,
538 mut existing_predicates: Vec<WherePredicate>,
539 vid_to_region: FxHashMap<ty::RegionVid, ty::Region<'cx>>,
542 "param_env_to_generics(did={:?}, param_env={:?}, type_generics={:?}, \
543 existing_predicates={:?})",
544 did, param_env, type_generics, existing_predicates
547 // The `Sized` trait must be handled specially, since we only only display it when
548 // it is *not* required (i.e. '?Sized')
549 let sized_trait = self.cx
551 .require_lang_item(lang_items::SizedTraitLangItem);
553 let mut replacer = RegionReplacer {
554 vid_to_region: &vid_to_region,
558 let orig_bounds: FxHashSet<_> = self.cx.tcx.param_env(did).caller_bounds.iter().collect();
559 let clean_where_predicates = param_env
563 !orig_bounds.contains(p) || match p {
564 &&ty::Predicate::Trait(pred) => pred.def_id() == sized_trait,
569 let replaced = p.fold_with(&mut replacer);
570 (replaced.clone(), replaced.clean(self.cx))
573 let full_generics = (&type_generics, &tcx.predicates_of(did));
575 params: mut generic_params,
577 } = full_generics.clean(self.cx);
579 let mut has_sized = FxHashSet::default();
580 let mut ty_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
581 let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
582 let mut ty_to_traits: FxHashMap<Type, FxHashSet<Type>> = Default::default();
584 let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();
586 for (orig_p, p) in clean_where_predicates {
588 WherePredicate::BoundPredicate { ty, mut bounds } => {
589 // Writing a projection trait bound of the form
590 // <T as Trait>::Name : ?Sized
591 // is illegal, because ?Sized bounds can only
592 // be written in the (here, nonexistant) definition
594 // Therefore, we make sure that we never add a ?Sized
595 // bound for projections
597 &Type::QPath { .. } => {
598 has_sized.insert(ty.clone());
603 if bounds.is_empty() {
607 let mut for_generics = self.extract_for_generics(tcx, orig_p.clone());
609 assert!(bounds.len() == 1);
610 let mut b = bounds.pop().expect("bounds were empty");
612 if b.is_sized_bound(self.cx) {
613 has_sized.insert(ty.clone());
614 } else if !b.get_trait_type()
618 .map(|bounds| bounds.contains(&strip_type(t.clone())))
622 // If we've already added a projection bound for the same type, don't add
623 // this, as it would be a duplicate
625 // Handle any 'Fn/FnOnce/FnMut' bounds specially,
626 // as we want to combine them with any 'Output' qpaths
629 let is_fn = match &mut b {
630 &mut GenericBound::TraitBound(ref mut p, _) => {
631 // Insert regions into the for_generics hash map first, to ensure
632 // that we don't end up with duplicate bounds (e.g. for<'b, 'b>)
633 for_generics.extend(p.generic_params.clone());
634 p.generic_params = for_generics.into_iter().collect();
635 self.is_fn_ty(&tcx, &p.trait_)
640 let poly_trait = b.get_poly_trait().expect("Cannot get poly trait");
645 .and_modify(|e| *e = (Some(poly_trait.clone()), e.1.clone()))
646 .or_insert(((Some(poly_trait.clone())), None));
659 WherePredicate::RegionPredicate { lifetime, bounds } => {
665 WherePredicate::EqPredicate { lhs, rhs } => {
672 let ty = &*self_type;
675 path: ref trait_path,
680 let mut new_trait_path = trait_path.clone();
682 if self.is_fn_ty(&tcx, trait_) && left_name == FN_OUTPUT_NAME {
685 .and_modify(|e| *e = (e.0.clone(), Some(rhs.clone())))
686 .or_insert((None, Some(rhs)));
690 // FIXME: Remove this scope when NLL lands
693 &mut new_trait_path.segments
695 .expect("segments were empty")
699 // Convert somethiung like '<T as Iterator::Item> = u8'
700 // to 'T: Iterator<Item=u8>'
701 &mut GenericArgs::AngleBracketed {
705 bindings.push(TypeBinding {
706 name: left_name.clone(),
710 &mut GenericArgs::Parenthesized { .. } => {
711 existing_predicates.push(
712 WherePredicate::EqPredicate {
717 continue; // If something other than a Fn ends up
718 // with parenthesis, leave it alone
723 let bounds = ty_to_bounds
727 bounds.insert(GenericBound::TraitBound(
729 trait_: Type::ResolvedPath {
730 path: new_trait_path,
731 typarams: typarams.clone(),
733 is_generic: *is_generic,
735 generic_params: Vec::new(),
737 hir::TraitBoundModifier::None,
740 // Remove any existing 'plain' bound (e.g. 'T: Iterator`) so
741 // that we don't see a
742 // duplicate bound like `T: Iterator + Iterator<Item=u8>`
744 bounds.remove(&GenericBound::TraitBound(
746 trait_: *trait_.clone(),
747 generic_params: Vec::new(),
749 hir::TraitBoundModifier::None,
751 // Avoid creating any new duplicate bounds later in the outer
756 .insert(*trait_.clone());
758 _ => panic!("Unexpected trait {:?} for {:?}", trait_, did),
761 _ => panic!("Unexpected LHS {:?} for {:?}", lhs, did),
767 let final_bounds = self.make_final_bounds(ty_to_bounds, ty_to_fn, lifetime_to_bounds);
769 existing_predicates.extend(final_bounds);
771 for param in generic_params.iter_mut() {
773 GenericParamDefKind::Type { ref mut default, ref mut bounds, .. } => {
774 // We never want something like `impl<T=Foo>`.
776 let generic_ty = Type::Generic(param.name.clone());
777 if !has_sized.contains(&generic_ty) {
778 bounds.insert(0, GenericBound::maybe_sized(self.cx));
781 GenericParamDefKind::Lifetime => {}
785 self.sort_where_predicates(&mut existing_predicates);
788 params: generic_params,
789 where_predicates: existing_predicates,
793 // Ensure that the predicates are in a consistent order. The precise
794 // ordering doesn't actually matter, but it's important that
795 // a given set of predicates always appears in the same order -
796 // both for visual consistency between 'rustdoc' runs, and to
797 // make writing tests much easier
799 fn sort_where_predicates(&self, mut predicates: &mut Vec<WherePredicate>) {
800 // We should never have identical bounds - and if we do,
801 // they're visually identical as well. Therefore, using
802 // an unstable sort is fine.
803 self.unstable_debug_sort(&mut predicates);
806 // Ensure that the bounds are in a consistent order. The precise
807 // ordering doesn't actually matter, but it's important that
808 // a given set of bounds always appears in the same order -
809 // both for visual consistency between 'rustdoc' runs, and to
810 // make writing tests much easier
812 fn sort_where_bounds(&self, mut bounds: &mut Vec<GenericBound>) {
813 // We should never have identical bounds - and if we do,
814 // they're visually identical as well. Therefore, using
815 // an unstable sort is fine.
816 self.unstable_debug_sort(&mut bounds);
819 // This might look horrendously hacky, but it's actually not that bad.
821 // For performance reasons, we use several different FxHashMaps
822 // in the process of computing the final set of where predicates.
823 // However, the iteration order of a HashMap is completely unspecified.
824 // In fact, the iteration of an FxHashMap can even vary between platforms,
825 // since FxHasher has different behavior for 32-bit and 64-bit platforms.
827 // Obviously, it's extremely undesirable for documentation rendering
828 // to be depndent on the platform it's run on. Apart from being confusing
829 // to end users, it makes writing tests much more difficult, as predicates
830 // can appear in any order in the final result.
832 // To solve this problem, we sort WherePredicates and GenericBounds
833 // by their Debug string. The thing to keep in mind is that we don't really
834 // care what the final order is - we're synthesizing an impl or bound
835 // ourselves, so any order can be considered equally valid. By sorting the
836 // predicates and bounds, however, we ensure that for a given codebase, all
837 // auto-trait impls always render in exactly the same way.
839 // Using the Debug implementation for sorting prevents us from needing to
840 // write quite a bit of almost entirely useless code (e.g. how should two
841 // Types be sorted relative to each other). It also allows us to solve the
842 // problem for both WherePredicates and GenericBounds at the same time. This
843 // approach is probably somewhat slower, but the small number of items
844 // involved (impls rarely have more than a few bounds) means that it
845 // shouldn't matter in practice.
846 fn unstable_debug_sort<T: Debug>(&self, vec: &mut Vec<T>) {
847 vec.sort_by_cached_key(|x| format!("{:?}", x))
850 fn is_fn_ty(&self, tcx: &TyCtxt, ty: &Type) -> bool {
852 &&Type::ResolvedPath { ref did, .. } => {
853 *did == tcx.require_lang_item(lang_items::FnTraitLangItem)
854 || *did == tcx.require_lang_item(lang_items::FnMutTraitLangItem)
855 || *did == tcx.require_lang_item(lang_items::FnOnceTraitLangItem)
862 // Replaces all ReVars in a type with ty::Region's, using the provided map
863 struct RegionReplacer<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
864 vid_to_region: &'a FxHashMap<ty::RegionVid, ty::Region<'tcx>>,
865 tcx: TyCtxt<'a, 'gcx, 'tcx>,
868 impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for RegionReplacer<'a, 'gcx, 'tcx> {
869 fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
873 fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
875 &ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
877 }).unwrap_or_else(|| r.super_fold_with(self))