Skip to content
Merged
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
17 changes: 17 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,23 @@ impl<'tcx> TypingEnv<'tcx> {
Self::new(tcx.param_env(def_id), TypingMode::non_body_analysis())
}

/// Ideally we just use `TypingMode::PostTypeckUntilBorrowck`.
/// But that's not compatible with the old solver yet.
///
/// FIXME: this should not be needed in the long term.
pub fn post_typeck_until_borrowck_for_mir_build(
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
) -> TypingEnv<'tcx> {
if tcx.use_typing_mode_post_typeck_until_borrowck() {
TypingEnv::new(tcx.param_env(def_id.to_def_id()), ty::TypingMode::borrowck(tcx, def_id))
} else {
// FIXME(#132279): We're in a body, we should use a typing
// mode which reveals the opaque types defined by that body.
TypingEnv::non_body_analysis(tcx, def_id)
}
}

pub fn post_analysis(tcx: TyCtxt<'tcx>, def_id: impl IntoQueryKey<DefId>) -> TypingEnv<'tcx> {
TypingEnv::new(tcx.param_env_normalized_for_post_analysis(def_id), TypingMode::PostAnalysis)
}
Expand Down
24 changes: 18 additions & 6 deletions compiler/rustc_mir_build/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,15 @@ fn construct_fn<'tcx>(
);
}

// FIXME(#132279): This should be able to reveal opaque
// types defined during HIR typeck.
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
let typing_mode = if tcx.use_typing_mode_post_typeck_until_borrowck() {
TypingMode::borrowck(tcx, fn_def)
} else {
// FIXME(#132279): This should be able to reveal opaque
// types defined during HIR typeck.
TypingMode::non_body_analysis()
};

let infcx = tcx.infer_ctxt().build(typing_mode);
let mut builder = Builder::new(
thir,
infcx,
Expand Down Expand Up @@ -586,9 +592,15 @@ fn construct_const<'a, 'tcx>(
_ => span_bug!(tcx.def_span(def), "can't build MIR for {:?}", def),
};

// FIXME(#132279): We likely want to be able to use the hidden types of
// opaques used by this function here.
let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis());
let typing_mode = if tcx.use_typing_mode_post_typeck_until_borrowck() {
TypingMode::borrowck(tcx, def)
} else {
// FIXME(#132279): This should be able to reveal opaque
// types defined during HIR typeck.
TypingMode::non_body_analysis()
};

let infcx = tcx.infer_ctxt().build(typing_mode);
let mut builder =
Builder::new(thir, infcx, def, hir_id, span, 0, const_ty, const_ty_span, None);

Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_mir_build/src/builder/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
tcx: self.tcx,
typeck_results,
module: self.tcx.parent_module(self.hir_id).to_def_id(),
// FIXME(#132279): We're in a body, should handle opaques.
typing_env: rustc_middle::ty::TypingEnv::non_body_analysis(self.tcx, self.def_id),
typing_env: ty::TypingEnv::post_typeck_until_borrowck_for_mir_build(
self.tcx,
self.def_id,
),
dropless_arena: &dropless_arena,
match_lint_level: self.hir_id,
whole_match_span: Some(rustc_span::Span::default()),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/check_tail_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ pub(crate) fn check_tail_calls(tcx: TyCtxt<'_>, def: LocalDefId) -> Result<(), E
tcx,
thir,
found_errors: Ok(()),
// FIXME(#132279): we're clearly in a body here.
typing_env: ty::TypingEnv::non_body_analysis(tcx, def),
typing_env: ty::TypingEnv::post_typeck_until_borrowck_for_mir_build(tcx, def),
is_closure,
caller_def_id: def,
};
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,8 +1093,7 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
body_target_features,
assignment_info: None,
in_union_destructure: false,
// FIXME(#132279): we're clearly in a body here.
typing_env: ty::TypingEnv::non_body_analysis(tcx, def),
typing_env: ty::TypingEnv::post_typeck_until_borrowck_for_mir_build(tcx, def),
inside_adt: false,
warnings: &mut warnings,
suggest_unsafe_block: true,
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_mir_build/src/thir/cx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
Self {
tcx,
thir: Thir::new(body_type),
// FIXME(#132279): We're in a body, we should use a typing
// mode which reveals the opaque types defined by that body.
typing_env: ty::TypingEnv::non_body_analysis(tcx, def),
typing_env: ty::TypingEnv::post_typeck_until_borrowck_for_mir_build(tcx, def),
typeck_results,
body_owner: def.to_def_id(),
apply_adjustments: !find_attr!(tcx, hir_id, CustomMir(..)),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ pub(crate) fn check_match(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), Err
tcx,
thir: &*thir,
typeck_results,
// FIXME(#132279): We're in a body, should handle opaques.
typing_env: ty::TypingEnv::non_body_analysis(tcx, def_id),
typing_env: ty::TypingEnv::post_typeck_until_borrowck_for_mir_build(tcx, def_id),
hir_source: tcx.local_def_id_to_hir_id(def_id),
let_source: LetSource::None,
pattern_arena: &pattern_arena,
Expand Down
27 changes: 27 additions & 0 deletions tests/ui/traits/next-solver/opaques/wrong-typing-mode-ice-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@ compile-flags: -Znext-solver
//@ edition: 2024

// Previously, when building MIR body, we were using typing env
// `non_body_analysis` which is wrong since we're indeed in a body.
// It caused opaque types in defining body to be not revealed.
// This caused opaque types in the defining body not to be revealed.

#![feature(type_alias_impl_trait)]

struct Task<F>(F);

impl Task<Foo> {
fn spawn(&self, _: impl FnOnce() -> Foo) {}
}
type Foo = impl Sized;

#[define_opaque(Foo)]
fn foo() {
async fn cb() {}
Task::spawn(&POOL, cb)
}

static POOL: Task<Foo> = todo!();
//~^ ERROR: evaluation panicked

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0080]: evaluation panicked: not yet implemented
--> $DIR/wrong-typing-mode-ice-1.rs:24:26
|
LL | static POOL: Task<Foo> = todo!();
| ^^^^^^^ evaluation of `POOL` failed here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
15 changes: 15 additions & 0 deletions tests/ui/traits/next-solver/opaques/wrong-typing-mode-ice-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ compile-flags: -Znext-solver
//@ check-pass

// Previously, when building MIR body, we were using typing env
// `non_body_analysis` which is wrong since we're indeed in a body.
// It caused opaque types in defining body to be not revealed.
// This caused opaque types in the defining body not to be revealed.

#![feature(type_alias_impl_trait)]
fn main() {
struct Foo(U);
type U = impl Copy;
let foo: _ = Foo(());
let Foo(()) = foo;
}
Loading