Skip to content

Commit 2b5b456

Browse files
committed
Move some outlives bounds things from rustc_trait_selection to rustc_typeck
1 parent d3fa07c commit 2b5b456

File tree

7 files changed

+55
-59
lines changed

7 files changed

+55
-59
lines changed

compiler/rustc_trait_selection/src/infer.rs

-49
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
2-
use crate::traits::query::outlives_bounds::InferCtxtExt as _;
32
use crate::traits::{self, TraitEngine, TraitEngineExt};
43

5-
use rustc_data_structures::stable_set::FxHashSet;
6-
use rustc_hir as hir;
74
use rustc_hir::def_id::DefId;
85
use rustc_hir::lang_items::LangItem;
9-
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
106
use rustc_infer::traits::ObligationCause;
117
use rustc_middle::arena::ArenaAllocatable;
128
use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, QueryResponse};
@@ -180,48 +176,3 @@ impl<'tcx> InferCtxtBuilderExt<'tcx> for InferCtxtBuilder<'tcx> {
180176
)
181177
}
182178
}
183-
184-
pub trait OutlivesEnvironmentExt<'tcx> {
185-
fn add_implied_bounds(
186-
&mut self,
187-
infcx: &InferCtxt<'a, 'tcx>,
188-
fn_sig_tys: FxHashSet<Ty<'tcx>>,
189-
body_id: hir::HirId,
190-
span: Span,
191-
);
192-
}
193-
194-
impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
195-
/// This method adds "implied bounds" into the outlives environment.
196-
/// Implied bounds are outlives relationships that we can deduce
197-
/// on the basis that certain types must be well-formed -- these are
198-
/// either the types that appear in the function signature or else
199-
/// the input types to an impl. For example, if you have a function
200-
/// like
201-
///
202-
/// ```
203-
/// fn foo<'a, 'b, T>(x: &'a &'b [T]) { }
204-
/// ```
205-
///
206-
/// we can assume in the caller's body that `'b: 'a` and that `T:
207-
/// 'b` (and hence, transitively, that `T: 'a`). This method would
208-
/// add those assumptions into the outlives-environment.
209-
///
210-
/// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs`
211-
fn add_implied_bounds(
212-
&mut self,
213-
infcx: &InferCtxt<'a, 'tcx>,
214-
fn_sig_tys: FxHashSet<Ty<'tcx>>,
215-
body_id: hir::HirId,
216-
span: Span,
217-
) {
218-
debug!("add_implied_bounds()");
219-
220-
for ty in fn_sig_tys {
221-
let ty = infcx.resolve_vars_if_possible(ty);
222-
debug!("add_implied_bounds: ty = {}", ty);
223-
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
224-
self.add_outlives_bounds(Some(infcx), implied_bounds)
225-
}
226-
}
227-
}

compiler/rustc_trait_selection/src/traits/query/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub mod dropck_outlives;
99
pub mod evaluate_obligation;
1010
pub mod method_autoderef;
1111
pub mod normalize;
12-
pub mod outlives_bounds;
1312
pub mod type_op;
1413

1514
pub use rustc_middle::traits::query::*;

compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
2-
use crate::traits::query::outlives_bounds::OutlivesBound;
32
use crate::traits::query::Fallible;
3+
use rustc_infer::traits::query::OutlivesBound;
44
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
55

66
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, Lift)]

compiler/rustc_traits/src/implied_outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use rustc_hir as hir;
66
use rustc_infer::infer::canonical::{self, Canonical};
77
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
88
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
9+
use rustc_infer::traits::query::OutlivesBound;
910
use rustc_infer::traits::TraitEngineExt as _;
1011
use rustc_middle::ty::query::Providers;
1112
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
1213
use rustc_span::source_map::DUMMY_SP;
1314
use rustc_trait_selection::infer::InferCtxtBuilderExt;
14-
use rustc_trait_selection::traits::query::outlives_bounds::OutlivesBound;
1515
use rustc_trait_selection::traits::query::{CanonicalTyGoal, Fallible, NoSolution};
1616
use rustc_trait_selection::traits::wf;
1717
use rustc_trait_selection::traits::FulfillmentContext;

compiler/rustc_typeck/src/check/regionck.rs

+48-3
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,19 @@ use crate::check::dropck;
7676
use crate::check::FnCtxt;
7777
use crate::mem_categorization as mc;
7878
use crate::middle::region;
79+
use crate::outlives::outlives_bounds::InferCtxtExt as _;
7980
use rustc_data_structures::stable_set::FxHashSet;
8081
use rustc_hir as hir;
8182
use rustc_hir::def_id::LocalDefId;
8283
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
8384
use rustc_hir::PatKind;
8485
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
85-
use rustc_infer::infer::{self, RegionObligation, RegionckMode};
86+
use rustc_infer::infer::{self, InferCtxt, RegionObligation, RegionckMode};
8687
use rustc_middle::hir::place::{PlaceBase, PlaceWithHirId};
8788
use rustc_middle::ty::adjustment;
8889
use rustc_middle::ty::{self, Ty};
8990
use rustc_span::Span;
90-
use rustc_trait_selection::infer::OutlivesEnvironmentExt;
91-
use rustc_trait_selection::opaque_types::InferCtxtExt;
91+
use rustc_trait_selection::opaque_types::InferCtxtExt as _;
9292
use std::ops::Deref;
9393

9494
// a variation on try that just returns unit
@@ -104,6 +104,51 @@ macro_rules! ignore_err {
104104
};
105105
}
106106

107+
trait OutlivesEnvironmentExt<'tcx> {
108+
fn add_implied_bounds(
109+
&mut self,
110+
infcx: &InferCtxt<'a, 'tcx>,
111+
fn_sig_tys: FxHashSet<Ty<'tcx>>,
112+
body_id: hir::HirId,
113+
span: Span,
114+
);
115+
}
116+
117+
impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
118+
/// This method adds "implied bounds" into the outlives environment.
119+
/// Implied bounds are outlives relationships that we can deduce
120+
/// on the basis that certain types must be well-formed -- these are
121+
/// either the types that appear in the function signature or else
122+
/// the input types to an impl. For example, if you have a function
123+
/// like
124+
///
125+
/// ```
126+
/// fn foo<'a, 'b, T>(x: &'a &'b [T]) { }
127+
/// ```
128+
///
129+
/// we can assume in the caller's body that `'b: 'a` and that `T:
130+
/// 'b` (and hence, transitively, that `T: 'a`). This method would
131+
/// add those assumptions into the outlives-environment.
132+
///
133+
/// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs`
134+
fn add_implied_bounds(
135+
&mut self,
136+
infcx: &InferCtxt<'a, 'tcx>,
137+
fn_sig_tys: FxHashSet<Ty<'tcx>>,
138+
body_id: hir::HirId,
139+
span: Span,
140+
) {
141+
debug!("add_implied_bounds()");
142+
143+
for ty in fn_sig_tys {
144+
let ty = infcx.resolve_vars_if_possible(ty);
145+
debug!("add_implied_bounds: ty = {}", ty);
146+
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
147+
self.add_outlives_bounds(Some(infcx), implied_bounds)
148+
}
149+
}
150+
}
151+
107152
///////////////////////////////////////////////////////////////////////////
108153
// PUBLIC ENTRY POINTS
109154

compiler/rustc_typeck/src/outlives/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_span::Span;
99

1010
mod explicit;
1111
mod implicit_infer;
12+
crate mod outlives_bounds;
1213
/// Code to write unit test for outlives.
1314
pub mod test;
1415
mod utils;

compiler/rustc_trait_selection/src/traits/query/outlives_bounds.rs renamed to compiler/rustc_typeck/src/outlives/outlives_bounds.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use crate::infer::canonical::OriginalQueryValues;
2-
use crate::infer::InferCtxt;
3-
use crate::traits::query::NoSolution;
4-
use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine};
51
use rustc_hir as hir;
62
use rustc_infer::traits::TraitEngineExt as _;
73
use rustc_middle::ty::{self, Ty};
84
use rustc_span::source_map::Span;
5+
use rustc_trait_selection::infer::canonical::OriginalQueryValues;
6+
use rustc_trait_selection::infer::InferCtxt;
7+
use rustc_trait_selection::traits::query::NoSolution;
8+
use rustc_trait_selection::traits::{FulfillmentContext, ObligationCause, TraitEngine};
99

1010
pub use rustc_middle::traits::query::OutlivesBound;
1111

0 commit comments

Comments
 (0)