1
Fork 0

make relate's const ty assertion use semantic equality

This commit is contained in:
Boxy 2023-02-11 23:05:11 +00:00
parent 8dabf5da9e
commit a85b0101e6
7 changed files with 237 additions and 22 deletions

View file

@ -1,12 +1,14 @@
//! Miscellaneous type-system utilities that are too small to deserve their own modules.
use crate::traits::{self, ObligationCause};
use crate::traits::{self, ObligationCause, ObligationCtxt};
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir;
use rustc_infer::infer::canonical::Canonical;
use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt};
use rustc_infer::{infer::outlives::env::OutlivesEnvironment, traits::FulfillmentError};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeVisitable};
use rustc_span::DUMMY_SP;
use super::outlives_bounds::InferCtxtExt;
@ -131,3 +133,19 @@ pub fn type_allowed_to_implement_copy<'tcx>(
Ok(())
}
pub fn check_const_param_definitely_unequal<'tcx>(
tcx: TyCtxt<'tcx>,
canonical: Canonical<'tcx, (ParamEnv<'tcx>, Ty<'tcx>, Ty<'tcx>)>,
) -> Result<(), ()> {
let (infcx, (param_env, ty_a, ty_b), _) =
tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &canonical);
let ocx = ObligationCtxt::new(&infcx);
let result = ocx.eq(&ObligationCause::dummy(), param_env, ty_a, ty_b);
// use `select_where_possible` instead of `select_all_or_error` so that
// we don't get errors from obligations being ambiguous.
let errors = ocx.select_where_possible();
if errors.len() > 0 || result.is_err() { Err(()) } else { Ok(()) }
}

View file

@ -554,6 +554,7 @@ pub fn provide(providers: &mut ty::query::Providers) {
specialization_graph_of: specialize::specialization_graph_provider,
specializes: specialize::specializes,
subst_and_check_impossible_predicates,
check_const_param_definitely_unequal: misc::check_const_param_definitely_unequal,
is_impossible_method,
..*providers
};