提交 6544d7b6 编写于 作者: B Bastian Kauschke

change `Predicate::kind` to return a reference

上级 57746f94
......@@ -11,42 +11,42 @@ pub fn anonymize_predicate<'tcx>(
pred: &ty::Predicate<'tcx>,
) -> ty::Predicate<'tcx> {
match pred.kind() {
ty::PredicateKind::Trait(ref data, constness) => {
&ty::PredicateKind::Trait(ref data, constness) => {
ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
.to_predicate(tcx)
}
ty::PredicateKind::RegionOutlives(ref data) => {
ty::PredicateKind::RegionOutlives(data) => {
ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
.to_predicate(tcx)
}
ty::PredicateKind::TypeOutlives(ref data) => {
ty::PredicateKind::TypeOutlives(data) => {
ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
.to_predicate(tcx)
}
ty::PredicateKind::Projection(ref data) => {
ty::PredicateKind::Projection(data) => {
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
}
ty::PredicateKind::WellFormed(data) => {
&ty::PredicateKind::WellFormed(data) => {
ty::PredicateKind::WellFormed(data).to_predicate(tcx)
}
ty::PredicateKind::ObjectSafe(data) => {
&ty::PredicateKind::ObjectSafe(data) => {
ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
}
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
}
ty::PredicateKind::Subtype(ref data) => {
ty::PredicateKind::Subtype(data) => {
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
}
......
......@@ -1023,8 +1023,8 @@ pub struct Predicate<'tcx> {
}
impl Predicate<'tcx> {
pub fn kind(&self) -> PredicateKind<'tcx> {
*self.kind
pub fn kind(&self) -> &'tcx PredicateKind<'tcx> {
self.kind
}
}
......@@ -1163,35 +1163,36 @@ pub fn subst_supertrait(
// this trick achieves that).
let substs = &trait_ref.skip_binder().substs;
match self.kind() {
PredicateKind::Trait(ref binder, constness) => {
let predicate = match self.kind() {
&PredicateKind::Trait(ref binder, constness) => {
PredicateKind::Trait(binder.map_bound(|data| data.subst(tcx, substs)), constness)
}
PredicateKind::Subtype(ref binder) => {
PredicateKind::Subtype(binder) => {
PredicateKind::Subtype(binder.map_bound(|data| data.subst(tcx, substs)))
}
PredicateKind::RegionOutlives(ref binder) => {
PredicateKind::RegionOutlives(binder) => {
PredicateKind::RegionOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
}
PredicateKind::TypeOutlives(ref binder) => {
PredicateKind::TypeOutlives(binder) => {
PredicateKind::TypeOutlives(binder.map_bound(|data| data.subst(tcx, substs)))
}
PredicateKind::Projection(ref binder) => {
PredicateKind::Projection(binder) => {
PredicateKind::Projection(binder.map_bound(|data| data.subst(tcx, substs)))
}
PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)),
PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id),
PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
&PredicateKind::WellFormed(data) => PredicateKind::WellFormed(data.subst(tcx, substs)),
&PredicateKind::ObjectSafe(trait_def_id) => PredicateKind::ObjectSafe(trait_def_id),
&PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
PredicateKind::ClosureKind(closure_def_id, closure_substs.subst(tcx, substs), kind)
}
PredicateKind::ConstEvaluatable(def_id, const_substs) => {
&PredicateKind::ConstEvaluatable(def_id, const_substs) => {
PredicateKind::ConstEvaluatable(def_id, const_substs.subst(tcx, substs))
}
PredicateKind::ConstEquate(c1, c2) => {
PredicateKind::ConstEquate(c1.subst(tcx, substs), c2.subst(tcx, substs))
}
}
.to_predicate(tcx)
};
predicate.to_predicate(tcx)
}
}
......@@ -1370,7 +1371,7 @@ fn to_predicate(&self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
impl<'tcx> Predicate<'tcx> {
pub fn to_opt_poly_trait_ref(&self) -> Option<PolyTraitRef<'tcx>> {
match self.kind() {
PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()),
&PredicateKind::Trait(ref t, _) => Some(t.to_poly_trait_ref()),
PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
| PredicateKind::RegionOutlives(..)
......@@ -1385,7 +1386,7 @@ pub fn to_opt_poly_trait_ref(&self) -> Option<PolyTraitRef<'tcx>> {
pub fn to_opt_type_outlives(&self) -> Option<PolyTypeOutlivesPredicate<'tcx>> {
match self.kind() {
PredicateKind::TypeOutlives(data) => Some(data),
&PredicateKind::TypeOutlives(data) => Some(data),
PredicateKind::Trait(..)
| PredicateKind::Projection(..)
| PredicateKind::Subtype(..)
......
......@@ -2032,28 +2032,28 @@ pub fn print_only_trait_path(self) -> ty::Binder<TraitRefPrintOnlyTraitPath<'tcx
ty::Predicate<'tcx> {
match self.kind() {
ty::PredicateKind::Trait(ref data, constness) => {
&ty::PredicateKind::Trait(ref data, constness) => {
if let hir::Constness::Const = constness {
p!(write("const "));
}
p!(print(data))
}
ty::PredicateKind::Subtype(ref predicate) => p!(print(predicate)),
ty::PredicateKind::RegionOutlives(ref predicate) => p!(print(predicate)),
ty::PredicateKind::TypeOutlives(ref predicate) => p!(print(predicate)),
ty::PredicateKind::Projection(ref predicate) => p!(print(predicate)),
ty::PredicateKind::Subtype(predicate) => p!(print(predicate)),
ty::PredicateKind::RegionOutlives(predicate) => p!(print(predicate)),
ty::PredicateKind::TypeOutlives(predicate) => p!(print(predicate)),
ty::PredicateKind::Projection(predicate) => p!(print(predicate)),
ty::PredicateKind::WellFormed(ty) => p!(print(ty), write(" well-formed")),
ty::PredicateKind::ObjectSafe(trait_def_id) => {
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
p!(write("the trait `"),
print_def_path(trait_def_id, &[]),
write("` is object-safe"))
}
ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
&ty::PredicateKind::ClosureKind(closure_def_id, _closure_substs, kind) => {
p!(write("the closure `"),
print_value_path(closure_def_id, &[]),
write("` implements the trait `{}`", kind))
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
p!(write("the constant `"),
print_value_path(def_id, substs),
write("` can be evaluated"))
......
......@@ -39,7 +39,7 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
ty::PredicateKind::Subtype(_) => {
bug!("subtype predicate on function: {:#?}", predicate)
}
ty::PredicateKind::Trait(pred, constness) => {
&ty::PredicateKind::Trait(pred, constness) => {
if Some(pred.def_id()) == tcx.lang_items().sized_trait() {
continue;
}
......
......@@ -634,7 +634,7 @@ fn evaluate_nested_obligations(
// We check this by calling is_of_param on the relevant types
// from the various possible predicates
match predicate.kind() {
ty::PredicateKind::Trait(p, _) => {
&ty::PredicateKind::Trait(p, _) => {
if self.is_param_no_infer(p.skip_binder().trait_ref.substs)
&& !only_projections
&& is_new_pred
......@@ -643,7 +643,7 @@ fn evaluate_nested_obligations(
}
predicates.push_back(p);
}
ty::PredicateKind::Projection(p) => {
&ty::PredicateKind::Projection(p) => {
debug!(
"evaluate_nested_obligations: examining projection predicate {:?}",
predicate
......
......@@ -524,12 +524,12 @@ fn report_selection_error(
)
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
let violations = self.tcx.object_safety_violations(trait_def_id);
report_object_safety_error(self.tcx, span, trait_def_id, violations)
}
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
let found_kind = self.closure_kind(closure_substs).unwrap();
let closure_span =
self.tcx.sess.source_map().guess_head_span(
......
......@@ -443,7 +443,7 @@ fn process_obligation(
}
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
if !self.selcx.tcx().is_object_safe(trait_def_id) {
ProcessResult::Error(CodeSelectionError(Unimplemented))
} else {
......@@ -451,7 +451,7 @@ fn process_obligation(
}
}
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.selcx.infcx().closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
......@@ -464,7 +464,7 @@ fn process_obligation(
}
}
ty::PredicateKind::WellFormed(ty) => {
&ty::PredicateKind::WellFormed(ty) => {
match wf::obligations(
self.selcx.infcx(),
obligation.param_env,
......@@ -481,7 +481,7 @@ fn process_obligation(
}
}
ty::PredicateKind::Subtype(ref subtype) => {
ty::PredicateKind::Subtype(subtype) => {
match self.selcx.infcx().subtype_predicate(
&obligation.cause,
obligation.param_env,
......@@ -510,7 +510,7 @@ fn process_obligation(
}
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
match self.selcx.infcx().const_eval_resolve(
obligation.param_env,
def_id,
......
......@@ -930,7 +930,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>(
let infcx = selcx.infcx();
for predicate in env_predicates {
debug!("assemble_candidates_from_predicates: predicate={:?}", predicate);
if let ty::PredicateKind::Projection(data) = predicate.kind() {
if let &ty::PredicateKind::Projection(data) = predicate.kind() {
let same_def_id = data.projection_def_id() == obligation.predicate.item_def_id;
let is_match = same_def_id
......@@ -1167,12 +1167,10 @@ fn confirm_object_candidate<'cx, 'tcx>(
// select only those projections that are actually projecting an
// item with the correct name
let env_predicates = env_predicates.filter_map(|o| match o.predicate.kind() {
ty::PredicateKind::Projection(data) => {
if data.projection_def_id() == obligation.predicate.item_def_id {
Some(data)
} else {
None
}
&ty::PredicateKind::Projection(data)
if data.projection_def_id() == obligation.predicate.item_def_id =>
{
Some(data)
}
_ => None,
});
......
......@@ -414,13 +414,13 @@ fn evaluate_predicate_recursively<'o>(
}
match obligation.predicate.kind() {
ty::PredicateKind::Trait(ref t, _) => {
ty::PredicateKind::Trait(t, _) => {
debug_assert!(!t.has_escaping_bound_vars());
let obligation = obligation.with(*t);
self.evaluate_trait_predicate_recursively(previous_stack, obligation)
}
ty::PredicateKind::Subtype(ref p) => {
ty::PredicateKind::Subtype(p) => {
// Does this code ever run?
match self.infcx.subtype_predicate(&obligation.cause, obligation.param_env, p) {
Some(Ok(InferOk { mut obligations, .. })) => {
......@@ -435,7 +435,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateKind::WellFormed(ty) => match wf::obligations(
&ty::PredicateKind::WellFormed(ty) => match wf::obligations(
self.infcx,
obligation.param_env,
obligation.cause.body_id,
......@@ -454,7 +454,7 @@ fn evaluate_predicate_recursively<'o>(
Ok(EvaluatedToOkModuloRegions)
}
ty::PredicateKind::ObjectSafe(trait_def_id) => {
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
if self.tcx().is_object_safe(trait_def_id) {
Ok(EvaluatedToOk)
} else {
......@@ -462,7 +462,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateKind::Projection(ref data) => {
ty::PredicateKind::Projection(data) => {
let project_obligation = obligation.with(*data);
match project::poly_project_and_unify_type(self, &project_obligation) {
Ok(Some(mut subobligations)) => {
......@@ -483,7 +483,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
match self.infcx.closure_kind(closure_substs) {
Some(closure_kind) => {
if closure_kind.extends(kind) {
......@@ -496,7 +496,7 @@ fn evaluate_predicate_recursively<'o>(
}
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
match self.tcx().const_eval_resolve(
obligation.param_env,
def_id,
......
......@@ -73,28 +73,28 @@ pub fn predicate_obligations<'a, 'tcx>(
// (*) ok to skip binders, because wf code is prepared for it
match predicate.kind() {
ty::PredicateKind::Trait(ref t, _) => {
ty::PredicateKind::Trait(t, _) => {
wf.compute_trait_ref(&t.skip_binder().trait_ref, Elaborate::None); // (*)
}
ty::PredicateKind::RegionOutlives(..) => {}
ty::PredicateKind::TypeOutlives(ref t) => {
ty::PredicateKind::TypeOutlives(t) => {
wf.compute(t.skip_binder().0);
}
ty::PredicateKind::Projection(ref t) => {
ty::PredicateKind::Projection(t) => {
let t = t.skip_binder(); // (*)
wf.compute_projection(t.projection_ty);
wf.compute(t.ty);
}
ty::PredicateKind::WellFormed(t) => {
&ty::PredicateKind::WellFormed(t) => {
wf.compute(t);
}
ty::PredicateKind::ObjectSafe(_) => {}
ty::PredicateKind::ClosureKind(..) => {}
ty::PredicateKind::Subtype(ref data) => {
ty::PredicateKind::Subtype(data) => {
wf.compute(data.skip_binder().a); // (*)
wf.compute(data.skip_binder().b); // (*)
}
ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
let obligations = wf.nominal_obligations(def_id, substs);
wf.out.extend(obligations);
......
......@@ -1605,7 +1605,7 @@ fn conv_object_ty_poly_trait_ref(
.map(|item| item.def_id),
);
}
ty::PredicateKind::Projection(pred) => {
&ty::PredicateKind::Projection(pred) => {
// A `Self` within the original bound will be substituted with a
// `trait_object_dummy_self`, so check for that.
let references_self =
......
......@@ -597,7 +597,7 @@ fn coerce_unsized(&self, mut source: Ty<'tcx>, mut target: Ty<'tcx>) -> CoerceRe
let obligation = queue.remove(0);
debug!("coerce_unsized resolve step: {:?}", obligation);
let trait_pred = match obligation.predicate.kind() {
ty::PredicateKind::Trait(trait_pred, _)
&ty::PredicateKind::Trait(trait_pred, _)
if traits.contains(&trait_pred.def_id()) =>
{
if unsize_did == trait_pred.def_id() {
......
......@@ -232,10 +232,10 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
let mut relator: SimpleEqRelation<'tcx> = SimpleEqRelation::new(tcx, self_param_env);
match (predicate.kind(), p.kind()) {
(ty::PredicateKind::Trait(a, _), ty::PredicateKind::Trait(b, _)) => {
relator.relate(&a, &b).is_ok()
relator.relate(a, b).is_ok()
}
(ty::PredicateKind::Projection(a), ty::PredicateKind::Projection(b)) => {
relator.relate(&a, &b).is_ok()
relator.relate(a, b).is_ok()
}
_ => predicate == p,
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册