use type alias impl trait in outlives_bounds::InferCtxtExt

This commit is contained in:
SparrowLii 2022-08-01 10:23:09 +08:00
parent d037f1843e
commit d39fefdd69
5 changed files with 26 additions and 14 deletions

View File

@ -256,6 +256,7 @@ pub trait Analysis<'tcx>: AnalysisDomain<'tcx> {
/// .iterate_to_fixpoint() /// .iterate_to_fixpoint()
/// .into_results_cursor(body); /// .into_results_cursor(body);
/// ``` /// ```
#[inline]
fn into_engine<'mir>( fn into_engine<'mir>(
self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
@ -413,7 +414,7 @@ where
} }
/* Extension methods */ /* Extension methods */
#[inline]
fn into_engine<'mir>( fn into_engine<'mir>(
self, self,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,

View File

@ -699,7 +699,7 @@ fn resolve_regions_with_wf_tys<'tcx>(
let outlives_environment = OutlivesEnvironment::with_bounds( let outlives_environment = OutlivesEnvironment::with_bounds(
param_env, param_env,
Some(&infcx), Some(&infcx),
infcx.implied_bounds_tys(param_env, id, wf_tys.iter().map(|ty| *ty)), infcx.implied_bounds_tys(param_env, id, wf_tys.clone()),
); );
let region_bound_pairs = outlives_environment.region_bound_pairs(); let region_bound_pairs = outlives_environment.region_bound_pairs();

View File

@ -158,6 +158,16 @@ fn get_impl_substs<'tcx>(
let errors = ocx.select_all_or_error(); let errors = ocx.select_all_or_error();
if !errors.is_empty() { if !errors.is_empty() {
ocx.infcx.report_fulfillment_errors(&errors, None, false); ocx.infcx.report_fulfillment_errors(&errors, None, false);

View File

@ -72,6 +72,7 @@ This API is completely unstable and subject to change.
#![feature(slice_partition_dedup)] #![feature(slice_partition_dedup)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![feature(is_some_with)] #![feature(is_some_with)]
#![feature(type_alias_impl_trait)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use] #[macro_use]

View File

@ -1,3 +1,4 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::HirId; use rustc_hir::HirId;
use rustc_middle::ty::{self, ParamEnv, Ty}; use rustc_middle::ty::{self, ParamEnv, Ty};
@ -8,6 +9,7 @@ use rustc_trait_selection::traits::{ObligationCause, TraitEngine, TraitEngineExt
pub use rustc_middle::traits::query::OutlivesBound; pub use rustc_middle::traits::query::OutlivesBound;
type Bounds<'a, 'tcx: 'a> = impl Iterator<Item = OutlivesBound<'tcx>> + 'a;
pub trait InferCtxtExt<'a, 'tcx> { pub trait InferCtxtExt<'a, 'tcx> {
fn implied_outlives_bounds( fn implied_outlives_bounds(
&self, &self,
@ -20,8 +22,8 @@ pub trait InferCtxtExt<'a, 'tcx> {
&'a self, &'a self,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
body_id: hir::HirId, body_id: hir::HirId,
tys: impl IntoIterator<Item = Ty<'tcx>> + 'a, tys: FxHashSet<Ty<'tcx>>,
) -> Box<dyn Iterator<Item = OutlivesBound<'tcx>> + 'a>; ) -> Bounds<'a, 'tcx>;
} }
impl<'a, 'cx, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'cx, 'tcx> { impl<'a, 'cx, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'cx, 'tcx> {
@ -100,15 +102,13 @@ impl<'a, 'cx, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'cx, 'tcx> {
&'a self, &'a self,
param_env: ParamEnv<'tcx>, param_env: ParamEnv<'tcx>,
body_id: HirId, body_id: HirId,
tys: impl IntoIterator<Item = Ty<'tcx>> + 'a, tys: FxHashSet<Ty<'tcx>>,
) -> Box<dyn Iterator<Item = OutlivesBound<'tcx>> + 'a> { ) -> Bounds<'a, 'tcx> {
Box::new( tys.into_iter()
tys.into_iter() .map(move |ty| {
.map(move |ty| { let ty = self.resolve_vars_if_possible(ty);
let ty = self.resolve_vars_if_possible(ty); self.implied_outlives_bounds(param_env, body_id, ty)
self.implied_outlives_bounds(param_env, body_id, ty) })
}) .flatten()
.flatten(),
)
} }
} }