]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_infer/src/infer/opaque_types.rs
Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726
[rust.git] / compiler / rustc_infer / src / infer / opaque_types.rs
1 use rustc_data_structures::vec_map::VecMap;
2 use rustc_hir as hir;
3 use rustc_middle::ty::{OpaqueTypeKey, Ty};
4 use rustc_span::Span;
5
6 pub type OpaqueTypeMap<'tcx> = VecMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
7
8 /// Information about the opaque types whose values we
9 /// are inferring in this function (these are the `impl Trait` that
10 /// appear in the return type).
11 #[derive(Copy, Clone, Debug)]
12 pub struct OpaqueTypeDecl<'tcx> {
13     /// The opaque type (`ty::Opaque`) for this declaration.
14     pub opaque_type: Ty<'tcx>,
15
16     /// The span of this particular definition of the opaque type. So
17     /// for example:
18     ///
19     /// ```ignore (incomplete snippet)
20     /// type Foo = impl Baz;
21     /// fn bar() -> Foo {
22     /// //          ^^^ This is the span we are looking for!
23     /// }
24     /// ```
25     ///
26     /// In cases where the fn returns `(impl Trait, impl Trait)` or
27     /// other such combinations, the result is currently
28     /// over-approximated, but better than nothing.
29     pub definition_span: Span,
30
31     /// The type variable that represents the value of the opaque type
32     /// that we require. In other words, after we compile this function,
33     /// we will be created a constraint like:
34     ///
35     ///     Foo<'a, T> = ?C
36     ///
37     /// where `?C` is the value of this type variable. =) It may
38     /// naturally refer to the type and lifetime parameters in scope
39     /// in this function, though ultimately it should only reference
40     /// those that are arguments to `Foo` in the constraint above. (In
41     /// other words, `?C` should not include `'b`, even though it's a
42     /// lifetime parameter on `foo`.)
43     pub concrete_ty: Ty<'tcx>,
44
45     /// The origin of the opaque type.
46     pub origin: hir::OpaqueTyOrigin,
47 }