Skip to content

Check where-clauses during monomorphization #135216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,12 @@ rustc_queries! {
cache_on_disk_if { true }
}

// UwU
Copy link
Contributor

Choose a reason for hiding this comment

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

nyaaa~

query check_instance_wf(key: ty::Instance<'tcx>) {
desc { "monomorphization-time checking of where-clauses" }
cache_on_disk_if { true }
}

/// Builds the set of functions that should be skipped for the move-size check.
query skip_move_check_fns(_: ()) -> &'tcx FxIndexSet<DefId> {
arena_cache
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_monomorphize/src/mono_checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fn check_mono_item<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
let body = tcx.instance_mir(instance.def);
abi_check::check_feature_dependent_abi(tcx, instance, body);
move_check::check_moves(tcx, instance, body);
tcx.ensure().check_instance_wf(instance);
}

pub(super) fn provide(providers: &mut Providers) {
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_traits/src/check_instance_wf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use rustc_infer::infer::TyCtxtInferExt as _;
use rustc_middle::ty::{self, TyCtxt, TypingEnv};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};

pub(crate) fn check_instance_wf<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::Instance<'tcx>) {
let ty::InstanceKind::Item(def_id) = instance.def else {
// Probably want other instances too...:
return;
};

let (infcx, param_env) =
tcx.infer_ctxt().build_with_typing_env(TypingEnv::fully_monomorphized());
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);

ocx.register_obligations(
tcx.predicates_of(def_id).instantiate(tcx, instance.args).into_iter().map(
|(clause, span)| {
Obligation::new(tcx, ObligationCause::dummy_with_span(span), param_env, clause)
},
),
);

let errors = ocx.select_all_or_error();
if !errors.is_empty() {
infcx.err_ctxt().report_fulfillment_errors(errors);
}
}
2 changes: 2 additions & 0 deletions compiler/rustc_traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![warn(unreachable_pub)]
// tidy-alphabetical-end

mod check_instance_wf;
mod codegen;
mod dropck_outlives;
mod evaluate_obligation;
Expand All @@ -25,4 +26,5 @@ pub fn provide(p: &mut Providers) {
normalize_erasing_regions::provide(p);
type_op::provide(p);
p.codegen_select_candidate = codegen::codegen_select_candidate;
p.check_instance_wf = check_instance_wf::check_instance_wf;
}
Loading