rustc_trait_selection/traits/query/type_op/
prove_predicate.rs1use rustc_infer::traits::Obligation;
2use rustc_middle::traits::ObligationCause;
3use rustc_middle::traits::query::NoSolution;
4pub use rustc_middle::traits::query::type_op::ProvePredicate;
5use rustc_middle::ty::{self, ParamEnvAnd, TyCtxt};
6use rustc_span::Span;
7
8use crate::infer::canonical::{CanonicalQueryInput, CanonicalQueryResponse};
9use crate::traits::{ObligationCtxt, sizedness_fast_path};
10
11impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
12 type QueryResponse = ();
13
14 fn try_fast_path(
15 tcx: TyCtxt<'tcx>,
16 key: &ParamEnvAnd<'tcx, Self>,
17 ) -> Option<Self::QueryResponse> {
18 if sizedness_fast_path(tcx, key.value.predicate) {
19 return Some(());
20 }
21
22 if let ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(term)) =
23 key.value.predicate.kind().skip_binder()
24 {
25 match term.as_type()?.kind() {
26 ty::Param(_)
27 | ty::Bool
28 | ty::Char
29 | ty::Int(_)
30 | ty::Float(_)
31 | ty::Str
32 | ty::Uint(_) => {
33 return Some(());
34 }
35 _ => {}
36 }
37 }
38
39 None
40 }
41
42 fn perform_query(
43 tcx: TyCtxt<'tcx>,
44 canonicalized: CanonicalQueryInput<'tcx, ParamEnvAnd<'tcx, Self>>,
45 ) -> Result<CanonicalQueryResponse<'tcx, ()>, NoSolution> {
46 tcx.type_op_prove_predicate(canonicalized)
47 }
48
49 fn perform_locally_with_next_solver(
50 ocx: &ObligationCtxt<'_, 'tcx>,
51 key: ParamEnvAnd<'tcx, Self>,
52 span: Span,
53 ) -> Result<Self::QueryResponse, NoSolution> {
54 ocx.register_obligation(Obligation::new(
55 ocx.infcx.tcx,
56 ObligationCause::dummy_with_span(span),
57 key.param_env,
58 key.value.predicate,
59 ));
60 Ok(())
61 }
62}