Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 334963c

Browse files
committed
Auto merge of rust-lang#135216 - compiler-errors:check-wc, r=<try>
Check where-clauses during monomorphization 💀 💀 💀 💀 💀 💀 💀 💀 💀 r? lcnr
2 parents ad211ce + 57639d3 commit 334963c

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,12 @@ rustc_queries! {
24832483
cache_on_disk_if { true }
24842484
}
24852485

2486+
// UwU
2487+
query check_instance_wf(key: ty::Instance<'tcx>) {
2488+
desc { "monomorphization-time checking of where-clauses" }
2489+
cache_on_disk_if { true }
2490+
}
2491+
24862492
/// Builds the set of functions that should be skipped for the move-size check.
24872493
query skip_move_check_fns(_: ()) -> &'tcx FxIndexSet<DefId> {
24882494
arena_cache

compiler/rustc_monomorphize/src/mono_checks/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn check_mono_item<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
1212
let body = tcx.instance_mir(instance.def);
1313
abi_check::check_feature_dependent_abi(tcx, instance, body);
1414
move_check::check_moves(tcx, instance, body);
15+
tcx.ensure().check_instance_wf(instance);
1516
}
1617

1718
pub(super) fn provide(providers: &mut Providers) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use rustc_infer::infer::TyCtxtInferExt as _;
2+
use rustc_middle::ty::{self, TyCtxt, TypingEnv};
3+
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4+
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
5+
6+
pub(crate) fn check_instance_wf<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::Instance<'tcx>) {
7+
let ty::InstanceKind::Item(def_id) = instance.def else {
8+
// Probably want other instances too...:
9+
return;
10+
};
11+
12+
let (infcx, param_env) =
13+
tcx.infer_ctxt().build_with_typing_env(TypingEnv::fully_monomorphized());
14+
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
15+
16+
ocx.register_obligations(
17+
tcx.predicates_of(def_id).instantiate(tcx, instance.args).into_iter().map(
18+
|(clause, span)| {
19+
Obligation::new(tcx, ObligationCause::dummy_with_span(span), param_env, clause)
20+
},
21+
),
22+
);
23+
24+
let errors = ocx.select_all_or_error();
25+
if !errors.is_empty() {
26+
infcx.err_ctxt().report_fulfillment_errors(errors);
27+
}
28+
}

compiler/rustc_traits/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![warn(unreachable_pub)]
66
// tidy-alphabetical-end
77

8+
mod check_instance_wf;
89
mod codegen;
910
mod dropck_outlives;
1011
mod evaluate_obligation;
@@ -25,4 +26,5 @@ pub fn provide(p: &mut Providers) {
2526
normalize_erasing_regions::provide(p);
2627
type_op::provide(p);
2728
p.codegen_select_candidate = codegen::codegen_select_candidate;
29+
p.check_instance_wf = check_instance_wf::check_instance_wf;
2830
}

0 commit comments

Comments
 (0)