1 use crate::outlives::outlives_bounds::InferCtxtExt as _;
2 use rustc_data_structures::fx::FxHashSet;
4 use rustc_infer::infer::outlives::env::OutlivesEnvironment;
5 use rustc_infer::infer::InferCtxt;
6 use rustc_middle::ty::Ty;
8 pub(crate) trait OutlivesEnvironmentExt<'tcx> {
11 infcx: &InferCtxt<'_, 'tcx>,
12 fn_sig_tys: FxHashSet<Ty<'tcx>>,
17 impl<'tcx> OutlivesEnvironmentExt<'tcx> for OutlivesEnvironment<'tcx> {
18 /// This method adds "implied bounds" into the outlives environment.
19 /// Implied bounds are outlives relationships that we can deduce
20 /// on the basis that certain types must be well-formed -- these are
21 /// either the types that appear in the function signature or else
22 /// the input types to an impl. For example, if you have a function
26 /// fn foo<'a, 'b, T>(x: &'a &'b [T]) { }
29 /// we can assume in the caller's body that `'b: 'a` and that `T:
30 /// 'b` (and hence, transitively, that `T: 'a`). This method would
31 /// add those assumptions into the outlives-environment.
33 /// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs`
34 #[instrument(level = "debug", skip(self, infcx))]
35 fn add_implied_bounds<'a>(
37 infcx: &InferCtxt<'a, 'tcx>,
38 fn_sig_tys: FxHashSet<Ty<'tcx>>,
41 for ty in fn_sig_tys {
42 let ty = infcx.resolve_vars_if_possible(ty);
43 let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty);
44 self.add_outlives_bounds(Some(infcx), implied_bounds)