]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_typeck/src/check/regionck.rs
Rollup merge of #98256 - GuillaumeGomez:whitespace-where-clause, r=notriddle
[rust.git] / compiler / rustc_typeck / src / check / regionck.rs
1 use crate::outlives::outlives_bounds::InferCtxtExt as _;
2 use rustc_data_structures::stable_set::FxHashSet;
3 use rustc_hir as hir;
4 use rustc_infer::infer::outlives::env::OutlivesEnvironment;
5 use rustc_infer::infer::InferCtxt;
6 use rustc_middle::ty::Ty;
7
8 pub(crate) trait OutlivesEnvironmentExt<'tcx> {
9     fn add_implied_bounds(
10         &mut self,
11         infcx: &InferCtxt<'_, 'tcx>,
12         fn_sig_tys: FxHashSet<Ty<'tcx>>,
13         body_id: hir::HirId,
14     );
15 }
16
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
23     /// like
24     ///
25     /// ```
26     /// fn foo<'a, 'b, T>(x: &'a &'b [T]) { }
27     /// ```
28     ///
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.
32     ///
33     /// Tests: `src/test/ui/regions/regions-free-region-ordering-*.rs`
34     #[instrument(level = "debug", skip(self, infcx))]
35     fn add_implied_bounds<'a>(
36         &mut self,
37         infcx: &InferCtxt<'a, 'tcx>,
38         fn_sig_tys: FxHashSet<Ty<'tcx>>,
39         body_id: hir::HirId,
40     ) {
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)
45         }
46     }
47 }