@@ -9,6 +9,54 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen
9
9
10
10
use crate :: { Canonical , CanonicalVarValues , Interner , Upcast } ;
11
11
12
+ /// Depending on the stage of compilation, we want projection to be
13
+ /// more or less conservative.
14
+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
15
+ #[ cfg_attr( feature = "nightly" , derive( TyDecodable , TyEncodable , HashStable_NoContext ) ) ]
16
+ pub enum Reveal {
17
+ /// At type-checking time, we refuse to project any associated
18
+ /// type that is marked `default`. Non-`default` ("final") types
19
+ /// are always projected. This is necessary in general for
20
+ /// soundness of specialization. However, we *could* allow
21
+ /// projections in fully-monomorphic cases. We choose not to,
22
+ /// because we prefer for `default type` to force the type
23
+ /// definition to be treated abstractly by any consumers of the
24
+ /// impl. Concretely, that means that the following example will
25
+ /// fail to compile:
26
+ ///
27
+ /// ```compile_fail,E0308
28
+ /// #![feature(specialization)]
29
+ /// trait Assoc {
30
+ /// type Output;
31
+ /// }
32
+ ///
33
+ /// impl<T> Assoc for T {
34
+ /// default type Output = bool;
35
+ /// }
36
+ ///
37
+ /// fn main() {
38
+ /// let x: <() as Assoc>::Output = true;
39
+ /// }
40
+ /// ```
41
+ ///
42
+ /// We also do not reveal the hidden type of opaque types during
43
+ /// type-checking.
44
+ UserFacing ,
45
+
46
+ /// At codegen time, all monomorphic projections will succeed.
47
+ /// Also, `impl Trait` is normalized to the concrete type,
48
+ /// which has to be already collected by type-checking.
49
+ ///
50
+ /// NOTE: as `impl Trait`'s concrete type should *never*
51
+ /// be observable directly by the user, `Reveal::All`
52
+ /// should not be used by checks which may expose
53
+ /// type equality or type contents to the user.
54
+ /// There are some exceptions, e.g., around auto traits and
55
+ /// transmute-checking, which expose some details, but
56
+ /// not the whole concrete type of the `impl Trait`.
57
+ All ,
58
+ }
59
+
12
60
pub type CanonicalInput < I , T = <I as Interner >:: Predicate > = Canonical < I , QueryInput < I , T > > ;
13
61
pub type CanonicalResponse < I > = Canonical < I , Response < I > > ;
14
62
/// The result of evaluating a canonical query.
0 commit comments