Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Nov 22, 2024
1 parent 0ac5a0b commit 8ba11b7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1375,8 +1375,9 @@ rustc_queries! {
/// type-checking etc, and it does not normalize specializable
/// associated types.
///
/// You should pretty much only use this if an `infcx` is available,
/// otherwise use a `TypingEnv`.
/// You should almost certainly not use this. If you already have an InferCtxt, then
/// you should also probably have a `ParamEnv` from when it was built. If you don't,
/// then you should take a `TypingEnv` to ensure that you handle opaque types correctly.
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
feedable
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_mir_transform/src/post_analysis_normalize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Normalizes MIR in TypingMode::PostAnalysis mode, most notably revealing
//! its opaques.
//! Normalizes MIR in `TypingMode::PostAnalysis`` mode, most notably revealing
//! its opaques. We also only normalize specializable associated items once in
//! `PostAnalysis` mode.
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
Expand Down
31 changes: 30 additions & 1 deletion compiler/rustc_type_ir/src/infer_ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,38 @@ pub enum TypingMode<I: Interner> {
///
/// We only normalize opaque types which may get defined by the current body,
/// which are stored in `defining_opaque_types`.
///
/// We also refuse to project any associated type that is marked `default`.
/// Non-`default` ("final") types are always projected. This is necessary in
/// general for soundness of specialization. However, we *could* allow projections
/// in fully-monomorphic cases. We choose not to, because we prefer for `default type`
/// to force the type definition to be treated abstractly by any consumers of the
/// impl. Concretely, that means that the following example will
/// fail to compile:
///
/// ```compile_fail,E0308
/// #![feature(specialization)]
/// trait Assoc {
/// type Output;
/// }
///
/// impl<T> Assoc for T {
/// default type Output = bool;
/// }
///
/// fn main() {
/// let x: <() as Assoc>::Output = true;
/// }
/// ```
Analysis { defining_opaque_types: I::DefiningOpaqueTypes },
/// After analysis, mostly during codegen and MIR optimizations, we're able to
/// reveal all opaque types.
/// reveal all opaque types. As the concrete type should *never* be observable
/// directly by the user, this should not be used by checks which may expose
/// such details to the user.
///
/// There are some exceptions to this as for example `layout_of` and const-evaluation
/// always run in `PostAnalysis` mode, even when used during analysis. This exposes
/// some information about the underlying type to users, but not the type itself.
PostAnalysis,
}

Expand Down

0 comments on commit 8ba11b7

Please sign in to comment.