Skip to content

Commit a7c132d

Browse files
committed
Move push_outlives_components to rustc_infer
1 parent 1dafe6d commit a7c132d

File tree

7 files changed

+23
-21
lines changed

7 files changed

+23
-21
lines changed

compiler/rustc_middle/src/ty/outlives.rs renamed to compiler/rustc_infer/src/infer/outlives/components.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that
33
// RFC for reference.
44

5-
use crate::ty::subst::{GenericArg, GenericArgKind};
6-
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
75
use rustc_data_structures::sso::SsoHashSet;
8-
use smallvec::SmallVec;
6+
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
7+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
8+
use smallvec::{smallvec, SmallVec};
99

1010
#[derive(Debug)]
1111
pub enum Component<'tcx> {
@@ -47,14 +47,16 @@ pub enum Component<'tcx> {
4747
EscapingProjection(Vec<Component<'tcx>>),
4848
}
4949

50-
impl<'tcx> TyCtxt<'tcx> {
51-
/// Push onto `out` all the things that must outlive `'a` for the condition
52-
/// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**.
53-
pub fn push_outlives_components(self, ty0: Ty<'tcx>, out: &mut SmallVec<[Component<'tcx>; 4]>) {
54-
let mut visited = SsoHashSet::new();
55-
compute_components(self, ty0, out, &mut visited);
56-
debug!("components({:?}) = {:?}", ty0, out);
57-
}
50+
/// Push onto `out` all the things that must outlive `'a` for the condition
51+
/// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**.
52+
pub fn push_outlives_components(
53+
tcx: TyCtxt<'tcx>,
54+
ty0: Ty<'tcx>,
55+
out: &mut SmallVec<[Component<'tcx>; 4]>,
56+
) {
57+
let mut visited = SsoHashSet::new();
58+
compute_components(tcx, ty0, out, &mut visited);
59+
debug!("components({:?}) = {:?}", ty0, out);
5860
}
5961

6062
fn compute_components(

compiler/rustc_infer/src/infer/outlives/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Various code related to computing outlives relations.
22
3+
pub mod components;
34
pub mod env;
45
pub mod obligations;
56
pub mod verify;

compiler/rustc_infer/src/infer/outlives/obligations.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Code that handles "type-outlives" constraints like `T: 'a`. This
2-
//! is based on the `push_outlives_components` function defined on the tcx,
2+
//! is based on the `push_outlives_components` function defined in rustc_infer,
33
//! but it adds a bit of heuristics on top, in particular to deal with
44
//! associated types and projections.
55
//!
@@ -59,13 +59,13 @@
5959
//! might later infer `?U` to something like `&'b u32`, which would
6060
//! imply that `'b: 'a`.
6161
62+
use crate::infer::outlives::components::{push_outlives_components, Component};
6263
use crate::infer::outlives::env::RegionBoundPairs;
6364
use crate::infer::outlives::verify::VerifyBoundCx;
6465
use crate::infer::{
6566
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
6667
};
6768
use crate::traits::{ObligationCause, ObligationCauseCode};
68-
use rustc_middle::ty::outlives::Component;
6969
use rustc_middle::ty::subst::GenericArgKind;
7070
use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeFoldable};
7171

@@ -271,7 +271,7 @@ where
271271
assert!(!ty.has_escaping_bound_vars());
272272

273273
let mut components = smallvec![];
274-
self.tcx.push_outlives_components(ty, &mut components);
274+
push_outlives_components(self.tcx, ty, &mut components);
275275
self.components_must_outlive(origin, &components, region);
276276
}
277277

compiler/rustc_infer/src/traits/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use smallvec::smallvec;
22

3+
use crate::infer::outlives::components::{push_outlives_components, Component};
34
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
45
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
5-
use rustc_middle::ty::outlives::Component;
66
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
77
use rustc_span::symbol::Ident;
88

@@ -200,7 +200,7 @@ impl Elaborator<'tcx> {
200200

201201
let visited = &mut self.visited;
202202
let mut components = smallvec![];
203-
tcx.push_outlives_components(ty_max, &mut components);
203+
push_outlives_components(tcx, ty_max, &mut components);
204204
self.stack.extend(
205205
components
206206
.into_iter()

compiler/rustc_middle/src/ty/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ pub mod fold;
9292
pub mod inhabitedness;
9393
pub mod layout;
9494
pub mod normalize_erasing_regions;
95-
pub mod outlives;
9695
pub mod print;
9796
pub mod query;
9897
pub mod relate;

compiler/rustc_traits/src/implied_outlives_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
55
use rustc_hir as hir;
66
use rustc_infer::infer::canonical::{self, Canonical};
7+
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
78
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
89
use rustc_infer::traits::TraitEngineExt as _;
9-
use rustc_middle::ty::outlives::Component;
1010
use rustc_middle::ty::query::Providers;
1111
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
1212
use rustc_span::source_map::DUMMY_SP;
@@ -118,7 +118,7 @@ fn compute_implied_outlives_bounds<'tcx>(
118118
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, r_b)) => {
119119
let ty_a = infcx.resolve_vars_if_possible(ty_a);
120120
let mut components = smallvec![];
121-
tcx.push_outlives_components(ty_a, &mut components);
121+
push_outlives_components(tcx, ty_a, &mut components);
122122
implied_bounds_from_components(r_b, components)
123123
}
124124
},

compiler/rustc_typeck/src/outlives/utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_middle::ty::outlives::Component;
1+
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
22
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
33
use rustc_middle::ty::{self, Region, RegionKind, Ty, TyCtxt};
44
use rustc_span::Span;
@@ -35,7 +35,7 @@ pub fn insert_outlives_predicate<'tcx>(
3535
// Or if within `struct Foo<U>` you had `T = Vec<U>`, then
3636
// we would want to add `U: 'outlived_region`
3737
let mut components = smallvec![];
38-
tcx.push_outlives_components(ty, &mut components);
38+
push_outlives_components(tcx, ty, &mut components);
3939
for component in components {
4040
match component {
4141
Component::Region(r) => {

0 commit comments

Comments
 (0)