2015-09-14 11:53:53 +02:00
|
|
|
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2018-04-09 09:38:00 +02:00
|
|
|
use rustc_data_structures::accumulate_vec::AccumulateVec;
|
2016-03-22 16:30:57 +01:00
|
|
|
use traits;
|
|
|
|
use traits::project::Normalized;
|
2017-11-23 22:03:47 +01:00
|
|
|
use ty::{self, Lift, TyCtxt};
|
2016-03-22 16:30:57 +01:00
|
|
|
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
|
2015-09-14 11:53:53 +02:00
|
|
|
|
|
|
|
use std::fmt;
|
2016-07-28 17:27:11 +02:00
|
|
|
use std::rc::Rc;
|
2015-09-14 11:53:53 +02:00
|
|
|
|
2016-03-22 16:30:57 +01:00
|
|
|
// structural impls for the structs in traits
|
2015-09-14 11:53:53 +02:00
|
|
|
|
|
|
|
impl<'tcx, T: fmt::Debug> fmt::Debug for Normalized<'tcx, T> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "Normalized({:?},{:?})",
|
|
|
|
self.value,
|
|
|
|
self.obligations)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, O: fmt::Debug> fmt::Debug for traits::Obligation<'tcx, O> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-11-23 22:03:47 +01:00
|
|
|
if ty::tls::with(|tcx| tcx.sess.verbose()) {
|
|
|
|
write!(f, "Obligation(predicate={:?},cause={:?},depth={})",
|
|
|
|
self.predicate,
|
|
|
|
self.cause,
|
|
|
|
self.recursion_depth)
|
|
|
|
} else {
|
|
|
|
write!(f, "Obligation(predicate={:?},depth={})",
|
|
|
|
self.predicate,
|
|
|
|
self.recursion_depth)
|
|
|
|
}
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::Vtable<'tcx, N> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
super::VtableImpl(ref v) =>
|
|
|
|
write!(f, "{:?}", v),
|
|
|
|
|
2017-10-09 18:59:20 +02:00
|
|
|
super::VtableAutoImpl(ref t) =>
|
2015-09-14 11:53:53 +02:00
|
|
|
write!(f, "{:?}", t),
|
|
|
|
|
|
|
|
super::VtableClosure(ref d) =>
|
|
|
|
write!(f, "{:?}", d),
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
super::VtableGenerator(ref d) =>
|
|
|
|
write!(f, "{:?}", d),
|
|
|
|
|
2015-09-14 11:53:53 +02:00
|
|
|
super::VtableFnPointer(ref d) =>
|
|
|
|
write!(f, "VtableFnPointer({:?})", d),
|
|
|
|
|
|
|
|
super::VtableObject(ref d) =>
|
|
|
|
write!(f, "{:?}", d),
|
|
|
|
|
|
|
|
super::VtableParam(ref n) =>
|
|
|
|
write!(f, "VtableParam({:?})", n),
|
|
|
|
|
|
|
|
super::VtableBuiltin(ref d) =>
|
|
|
|
write!(f, "{:?}", d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableImplData<'tcx, N> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableImpl(impl_def_id={:?}, substs={:?}, nested={:?})",
|
|
|
|
self.impl_def_id,
|
|
|
|
self.substs,
|
|
|
|
self.nested)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-26 14:34:03 +01:00
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableGeneratorData<'tcx, N> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2018-05-02 13:14:30 +02:00
|
|
|
write!(f, "VtableGenerator(generator_def_id={:?}, substs={:?}, nested={:?})",
|
|
|
|
self.generator_def_id,
|
2016-12-26 14:34:03 +01:00
|
|
|
self.substs,
|
|
|
|
self.nested)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 11:53:53 +02:00
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableClosureData<'tcx, N> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableClosure(closure_def_id={:?}, substs={:?}, nested={:?})",
|
|
|
|
self.closure_def_id,
|
|
|
|
self.substs,
|
|
|
|
self.nested)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableBuiltinData<N> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableBuiltin(nested={:?})", self.nested)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-09 18:59:20 +02:00
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableAutoImplData<N> {
|
2015-09-14 11:53:53 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-10-09 18:59:20 +02:00
|
|
|
write!(f, "VtableAutoImplData(trait_def_id={:?}, nested={:?})",
|
2015-09-14 11:53:53 +02:00
|
|
|
self.trait_def_id,
|
|
|
|
self.nested)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-11 23:40:24 +02:00
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableObjectData<'tcx, N> {
|
2015-09-14 11:53:53 +02:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2016-05-11 23:40:24 +02:00
|
|
|
write!(f, "VtableObject(upcast={:?}, vtable_base={}, nested={:?})",
|
2015-09-14 11:53:53 +02:00
|
|
|
self.upcast_trait_ref,
|
2016-05-11 23:40:24 +02:00
|
|
|
self.vtable_base,
|
|
|
|
self.nested)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx, N: fmt::Debug> fmt::Debug for traits::VtableFnPointerData<'tcx, N> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableFnPointer(fn_ty={:?}, nested={:?})",
|
|
|
|
self.fn_ty,
|
|
|
|
self.nested)
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Debug for traits::FulfillmentError<'tcx> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "FulfillmentError({:?},{:?})",
|
|
|
|
self.obligation,
|
|
|
|
self.code)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
|
|
|
super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
|
|
|
|
super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
|
2017-04-11 23:12:00 +02:00
|
|
|
super::CodeSubtypeError(ref a, ref b) =>
|
|
|
|
write!(f, "CodeSubtypeError({:?}, {:?})", a, b),
|
2015-09-14 11:53:53 +02:00
|
|
|
super::CodeAmbiguity => write!(f, "Ambiguity")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Debug for traits::MismatchedProjectionTypes<'tcx> {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "MismatchedProjectionTypes({:?})", self.err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 05:00:23 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Lift implementations
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> {
|
|
|
|
type Lifted = traits::SelectionError<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
|
|
|
super::Unimplemented => Some(super::Unimplemented),
|
|
|
|
super::OutputTypeParameterMismatch(a, b, ref err) => {
|
|
|
|
tcx.lift(&(a, b)).and_then(|(a, b)| {
|
|
|
|
tcx.lift(err).map(|err| {
|
|
|
|
super::OutputTypeParameterMismatch(a, b, err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
super::TraitNotObjectSafe(def_id) => {
|
|
|
|
Some(super::TraitNotObjectSafe(def_id))
|
|
|
|
}
|
2017-08-07 07:08:53 +02:00
|
|
|
super::ConstEvalFailure(ref err) => {
|
|
|
|
tcx.lift(err).map(super::ConstEvalFailure)
|
|
|
|
}
|
2018-04-19 09:49:21 +02:00
|
|
|
super::Overflow => bug!() // FIXME: ape ConstEvalFailure?
|
2016-04-29 05:00:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-28 17:27:11 +02:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
|
|
|
|
type Lifted = traits::ObligationCauseCode<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match *self {
|
2017-03-17 14:37:18 +01:00
|
|
|
super::ReturnNoExpression => Some(super::ReturnNoExpression),
|
2016-07-28 17:27:11 +02:00
|
|
|
super::MiscObligation => Some(super::MiscObligation),
|
|
|
|
super::SliceOrArrayElem => Some(super::SliceOrArrayElem),
|
|
|
|
super::TupleElem => Some(super::TupleElem),
|
|
|
|
super::ProjectionWf(proj) => tcx.lift(&proj).map(super::ProjectionWf),
|
|
|
|
super::ItemObligation(def_id) => Some(super::ItemObligation(def_id)),
|
|
|
|
super::ReferenceOutlivesReferent(ty) => {
|
|
|
|
tcx.lift(&ty).map(super::ReferenceOutlivesReferent)
|
|
|
|
}
|
2016-10-14 16:09:59 +02:00
|
|
|
super::ObjectTypeBound(ty, r) => {
|
|
|
|
tcx.lift(&ty).and_then(|ty| {
|
|
|
|
tcx.lift(&r).and_then(|r| {
|
|
|
|
Some(super::ObjectTypeBound(ty, r))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2016-07-28 17:27:11 +02:00
|
|
|
super::ObjectCastObligation(ty) => {
|
|
|
|
tcx.lift(&ty).map(super::ObjectCastObligation)
|
|
|
|
}
|
|
|
|
super::AssignmentLhsSized => Some(super::AssignmentLhsSized),
|
2017-06-08 07:46:46 +02:00
|
|
|
super::TupleInitializerSized => Some(super::TupleInitializerSized),
|
2016-07-28 17:27:11 +02:00
|
|
|
super::StructInitializerSized => Some(super::StructInitializerSized),
|
|
|
|
super::VariableType(id) => Some(super::VariableType(id)),
|
2017-06-24 09:57:39 +02:00
|
|
|
super::ReturnType(id) => Some(super::ReturnType(id)),
|
|
|
|
super::SizedReturnType => Some(super::SizedReturnType),
|
2018-01-28 20:23:49 +01:00
|
|
|
super::SizedYieldType => Some(super::SizedYieldType),
|
2016-07-28 17:27:11 +02:00
|
|
|
super::RepeatVec => Some(super::RepeatVec),
|
2017-08-16 18:45:54 +02:00
|
|
|
super::FieldSized(item) => Some(super::FieldSized(item)),
|
2016-07-28 17:27:11 +02:00
|
|
|
super::ConstSized => Some(super::ConstSized),
|
|
|
|
super::SharedStatic => Some(super::SharedStatic),
|
|
|
|
super::BuiltinDerivedObligation(ref cause) => {
|
|
|
|
tcx.lift(cause).map(super::BuiltinDerivedObligation)
|
|
|
|
}
|
|
|
|
super::ImplDerivedObligation(ref cause) => {
|
|
|
|
tcx.lift(cause).map(super::ImplDerivedObligation)
|
|
|
|
}
|
2016-10-05 16:17:14 +02:00
|
|
|
super::CompareImplMethodObligation { item_name,
|
|
|
|
impl_item_def_id,
|
2017-11-01 19:23:30 +01:00
|
|
|
trait_item_def_id } => {
|
2016-10-05 16:17:14 +02:00
|
|
|
Some(super::CompareImplMethodObligation {
|
2017-07-03 20:19:51 +02:00
|
|
|
item_name,
|
|
|
|
impl_item_def_id,
|
|
|
|
trait_item_def_id,
|
2016-10-05 16:17:14 +02:00
|
|
|
})
|
2016-07-28 17:27:11 +02:00
|
|
|
}
|
2017-06-24 09:57:39 +02:00
|
|
|
super::ExprAssignable => Some(super::ExprAssignable),
|
2016-11-07 19:25:06 +01:00
|
|
|
super::MatchExpressionArm { arm_span, source } => {
|
2017-07-03 20:19:51 +02:00
|
|
|
Some(super::MatchExpressionArm { arm_span,
|
2016-11-07 19:25:06 +01:00
|
|
|
source: source })
|
|
|
|
}
|
2017-06-24 09:57:39 +02:00
|
|
|
super::IfExpression => Some(super::IfExpression),
|
|
|
|
super::IfExpressionWithNoElse => Some(super::IfExpressionWithNoElse),
|
|
|
|
super::MainFunctionType => Some(super::MainFunctionType),
|
|
|
|
super::StartFunctionType => Some(super::StartFunctionType),
|
|
|
|
super::IntrinsicType => Some(super::IntrinsicType),
|
|
|
|
super::MethodReceiver => Some(super::MethodReceiver),
|
|
|
|
super::BlockTailExpression(id) => Some(super::BlockTailExpression(id)),
|
2018-05-06 23:50:35 +02:00
|
|
|
super::TrivialBound => Some(super::TrivialBound),
|
2016-07-28 17:27:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for traits::DerivedObligationCause<'a> {
|
|
|
|
type Lifted = traits::DerivedObligationCause<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.parent_trait_ref).and_then(|trait_ref| {
|
|
|
|
tcx.lift(&*self.parent_code).map(|code| {
|
|
|
|
traits::DerivedObligationCause {
|
|
|
|
parent_trait_ref: trait_ref,
|
|
|
|
parent_code: Rc::new(code)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCause<'a> {
|
|
|
|
type Lifted = traits::ObligationCause<'tcx>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
tcx.lift(&self.code).map(|code| {
|
|
|
|
traits::ObligationCause {
|
|
|
|
span: self.span,
|
|
|
|
body_id: self.body_id,
|
2017-07-03 20:19:51 +02:00
|
|
|
code,
|
2016-07-28 17:27:11 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-08 15:10:16 +02:00
|
|
|
// For codegen only.
|
2016-05-11 03:14:41 +02:00
|
|
|
impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
|
|
|
|
type Lifted = traits::Vtable<'tcx, ()>;
|
|
|
|
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
|
|
|
|
match self.clone() {
|
|
|
|
traits::VtableImpl(traits::VtableImplData {
|
|
|
|
impl_def_id,
|
|
|
|
substs,
|
|
|
|
nested
|
|
|
|
}) => {
|
|
|
|
tcx.lift(&substs).map(|substs| {
|
|
|
|
traits::VtableImpl(traits::VtableImplData {
|
2017-07-03 20:19:51 +02:00
|
|
|
impl_def_id,
|
|
|
|
substs,
|
|
|
|
nested,
|
2016-05-11 03:14:41 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2017-10-09 18:59:20 +02:00
|
|
|
traits::VtableAutoImpl(t) => Some(traits::VtableAutoImpl(t)),
|
2016-12-26 14:34:03 +01:00
|
|
|
traits::VtableGenerator(traits::VtableGeneratorData {
|
2018-05-02 13:14:30 +02:00
|
|
|
generator_def_id,
|
2016-12-26 14:34:03 +01:00
|
|
|
substs,
|
|
|
|
nested
|
|
|
|
}) => {
|
|
|
|
tcx.lift(&substs).map(|substs| {
|
|
|
|
traits::VtableGenerator(traits::VtableGeneratorData {
|
2018-05-02 13:14:30 +02:00
|
|
|
generator_def_id: generator_def_id,
|
2016-12-26 14:34:03 +01:00
|
|
|
substs: substs,
|
|
|
|
nested: nested
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2016-05-11 03:14:41 +02:00
|
|
|
traits::VtableClosure(traits::VtableClosureData {
|
|
|
|
closure_def_id,
|
|
|
|
substs,
|
|
|
|
nested
|
|
|
|
}) => {
|
|
|
|
tcx.lift(&substs).map(|substs| {
|
|
|
|
traits::VtableClosure(traits::VtableClosureData {
|
2017-07-03 20:19:51 +02:00
|
|
|
closure_def_id,
|
|
|
|
substs,
|
|
|
|
nested,
|
2016-05-11 03:14:41 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2016-05-11 23:40:24 +02:00
|
|
|
traits::VtableFnPointer(traits::VtableFnPointerData { fn_ty, nested }) => {
|
|
|
|
tcx.lift(&fn_ty).map(|fn_ty| {
|
|
|
|
traits::VtableFnPointer(traits::VtableFnPointerData {
|
2017-07-03 20:19:51 +02:00
|
|
|
fn_ty,
|
|
|
|
nested,
|
2016-05-11 23:40:24 +02:00
|
|
|
})
|
|
|
|
})
|
2016-05-11 03:14:41 +02:00
|
|
|
}
|
|
|
|
traits::VtableParam(n) => Some(traits::VtableParam(n)),
|
2017-08-07 13:22:48 +02:00
|
|
|
traits::VtableBuiltin(n) => Some(traits::VtableBuiltin(n)),
|
2016-05-11 03:14:41 +02:00
|
|
|
traits::VtableObject(traits::VtableObjectData {
|
|
|
|
upcast_trait_ref,
|
2016-05-11 23:40:24 +02:00
|
|
|
vtable_base,
|
|
|
|
nested
|
2016-05-11 03:14:41 +02:00
|
|
|
}) => {
|
|
|
|
tcx.lift(&upcast_trait_ref).map(|trait_ref| {
|
|
|
|
traits::VtableObject(traits::VtableObjectData {
|
|
|
|
upcast_trait_ref: trait_ref,
|
2017-07-03 20:19:51 +02:00
|
|
|
vtable_base,
|
|
|
|
nested,
|
2016-05-11 03:14:41 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 05:00:23 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// TypeFoldable implementations.
|
|
|
|
|
2015-09-14 11:53:53 +02:00
|
|
|
impl<'tcx, O: TypeFoldable<'tcx>> TypeFoldable<'tcx> for traits::Obligation<'tcx, O>
|
|
|
|
{
|
2016-04-29 05:00:23 +02:00
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
2015-09-14 11:53:53 +02:00
|
|
|
traits::Obligation {
|
|
|
|
cause: self.cause.clone(),
|
|
|
|
recursion_depth: self.recursion_depth,
|
|
|
|
predicate: self.predicate.fold_with(folder),
|
2017-05-23 10:19:47 +02:00
|
|
|
param_env: self.param_env.fold_with(folder),
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-11-18 10:38:57 +01:00
|
|
|
|
2016-01-06 03:01:28 +01:00
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
2015-11-18 10:38:57 +01:00
|
|
|
self.predicate.visit_with(visitor)
|
|
|
|
}
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableImplData<'tcx, N> {
|
|
|
|
impl_def_id, substs, nested
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableGeneratorData<'tcx, N> {
|
2018-05-02 13:14:30 +02:00
|
|
|
generator_def_id, substs, nested
|
2018-02-09 16:34:23 +01:00
|
|
|
} where N: TypeFoldable<'tcx>
|
2016-12-26 14:34:03 +01:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableClosureData<'tcx, N> {
|
|
|
|
closure_def_id, substs, nested
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableAutoImplData<N> {
|
|
|
|
trait_def_id, nested
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableBuiltinData<N> {
|
|
|
|
nested
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableObjectData<'tcx, N> {
|
|
|
|
upcast_trait_ref, vtable_base, nested
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2016-05-11 23:40:24 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::VtableFnPointerData<'tcx, N> {
|
|
|
|
fn_ty,
|
|
|
|
nested
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2015-09-14 23:47:14 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
EnumTypeFoldableImpl! {
|
|
|
|
impl<'tcx, N> TypeFoldable<'tcx> for traits::Vtable<'tcx, N> {
|
|
|
|
(traits::VtableImpl)(a),
|
|
|
|
(traits::VtableAutoImpl)(a),
|
|
|
|
(traits::VtableGenerator)(a),
|
|
|
|
(traits::VtableClosure)(a),
|
|
|
|
(traits::VtableFnPointer)(a),
|
|
|
|
(traits::VtableParam)(a),
|
|
|
|
(traits::VtableBuiltin)(a),
|
|
|
|
(traits::VtableObject)(a),
|
|
|
|
} where N: TypeFoldable<'tcx>
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 16:34:23 +01:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx, T> TypeFoldable<'tcx> for Normalized<'tcx, T> {
|
|
|
|
value,
|
|
|
|
obligations
|
|
|
|
} where T: TypeFoldable<'tcx>
|
2015-09-14 11:53:53 +02:00
|
|
|
}
|
2018-03-10 12:44:33 +01:00
|
|
|
|
|
|
|
impl<'tcx> fmt::Display for traits::WhereClauseAtom<'tcx> {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use traits::WhereClauseAtom::*;
|
2018-03-14 13:38:03 +01:00
|
|
|
|
|
|
|
match self {
|
|
|
|
Implemented(trait_ref) => write!(fmt, "Implemented({})", trait_ref),
|
|
|
|
ProjectionEq(projection) => write!(fmt, "ProjectionEq({})", projection),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Display for traits::DomainGoal<'tcx> {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use traits::DomainGoal::*;
|
|
|
|
use traits::WhereClauseAtom::*;
|
2018-03-14 13:38:03 +01:00
|
|
|
|
|
|
|
match self {
|
2018-03-10 12:44:33 +01:00
|
|
|
Holds(wc) => write!(fmt, "{}", wc),
|
2018-03-14 13:38:03 +01:00
|
|
|
WellFormed(Implemented(trait_ref)) => write!(fmt, "WellFormed({})", trait_ref),
|
|
|
|
WellFormed(ProjectionEq(projection)) => write!(fmt, "WellFormed({})", projection),
|
|
|
|
FromEnv(Implemented(trait_ref)) => write!(fmt, "FromEnv({})", trait_ref),
|
|
|
|
FromEnv(ProjectionEq(projection)) => write!(fmt, "FromEnv({})", projection),
|
|
|
|
WellFormedTy(ty) => write!(fmt, "WellFormed({})", ty),
|
2018-04-03 17:53:13 +02:00
|
|
|
Normalize(projection) => write!(fmt, "Normalize({})", projection),
|
2018-03-14 13:38:03 +01:00
|
|
|
FromEnvTy(ty) => write!(fmt, "FromEnv({})", ty),
|
|
|
|
RegionOutlives(predicate) => write!(fmt, "RegionOutlives({})", predicate),
|
|
|
|
TypeOutlives(predicate) => write!(fmt, "TypeOutlives({})", predicate),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for traits::QuantifierKind {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use traits::QuantifierKind::*;
|
2018-03-14 13:38:03 +01:00
|
|
|
|
|
|
|
match self {
|
2018-03-10 12:44:33 +01:00
|
|
|
Universal => write!(fmt, "forall"),
|
|
|
|
Existential => write!(fmt, "exists"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> fmt::Display for traits::Goal<'tcx> {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use traits::Goal::*;
|
2018-03-14 13:38:03 +01:00
|
|
|
|
|
|
|
match self {
|
|
|
|
Implies(hypotheses, goal) => {
|
2018-03-10 12:44:33 +01:00
|
|
|
write!(fmt, "if (")?;
|
|
|
|
for (index, hyp) in hypotheses.iter().enumerate() {
|
|
|
|
if index > 0 {
|
|
|
|
write!(fmt, ", ")?;
|
|
|
|
}
|
|
|
|
write!(fmt, "{}", hyp)?;
|
|
|
|
}
|
|
|
|
write!(fmt, ") {{ {} }}", goal)
|
|
|
|
}
|
2018-03-14 13:38:03 +01:00
|
|
|
And(goal1, goal2) => write!(fmt, "({} && {})", goal1, goal2),
|
|
|
|
Not(goal) => write!(fmt, "not {{ {} }}", goal),
|
|
|
|
DomainGoal(goal) => write!(fmt, "{}", goal),
|
|
|
|
Quantified(qkind, goal) => {
|
2018-03-10 12:44:33 +01:00
|
|
|
// FIXME: appropriate binder names
|
|
|
|
write!(fmt, "{}<> {{ {} }}", qkind, goal.skip_binder())
|
|
|
|
}
|
2018-03-23 09:58:18 +01:00
|
|
|
CannotProve => write!(fmt, "CannotProve"),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:13:08 +02:00
|
|
|
impl<'tcx> fmt::Display for traits::ProgramClause<'tcx> {
|
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let traits::ProgramClause { goal, hypotheses } = self;
|
|
|
|
write!(fmt, "{}", goal)?;
|
|
|
|
if !hypotheses.is_empty() {
|
|
|
|
write!(fmt, " :- ")?;
|
|
|
|
for (index, condition) in hypotheses.iter().enumerate() {
|
|
|
|
if index > 0 {
|
|
|
|
write!(fmt, ", ")?;
|
|
|
|
}
|
|
|
|
write!(fmt, "{}", condition)?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write!(fmt, ".")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:38:03 +01:00
|
|
|
impl<'tcx> fmt::Display for traits::Clause<'tcx> {
|
2018-03-10 12:44:33 +01:00
|
|
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
2018-03-14 13:38:03 +01:00
|
|
|
use traits::Clause::*;
|
|
|
|
|
|
|
|
match self {
|
2018-03-28 14:13:08 +02:00
|
|
|
Implies(clause) => write!(fmt, "{}", clause),
|
2018-03-14 13:38:03 +01:00
|
|
|
ForAll(clause) => {
|
|
|
|
// FIXME: appropriate binder names
|
|
|
|
write!(fmt, "forall<> {{ {} }}", clause.skip_binder())
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:38:03 +01:00
|
|
|
EnumTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for traits::WhereClauseAtom<'tcx> {
|
|
|
|
(traits::WhereClauseAtom::Implemented)(trait_ref),
|
|
|
|
(traits::WhereClauseAtom::ProjectionEq)(projection),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:38:03 +01:00
|
|
|
EnumTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for traits::DomainGoal<'tcx> {
|
|
|
|
(traits::DomainGoal::Holds)(wc),
|
|
|
|
(traits::DomainGoal::WellFormed)(wc),
|
|
|
|
(traits::DomainGoal::FromEnv)(wc),
|
|
|
|
(traits::DomainGoal::WellFormedTy)(ty),
|
2018-04-03 17:53:13 +02:00
|
|
|
(traits::DomainGoal::Normalize)(projection),
|
2018-03-14 13:38:03 +01:00
|
|
|
(traits::DomainGoal::FromEnvTy)(ty),
|
|
|
|
(traits::DomainGoal::RegionOutlives)(predicate),
|
|
|
|
(traits::DomainGoal::TypeOutlives)(predicate),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:38:03 +01:00
|
|
|
CloneTypeFoldableImpls! {
|
|
|
|
traits::QuantifierKind,
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
|
2018-03-14 13:38:03 +01:00
|
|
|
EnumTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for traits::Goal<'tcx> {
|
|
|
|
(traits::Goal::Implies)(hypotheses, goal),
|
|
|
|
(traits::Goal::And)(goal1, goal2),
|
|
|
|
(traits::Goal::Not)(goal),
|
|
|
|
(traits::Goal::DomainGoal)(domain_goal),
|
|
|
|
(traits::Goal::Quantified)(qkind, goal),
|
2018-03-23 09:58:18 +01:00
|
|
|
(traits::Goal::CannotProve),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
2018-03-14 13:38:03 +01:00
|
|
|
}
|
2018-03-10 12:44:33 +01:00
|
|
|
|
2018-04-09 09:38:00 +02:00
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<traits::Goal<'tcx>> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
let v = self.iter().map(|t| t.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
|
|
|
|
folder.tcx().intern_goals(&v)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.iter().any(|t| t.visit_with(visitor))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx traits::Goal<'tcx> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
let v = (**self).fold_with(folder);
|
|
|
|
folder.tcx().mk_goal(v)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
(**self).visit_with(visitor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 14:13:08 +02:00
|
|
|
BraceStructTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for traits::ProgramClause<'tcx> {
|
|
|
|
goal,
|
|
|
|
hypotheses
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-14 13:38:03 +01:00
|
|
|
EnumTypeFoldableImpl! {
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for traits::Clause<'tcx> {
|
2018-03-28 14:13:08 +02:00
|
|
|
(traits::Clause::Implies)(clause),
|
2018-03-14 13:38:03 +01:00
|
|
|
(traits::Clause::ForAll)(clause),
|
2018-03-10 12:44:33 +01:00
|
|
|
}
|
|
|
|
}
|
2018-04-09 09:38:00 +02:00
|
|
|
|
|
|
|
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::Slice<traits::Clause<'tcx>> {
|
|
|
|
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
|
|
|
|
let v = self.iter().map(|t| t.fold_with(folder)).collect::<AccumulateVec<[_; 8]>>();
|
|
|
|
folder.tcx().intern_clauses(&v)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
|
|
|
|
self.iter().any(|t| t.visit_with(visitor))
|
|
|
|
}
|
|
|
|
}
|