Skip to content

Check preds post mono (round 2) #137003

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
7 changes: 6 additions & 1 deletion compiler/rustc_monomorphize/src/mono_checks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! checks in a way that is friendly to incremental compilation.

use rustc_middle::query::Providers;
use rustc_middle::ty::{Instance, TyCtxt};
use rustc_middle::ty::{Instance, InstanceKind, TyCtxt};

mod abi_check;
mod move_check;
Expand All @@ -12,6 +12,11 @@ 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);
if let InstanceKind::Item(def_id) = instance.def {
if tcx.instantiate_and_check_impossible_predicates((def_id, instance.args)) {
tcx.dcx().span_err(tcx.def_span(def_id), "post-mono");
}
}
}

pub(super) fn provide(providers: &mut Providers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,11 @@ where
continue;
}

// Skip RPITITs, since the AFIDT feature means that they are always implied.
if cx.is_impl_trait_in_trait(associated_type_def_id) {
continue;
}

requirements
.extend(cx.item_bounds(associated_type_def_id).iter_instantiated(cx, trait_ref.args));
}
Expand Down
14 changes: 5 additions & 9 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,11 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
/// used during analysis.
pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause<'tcx>>) -> bool {
debug!("impossible_predicates(predicates={:?})", predicates);
let (infcx, param_env) =
tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::fully_monomorphized());
let (infcx, param_env) = tcx
.infer_ctxt()
.with_next_trait_solver(true)
.build_with_typing_env(ty::TypingEnv::fully_monomorphized());

let ocx = ObligationCtxt::new(&infcx);
let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates);
for predicate in predicates {
Expand All @@ -717,13 +720,6 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
return true;
}

// Leak check for any higher-ranked trait mismatches.
// We only need to do this in the old solver, since the new solver already
// leak-checks.
if !infcx.next_trait_solver() && infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
return true;
}

false
}

Expand Down
Loading