Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,19 @@ impl<'tcx> Body<'tcx> {

pub fn typing_env(&self, tcx: TyCtxt<'tcx>) -> TypingEnv<'tcx> {
match self.phase {
// FIXME(#132279): we should reveal the opaques defined in the body during analysis.
MirPhase::Built | MirPhase::Analysis(_) => TypingEnv {
typing_mode: ty::TypingMode::non_body_analysis(),
param_env: tcx.param_env(self.source.def_id()),
},
MirPhase::Built | MirPhase::Analysis(_) => {
let def_id = self.source.def_id();
let typing_mode = match self.source.instance {
InstanceKind::Item(item_def_id) => item_def_id
.as_local()
.map_or(ty::TypingMode::non_body_analysis(), |local_def_id| {
Comment on lines +425 to +426
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when do we have non-local DefIds here?

ty::TypingMode::analysis_in_body(tcx, local_def_id)
}),
_ => ty::TypingMode::non_body_analysis(),
};

TypingEnv { typing_mode, param_env: tcx.param_env(def_id) }
}
MirPhase::Runtime(_) => TypingEnv::post_analysis(tcx, self.source.def_id()),
}
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
if pred.has_opaque_types() {
return true;
}
if self.typing_env.typing_mode.may_define_opaque_types() {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? This means we're now checking less things. Given that the typing env now correctly reveals opauqes, why do we need either the old or the new check? I would expect the change in TypingEnv to remove the need for both


let (infcx, param_env) = self.tcx.infer_ctxt().build_with_typing_env(self.typing_env);
let ocx = ObligationCtxt::new(&infcx);
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_type_ir/src/infer_ctxt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ impl<I: Interner> TypingMode<I> {
TypingMode::PostBorrowckAnalysis { defined_opaque_types }
}
}

/// Returns `true` if this typing mode is allowed to define new opaque types.
pub fn may_define_opaque_types(&self) -> bool {
match self {
TypingMode::Analysis { defining_opaque_types_and_generators } => {
!defining_opaque_types_and_generators.is_empty()
}
TypingMode::Borrowck { defining_opaque_types } => !defining_opaque_types.is_empty(),
_ => false,
}
}
}

#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir_infer_ctxt_like")]
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to remove the known-bug comment here and add other annotations to make the test pass (which can include failing compilation)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli-obk Thank you for the feedback. I addressed it in my most recent commit.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ known-bug: #131886
//@ compile-flags: -Zvalidate-mir
//@ check-pass
#![feature(type_alias_impl_trait)]

type Tait = impl Sized;
Expand Down
Loading