Skip to content

Commit 5871733

Browse files
Uplift Reveal to rustc_type_ir
1 parent f6236f6 commit 5871733

File tree

2 files changed

+49
-48
lines changed

2 files changed

+49
-48
lines changed

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,54 +32,7 @@ use std::hash::{Hash, Hasher};
3232

3333
pub use self::select::{EvaluationCache, EvaluationResult, OverflowError, SelectionCache};
3434
// FIXME: Remove this import and import via `solve::`
35-
pub use rustc_type_ir::solve::BuiltinImplSource;
36-
37-
/// Depending on the stage of compilation, we want projection to be
38-
/// more or less conservative.
39-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, HashStable, Encodable, Decodable)]
40-
pub enum Reveal {
41-
/// At type-checking time, we refuse to project any associated
42-
/// type that is marked `default`. Non-`default` ("final") types
43-
/// are always projected. This is necessary in general for
44-
/// soundness of specialization. However, we *could* allow
45-
/// projections in fully-monomorphic cases. We choose not to,
46-
/// because we prefer for `default type` to force the type
47-
/// definition to be treated abstractly by any consumers of the
48-
/// impl. Concretely, that means that the following example will
49-
/// fail to compile:
50-
///
51-
/// ```compile_fail,E0308
52-
/// #![feature(specialization)]
53-
/// trait Assoc {
54-
/// type Output;
55-
/// }
56-
///
57-
/// impl<T> Assoc for T {
58-
/// default type Output = bool;
59-
/// }
60-
///
61-
/// fn main() {
62-
/// let x: <() as Assoc>::Output = true;
63-
/// }
64-
/// ```
65-
///
66-
/// We also do not reveal the hidden type of opaque types during
67-
/// type-checking.
68-
UserFacing,
69-
70-
/// At codegen time, all monomorphic projections will succeed.
71-
/// Also, `impl Trait` is normalized to the concrete type,
72-
/// which has to be already collected by type-checking.
73-
///
74-
/// NOTE: as `impl Trait`'s concrete type should *never*
75-
/// be observable directly by the user, `Reveal::All`
76-
/// should not be used by checks which may expose
77-
/// type equality or type contents to the user.
78-
/// There are some exceptions, e.g., around auto traits and
79-
/// transmute-checking, which expose some details, but
80-
/// not the whole concrete type of the `impl Trait`.
81-
All,
82-
}
35+
pub use rustc_type_ir::solve::{BuiltinImplSource, Reveal};
8336

8437
/// The reason why we incurred this obligation; used for error reporting.
8538
///

compiler/rustc_type_ir/src/solve.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,54 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen
99

1010
use crate::{Canonical, CanonicalVarValues, Interner, Upcast};
1111

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+
1260
pub type CanonicalInput<I, T = <I as Interner>::Predicate> = Canonical<I, QueryInput<I, T>>;
1361
pub type CanonicalResponse<I> = Canonical<I, Response<I>>;
1462
/// The result of evaluating a canonical query.

0 commit comments

Comments
 (0)