diff --git a/compiler/rustc_monomorphize/src/mono_checks/mod.rs b/compiler/rustc_monomorphize/src/mono_checks/mod.rs index 1ecda824fb8c2..459374d860b2c 100644 --- a/compiler/rustc_monomorphize/src/mono_checks/mod.rs +++ b/compiler/rustc_monomorphize/src/mono_checks/mod.rs @@ -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; @@ -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) { diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 082c356cc5fbd..86b0c1d256f5a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -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)); } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 105cb9175717d..fa9fbb558e9c0 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -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>) -> 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 { @@ -717,13 +720,6 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec