Move some outlives bounds things from rustc_trait_selection to rustc_typeck
This commit is contained in:
parent
d3fa07c72e
commit
2b5b456e23
7 changed files with 55 additions and 59 deletions
|
@ -1,12 +1,8 @@
|
|||
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use crate::traits::query::outlives_bounds::InferCtxtExt as _;
|
||||
use crate::traits::{self, TraitEngine, TraitEngineExt};
|
||||
|
||||
use rustc_data_structures::stable_set::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::traits::ObligationCause;
|
||||
use rustc_middle::arena::ArenaAllocatable;
|
||||
use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, QueryResponse};
|
||||
|
@ -180,48 +176,3 @@ impl<'tcx> InferCtxtBuilderExt<'tcx> for InferCtxtBuilder<'tcx> {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OutlivesEnvironmentExt<'tcx> {
|
||||
fn add_implied_bounds(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx>,
|
||||
fn_sig_tys: FxHashSet<Ty<'tcx>>,
|
||||
body_id: hir::HirId,
|
||||
span: Span,
|
||||
);
|
||||
}
|
||||
|
||||
impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
|
||||
/// This method adds "implied bounds" into the outlives environment.
|
||||
/// Implied bounds are outlives relationships that we can deduce
|
||||
/// on the basis that certain types must be well-formed -- these are
|
||||
/// either the types that appear in the function signature or else
|
||||
/// the input types to an impl. For example, if you have a function
|
||||
/// like
|
||||
///
|
||||
/// ```
|
||||
/// fn foo<'a, 'b, T>(x: &'a &'b [T]) { }
|
||||
/// ```
|
||||
///
|
||||
/// we can assume in the caller's body that `'b: 'a` and that `T:
|
||||
/// 'b` (and hence, transitively, that `T: 'a`). This method would
|
||||
/// add those assumptions into the outlives-environment.
|
||||
///
|
||||
/// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs`
|
||||
fn add_implied_bounds(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx>,
|
||||
fn_sig_tys: FxHashSet<Ty<'tcx>>,
|
||||
body_id: hir::HirId,
|
||||
span: Span,
|
||||
) {
|
||||
debug!("add_implied_bounds()");
|
||||
|
||||
for ty in fn_sig_tys {
|
||||
let ty = infcx.resolve_vars_if_possible(ty);
|
||||
debug!("add_implied_bounds: ty = {}", ty);
|
||||
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
|
||||
self.add_outlives_bounds(Some(infcx), implied_bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ pub mod dropck_outlives;
|
|||
pub mod evaluate_obligation;
|
||||
pub mod method_autoderef;
|
||||
pub mod normalize;
|
||||
pub mod outlives_bounds;
|
||||
pub mod type_op;
|
||||
|
||||
pub use rustc_middle::traits::query::*;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
|
||||
use crate::traits::query::outlives_bounds::OutlivesBound;
|
||||
use crate::traits::query::Fallible;
|
||||
use rustc_infer::traits::query::OutlivesBound;
|
||||
use rustc_middle::ty::{ParamEnvAnd, Ty, TyCtxt};
|
||||
|
||||
#[derive(Copy, Clone, Debug, HashStable, TypeFoldable, Lift)]
|
||||
|
|
|
@ -6,12 +6,12 @@ use rustc_hir as hir;
|
|||
use rustc_infer::infer::canonical::{self, Canonical};
|
||||
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
|
||||
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
|
||||
use rustc_infer::traits::query::OutlivesBound;
|
||||
use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
use rustc_trait_selection::infer::InferCtxtBuilderExt;
|
||||
use rustc_trait_selection::traits::query::outlives_bounds::OutlivesBound;
|
||||
use rustc_trait_selection::traits::query::{CanonicalTyGoal, Fallible, NoSolution};
|
||||
use rustc_trait_selection::traits::wf;
|
||||
use rustc_trait_selection::traits::FulfillmentContext;
|
||||
|
|
|
@ -76,19 +76,19 @@ use crate::check::dropck;
|
|||
use crate::check::FnCtxt;
|
||||
use crate::mem_categorization as mc;
|
||||
use crate::middle::region;
|
||||
use crate::outlives::outlives_bounds::InferCtxtExt as _;
|
||||
use rustc_data_structures::stable_set::FxHashSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::PatKind;
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::infer::{self, RegionObligation, RegionckMode};
|
||||
use rustc_infer::infer::{self, InferCtxt, RegionObligation, RegionckMode};
|
||||
use rustc_middle::hir::place::{PlaceBase, PlaceWithHirId};
|
||||
use rustc_middle::ty::adjustment;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::infer::OutlivesEnvironmentExt;
|
||||
use rustc_trait_selection::opaque_types::InferCtxtExt;
|
||||
use rustc_trait_selection::opaque_types::InferCtxtExt as _;
|
||||
use std::ops::Deref;
|
||||
|
||||
// a variation on try that just returns unit
|
||||
|
@ -104,6 +104,51 @@ macro_rules! ignore_err {
|
|||
};
|
||||
}
|
||||
|
||||
trait OutlivesEnvironmentExt<'tcx> {
|
||||
fn add_implied_bounds(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx>,
|
||||
fn_sig_tys: FxHashSet<Ty<'tcx>>,
|
||||
body_id: hir::HirId,
|
||||
span: Span,
|
||||
);
|
||||
}
|
||||
|
||||
impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
|
||||
/// This method adds "implied bounds" into the outlives environment.
|
||||
/// Implied bounds are outlives relationships that we can deduce
|
||||
/// on the basis that certain types must be well-formed -- these are
|
||||
/// either the types that appear in the function signature or else
|
||||
/// the input types to an impl. For example, if you have a function
|
||||
/// like
|
||||
///
|
||||
/// ```
|
||||
/// fn foo<'a, 'b, T>(x: &'a &'b [T]) { }
|
||||
/// ```
|
||||
///
|
||||
/// we can assume in the caller's body that `'b: 'a` and that `T:
|
||||
/// 'b` (and hence, transitively, that `T: 'a`). This method would
|
||||
/// add those assumptions into the outlives-environment.
|
||||
///
|
||||
/// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs`
|
||||
fn add_implied_bounds(
|
||||
&mut self,
|
||||
infcx: &InferCtxt<'a, 'tcx>,
|
||||
fn_sig_tys: FxHashSet<Ty<'tcx>>,
|
||||
body_id: hir::HirId,
|
||||
span: Span,
|
||||
) {
|
||||
debug!("add_implied_bounds()");
|
||||
|
||||
for ty in fn_sig_tys {
|
||||
let ty = infcx.resolve_vars_if_possible(ty);
|
||||
debug!("add_implied_bounds: ty = {}", ty);
|
||||
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
|
||||
self.add_outlives_bounds(Some(infcx), implied_bounds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// PUBLIC ENTRY POINTS
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_span::Span;
|
|||
|
||||
mod explicit;
|
||||
mod implicit_infer;
|
||||
crate mod outlives_bounds;
|
||||
/// Code to write unit test for outlives.
|
||||
pub mod test;
|
||||
mod utils;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use crate::infer::canonical::OriginalQueryValues;
|
||||
use crate::infer::InferCtxt;
|
||||
use crate::traits::query::NoSolution;
|
||||
use crate::traits::{FulfillmentContext, ObligationCause, TraitEngine};
|
||||
use rustc_hir as hir;
|
||||
use rustc_infer::traits::TraitEngineExt as _;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_trait_selection::infer::canonical::OriginalQueryValues;
|
||||
use rustc_trait_selection::infer::InferCtxt;
|
||||
use rustc_trait_selection::traits::query::NoSolution;
|
||||
use rustc_trait_selection::traits::{FulfillmentContext, ObligationCause, TraitEngine};
|
||||
|
||||
pub use rustc_middle::traits::query::OutlivesBound;
|
||||
|
Loading…
Add table
Reference in a new issue