rustc_traits/
normalize_erasing_regions.rs1use rustc_infer::infer::TyCtxtInferExt;
2use rustc_middle::query::Providers;
3use rustc_middle::traits::query::NoSolution;
4use rustc_middle::ty::{self, PseudoCanonicalInput, TyCtxt, TypeFoldable, TypeVisitableExt};
5use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
6use rustc_trait_selection::traits::{Normalized, ObligationCause};
7use tracing::debug;
8
9pub(crate) fn provide(p: &mut Providers) {
10 *p = Providers {
11 try_normalize_generic_arg_after_erasing_regions: |tcx, goal| {
12 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_traits/src/normalize_erasing_regions.rs:12",
"rustc_traits::normalize_erasing_regions",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_traits/src/normalize_erasing_regions.rs"),
::tracing_core::__macro_support::Option::Some(12u32),
::tracing_core::__macro_support::Option::Some("rustc_traits::normalize_erasing_regions"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("try_normalize_generic_arg_after_erasing_regions(goal={0:#?}",
goal) as &dyn Value))])
});
} else { ; }
};debug!("try_normalize_generic_arg_after_erasing_regions(goal={:#?}", goal);
13
14 try_normalize_after_erasing_regions(tcx, goal)
15 },
16 ..*p
17 };
18}
19
20fn try_normalize_after_erasing_regions<'tcx, T: TypeFoldable<TyCtxt<'tcx>> + PartialEq + Copy>(
21 tcx: TyCtxt<'tcx>,
22 goal: PseudoCanonicalInput<'tcx, T>,
23) -> Result<T, NoSolution> {
24 let PseudoCanonicalInput { typing_env, value } = goal;
25 let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
26 let cause = ObligationCause::dummy();
27 match infcx.at(&cause, param_env).query_normalize(value) {
28 Ok(Normalized { value: normalized_value, obligations: normalized_obligations }) => {
29 match (&normalized_obligations.iter().find(|p|
not_outlives_predicate(p.predicate)), &None) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(
35 normalized_obligations.iter().find(|p| not_outlives_predicate(p.predicate)),
36 None,
37 );
38
39 let resolved_value = infcx.resolve_vars_if_possible(normalized_value);
40 if true {
match (&normalized_value, &resolved_value) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};debug_assert_eq!(normalized_value, resolved_value);
44 let erased = infcx.tcx.erase_and_anonymize_regions(resolved_value);
45 if infcx.next_trait_solver() {
46 if true {
if !!erased.has_infer() {
{ ::core::panicking::panic_fmt(format_args!("{0:?}", erased)); }
};
};debug_assert!(!erased.has_infer(), "{erased:?}");
47 } else {
48 if erased.has_infer() {
54 return Err(NoSolution);
55 }
56 }
57 Ok(erased)
58 }
59 Err(NoSolution) => Err(NoSolution),
60 }
61}
62
63fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
64 match p.kind().skip_binder() {
65 ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
66 | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..)) => false,
67 ty::PredicateKind::Clause(ty::ClauseKind::Trait(..))
68 | ty::PredicateKind::Clause(ty::ClauseKind::Projection(..))
69 | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
70 | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
71 | ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
72 | ty::PredicateKind::NormalizesTo(..)
73 | ty::PredicateKind::AliasRelate(..)
74 | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
75 | ty::PredicateKind::DynCompatible(..)
76 | ty::PredicateKind::Subtype(..)
77 | ty::PredicateKind::Coerce(..)
78 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
79 | ty::PredicateKind::ConstEquate(..)
80 | ty::PredicateKind::Ambiguous => true,
81 }
82}