|
1 | 1 | use std::ops::Deref;
|
2 | 2 |
|
3 | 3 | use rustc_data_structures::fx::FxHashSet;
|
| 4 | +use rustc_hir::LangItem; |
4 | 5 | use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
|
5 | 6 | use rustc_infer::infer::canonical::query_response::make_query_region_constraints;
|
6 | 7 | use rustc_infer::infer::canonical::{
|
7 | 8 | Canonical, CanonicalExt as _, CanonicalQueryInput, CanonicalVarInfo, CanonicalVarValues,
|
8 | 9 | };
|
9 |
| -use rustc_infer::infer::{InferCtxt, RegionVariableOrigin, TyCtxtInferExt}; |
| 10 | +use rustc_infer::infer::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TyCtxtInferExt}; |
10 | 11 | use rustc_infer::traits::solve::Goal;
|
11 | 12 | use rustc_middle::traits::query::NoSolution;
|
12 | 13 | use rustc_middle::traits::solve::Certainty;
|
13 | 14 | use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitableExt as _, TypingMode};
|
14 | 15 | use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
|
15 | 16 |
|
16 |
| -use crate::traits::{EvaluateConstErr, specialization_graph}; |
| 17 | +use crate::traits::{EvaluateConstErr, ObligationCause, specialization_graph}; |
17 | 18 |
|
18 | 19 | #[repr(transparent)]
|
19 | 20 | pub struct SolverDelegate<'tcx>(InferCtxt<'tcx>);
|
@@ -55,6 +56,52 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
|
55 | 56 | (SolverDelegate(infcx), value, vars)
|
56 | 57 | }
|
57 | 58 |
|
| 59 | + fn compute_goal_fast_path( |
| 60 | + &self, |
| 61 | + goal: Goal<'tcx, ty::Predicate<'tcx>>, |
| 62 | + span: Span, |
| 63 | + ) -> Option<()> { |
| 64 | + let pred = goal.predicate.kind(); |
| 65 | + match pred.no_bound_vars()? { |
| 66 | + ty::PredicateKind::DynCompatible(def_id) if self.0.tcx.is_dyn_compatible(def_id) => { |
| 67 | + Some(()) |
| 68 | + } |
| 69 | + ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(outlives)) => { |
| 70 | + self.0.sub_regions( |
| 71 | + SubregionOrigin::RelateRegionParamBound(span, None), |
| 72 | + outlives.1, |
| 73 | + outlives.0, |
| 74 | + ); |
| 75 | + Some(()) |
| 76 | + } |
| 77 | + ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(outlives)) => { |
| 78 | + self.0.register_region_obligation_with_cause( |
| 79 | + outlives.0, |
| 80 | + outlives.1, |
| 81 | + &ObligationCause::dummy_with_span(span), |
| 82 | + ); |
| 83 | + |
| 84 | + Some(()) |
| 85 | + } |
| 86 | + ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) => { |
| 87 | + match self.0.tcx.as_lang_item(trait_pred.def_id()) { |
| 88 | + Some(LangItem::Sized) |
| 89 | + if trait_pred.self_ty().is_trivially_sized(self.0.tcx) => |
| 90 | + { |
| 91 | + Some(()) |
| 92 | + } |
| 93 | + Some(LangItem::Copy | LangItem::Clone) |
| 94 | + if trait_pred.self_ty().is_trivially_pure_clone_copy() => |
| 95 | + { |
| 96 | + Some(()) |
| 97 | + } |
| 98 | + _ => None, |
| 99 | + } |
| 100 | + } |
| 101 | + _ => None, |
| 102 | + } |
| 103 | + } |
| 104 | + |
58 | 105 | fn fresh_var_for_kind_with_span(
|
59 | 106 | &self,
|
60 | 107 | arg: ty::GenericArg<'tcx>,
|
|
0 commit comments