2014-09-12 09:53:35 -05:00
|
|
|
// Copyright 2014 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.
|
|
|
|
|
2014-12-29 15:32:12 -06:00
|
|
|
use middle::subst::{Substs, VecPerParamSpace};
|
2014-11-25 15:59:02 -06:00
|
|
|
use middle::infer::InferCtxt;
|
2015-01-03 21:42:21 -06:00
|
|
|
use middle::ty::{self, Ty, AsPredicate, ToPolyTraitRef};
|
2014-09-18 10:08:04 -05:00
|
|
|
use std::collections::HashSet;
|
2014-09-12 09:53:35 -05:00
|
|
|
use std::fmt;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::codemap::Span;
|
2014-11-08 05:59:10 -06:00
|
|
|
use util::common::ErrorReported;
|
2014-09-12 09:53:35 -05:00
|
|
|
use util::ppaux::Repr;
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
use super::{Obligation, ObligationCause, PredicateObligation,
|
2014-12-27 03:22:29 -06:00
|
|
|
VtableImpl, VtableParam, VtableImplData};
|
2014-09-12 09:53:35 -05:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2014-12-11 03:35:51 -06:00
|
|
|
// `Elaboration` iterator
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2014-09-12 09:53:35 -05:00
|
|
|
|
2014-12-11 03:35:51 -06:00
|
|
|
/// "Elaboration" is the process of identifying all the predicates that
|
|
|
|
/// are implied by a source predicate. Currently this basically means
|
|
|
|
/// walking the "supertraits" and other similar assumptions. For
|
|
|
|
/// example, if we know that `T : Ord`, the elaborator would deduce
|
|
|
|
/// that `T : PartialOrd` holds as well. Similarly, if we have `trait
|
|
|
|
/// Foo : 'static`, and we know that `T : Foo`, then we know that `T :
|
|
|
|
/// 'static`.
|
2014-12-07 10:10:48 -06:00
|
|
|
pub struct Elaborator<'cx, 'tcx:'cx> {
|
2014-09-12 09:53:35 -05:00
|
|
|
tcx: &'cx ty::ctxt<'tcx>,
|
2014-12-07 10:10:48 -06:00
|
|
|
stack: Vec<StackEntry<'tcx>>,
|
|
|
|
visited: HashSet<ty::Predicate<'tcx>>,
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
struct StackEntry<'tcx> {
|
2014-09-12 09:53:35 -05:00
|
|
|
position: uint,
|
2014-12-07 10:10:48 -06:00
|
|
|
predicates: Vec<ty::Predicate<'tcx>>,
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
pub fn elaborate_trait_ref<'cx, 'tcx>(
|
|
|
|
tcx: &'cx ty::ctxt<'tcx>,
|
2014-12-17 13:16:28 -06:00
|
|
|
trait_ref: ty::PolyTraitRef<'tcx>)
|
2014-12-07 10:10:48 -06:00
|
|
|
-> Elaborator<'cx, 'tcx>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
2014-12-17 13:16:28 -06:00
|
|
|
elaborate_predicates(tcx, vec![trait_ref.as_predicate()])
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
pub fn elaborate_trait_refs<'cx, 'tcx>(
|
|
|
|
tcx: &'cx ty::ctxt<'tcx>,
|
2014-12-17 13:16:28 -06:00
|
|
|
trait_refs: &[ty::PolyTraitRef<'tcx>])
|
2014-12-07 10:10:48 -06:00
|
|
|
-> Elaborator<'cx, 'tcx>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
2014-12-07 10:10:48 -06:00
|
|
|
let predicates = trait_refs.iter()
|
2014-12-17 13:16:28 -06:00
|
|
|
.map(|trait_ref| trait_ref.as_predicate())
|
2014-12-07 10:10:48 -06:00
|
|
|
.collect();
|
|
|
|
elaborate_predicates(tcx, predicates)
|
|
|
|
}
|
2014-09-18 10:08:04 -05:00
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
pub fn elaborate_predicates<'cx, 'tcx>(
|
|
|
|
tcx: &'cx ty::ctxt<'tcx>,
|
|
|
|
predicates: Vec<ty::Predicate<'tcx>>)
|
|
|
|
-> Elaborator<'cx, 'tcx>
|
|
|
|
{
|
|
|
|
let visited: HashSet<ty::Predicate<'tcx>> =
|
|
|
|
predicates.iter()
|
|
|
|
.map(|b| (*b).clone())
|
|
|
|
.collect();
|
2014-09-18 10:08:04 -05:00
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
let entry = StackEntry { position: 0, predicates: predicates };
|
|
|
|
Elaborator { tcx: tcx, stack: vec![entry], visited: visited }
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
|
2014-12-27 03:22:29 -06:00
|
|
|
pub fn filter_to_traits(self) -> Supertraits<'cx, 'tcx> {
|
|
|
|
Supertraits { elaborator: self }
|
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
fn push(&mut self, predicate: &ty::Predicate<'tcx>) {
|
|
|
|
match *predicate {
|
2014-12-17 13:16:28 -06:00
|
|
|
ty::Predicate::Trait(ref data) => {
|
2014-12-07 10:10:48 -06:00
|
|
|
let mut predicates =
|
2014-12-17 13:16:28 -06:00
|
|
|
ty::predicates_for_trait_ref(self.tcx,
|
|
|
|
&data.to_poly_trait_ref());
|
2014-12-07 10:10:48 -06:00
|
|
|
|
|
|
|
// Only keep those bounds that we haven't already
|
|
|
|
// seen. This is necessary to prevent infinite
|
|
|
|
// recursion in some cases. One common case is when
|
2015-01-04 22:20:17 -06:00
|
|
|
// people define `trait Sized: Sized { }` rather than `trait
|
|
|
|
// Sized { }`.
|
2014-12-17 13:16:28 -06:00
|
|
|
predicates.retain(|r| self.visited.insert(r.clone()));
|
2014-12-07 10:10:48 -06:00
|
|
|
|
|
|
|
self.stack.push(StackEntry { position: 0,
|
|
|
|
predicates: predicates });
|
|
|
|
}
|
|
|
|
ty::Predicate::Equate(..) => {
|
2014-12-17 13:16:28 -06:00
|
|
|
// Currently, we do not "elaborate" predicates like
|
|
|
|
// `X == Y`, though conceivably we might. For example,
|
|
|
|
// `&X == &Y` implies that `X == Y`.
|
|
|
|
}
|
|
|
|
ty::Predicate::Projection(..) => {
|
|
|
|
// Nothing to elaborate in a projection predicate.
|
2014-12-07 10:10:48 -06:00
|
|
|
}
|
|
|
|
ty::Predicate::RegionOutlives(..) |
|
|
|
|
ty::Predicate::TypeOutlives(..) => {
|
|
|
|
// Currently, we do not "elaborate" predicates like
|
|
|
|
// `'a : 'b` or `T : 'a`. We could conceivably do
|
|
|
|
// more here. For example,
|
|
|
|
//
|
|
|
|
// &'a int : 'b
|
|
|
|
//
|
|
|
|
// implies that
|
|
|
|
//
|
|
|
|
// 'a : 'b
|
|
|
|
//
|
|
|
|
// and we could get even more if we took WF
|
|
|
|
// constraints into account. For example,
|
|
|
|
//
|
|
|
|
// &'a &'b int : 'c
|
|
|
|
//
|
|
|
|
// implies that
|
|
|
|
//
|
|
|
|
// 'b : 'a
|
|
|
|
// 'a : 'c
|
2014-12-06 00:30:41 -06:00
|
|
|
}
|
2014-09-18 10:08:04 -05:00
|
|
|
}
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-01 22:26:38 -06:00
|
|
|
impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
|
|
|
|
type Item = ty::Predicate<'tcx>;
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
fn next(&mut self) -> Option<ty::Predicate<'tcx>> {
|
2014-09-12 09:53:35 -05:00
|
|
|
loop {
|
|
|
|
// Extract next item from top-most stack frame, if any.
|
2014-12-07 10:10:48 -06:00
|
|
|
let next_predicate = match self.stack.last_mut() {
|
2014-09-12 09:53:35 -05:00
|
|
|
None => {
|
|
|
|
// No more stack frames. Done.
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
Some(entry) => {
|
|
|
|
let p = entry.position;
|
2014-12-07 10:10:48 -06:00
|
|
|
if p < entry.predicates.len() {
|
|
|
|
// Still more predicates left in the top stack frame.
|
2014-09-12 09:53:35 -05:00
|
|
|
entry.position += 1;
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
let next_predicate =
|
|
|
|
entry.predicates[p].clone();
|
|
|
|
|
|
|
|
Some(next_predicate)
|
2014-09-12 09:53:35 -05:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
match next_predicate {
|
|
|
|
Some(next_predicate) => {
|
|
|
|
self.push(&next_predicate);
|
|
|
|
return Some(next_predicate);
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
None => {
|
|
|
|
// Top stack frame is exhausted, pop it.
|
|
|
|
self.stack.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Supertrait iterator
|
2014-12-11 03:35:51 -06:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2014-12-07 10:10:48 -06:00
|
|
|
|
2014-12-11 03:35:51 -06:00
|
|
|
/// A filter around the `Elaborator` that just yields up supertrait references,
|
|
|
|
/// not other kinds of predicates.
|
2014-12-07 10:10:48 -06:00
|
|
|
pub struct Supertraits<'cx, 'tcx:'cx> {
|
|
|
|
elaborator: Elaborator<'cx, 'tcx>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
|
2014-12-17 13:16:28 -06:00
|
|
|
trait_ref: ty::PolyTraitRef<'tcx>)
|
2014-12-07 10:10:48 -06:00
|
|
|
-> Supertraits<'cx, 'tcx>
|
|
|
|
{
|
2014-12-27 03:22:29 -06:00
|
|
|
elaborate_trait_ref(tcx, trait_ref).filter_to_traits()
|
2014-12-07 10:10:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
|
2014-12-17 13:16:28 -06:00
|
|
|
bounds: &[ty::PolyTraitRef<'tcx>])
|
2014-12-07 10:10:48 -06:00
|
|
|
-> Supertraits<'cx, 'tcx>
|
|
|
|
{
|
2014-12-27 03:22:29 -06:00
|
|
|
elaborate_trait_refs(tcx, bounds).filter_to_traits()
|
2014-12-07 10:10:48 -06:00
|
|
|
}
|
|
|
|
|
2015-01-01 22:26:38 -06:00
|
|
|
impl<'cx, 'tcx> Iterator for Supertraits<'cx, 'tcx> {
|
|
|
|
type Item = ty::PolyTraitRef<'tcx>;
|
|
|
|
|
2014-12-17 13:16:28 -06:00
|
|
|
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
|
2014-12-07 10:10:48 -06:00
|
|
|
loop {
|
|
|
|
match self.elaborator.next() {
|
|
|
|
None => {
|
|
|
|
return None;
|
|
|
|
}
|
2014-12-17 13:16:28 -06:00
|
|
|
Some(ty::Predicate::Trait(data)) => {
|
|
|
|
return Some(data.to_poly_trait_ref());
|
2014-12-07 10:10:48 -06:00
|
|
|
}
|
2014-12-17 13:16:28 -06:00
|
|
|
Some(_) => {
|
2014-12-07 10:10:48 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 03:35:51 -06:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Other
|
2014-12-07 10:10:48 -06:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-09-12 09:53:35 -05:00
|
|
|
// determine the `self` type, using fresh variables for all variables
|
2014-11-28 22:09:12 -06:00
|
|
|
// declared on the impl declaration e.g., `impl<A,B> for Box<[(A,B)]>`
|
2014-09-12 09:53:35 -05:00
|
|
|
// would return ($0, $1) where $0 and $1 are freshly instantiated type
|
|
|
|
// variables.
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn fresh_substs_for_impl<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
|
|
|
|
span: Span,
|
|
|
|
impl_def_id: ast::DefId)
|
|
|
|
-> Substs<'tcx>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
|
|
|
let tcx = infcx.tcx;
|
|
|
|
let impl_generics = ty::lookup_item_type(tcx, impl_def_id).generics;
|
2014-12-29 15:32:12 -06:00
|
|
|
infcx.fresh_substs_for_generics(span, &impl_generics)
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2015-01-20 17:45:07 -06:00
|
|
|
impl<'tcx, N> fmt::Debug for VtableImplData<'tcx, N> {
|
2014-09-12 09:53:35 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2014-12-20 02:09:35 -06:00
|
|
|
write!(f, "VtableImpl({:?})", self.impl_def_id)
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 17:45:07 -06:00
|
|
|
impl<'tcx> fmt::Debug for super::VtableObjectData<'tcx> {
|
2014-12-23 04:26:34 -06:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableObject(...)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// See `super::obligations_for_generics`
|
2014-12-07 10:10:48 -06:00
|
|
|
pub fn predicates_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
recursion_depth: uint,
|
|
|
|
generic_bounds: &ty::GenericBounds<'tcx>)
|
|
|
|
-> VecPerParamSpace<PredicateObligation<'tcx>>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
2014-12-07 10:10:48 -06:00
|
|
|
debug!("predicates_for_generics(generic_bounds={})",
|
|
|
|
generic_bounds.repr(tcx));
|
2014-09-12 09:53:35 -05:00
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
generic_bounds.predicates.map(|predicate| {
|
2014-12-06 10:39:25 -06:00
|
|
|
Obligation { cause: cause.clone(),
|
2014-12-07 10:10:48 -06:00
|
|
|
recursion_depth: recursion_depth,
|
2014-12-17 15:00:34 -06:00
|
|
|
predicate: predicate.clone() }
|
2014-12-07 10:10:48 -06:00
|
|
|
})
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-12-17 13:16:28 -06:00
|
|
|
pub fn trait_ref_for_builtin_bound<'tcx>(
|
2014-09-29 14:11:30 -05:00
|
|
|
tcx: &ty::ctxt<'tcx>,
|
2014-09-12 09:53:35 -05:00
|
|
|
builtin_bound: ty::BuiltinBound,
|
2014-09-29 14:11:30 -05:00
|
|
|
param_ty: Ty<'tcx>)
|
2014-12-17 13:16:28 -06:00
|
|
|
-> Result<Rc<ty::TraitRef<'tcx>>, ErrorReported>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
|
|
|
match tcx.lang_items.from_builtin_kind(builtin_bound) {
|
|
|
|
Ok(def_id) => {
|
2014-12-17 13:16:28 -06:00
|
|
|
Ok(Rc::new(ty::TraitRef {
|
2014-09-18 10:08:04 -05:00
|
|
|
def_id: def_id,
|
2014-12-03 18:01:29 -06:00
|
|
|
substs: tcx.mk_substs(Substs::empty().with_self_ty(param_ty))
|
2014-12-17 13:16:28 -06:00
|
|
|
}))
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
Err(e) => {
|
2014-09-23 00:18:54 -05:00
|
|
|
tcx.sess.err(e.as_slice());
|
2014-12-06 00:30:41 -06:00
|
|
|
Err(ErrorReported)
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
pub fn predicate_for_builtin_bound<'tcx>(
|
2014-09-29 14:11:30 -05:00
|
|
|
tcx: &ty::ctxt<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
2014-09-18 10:08:04 -05:00
|
|
|
builtin_bound: ty::BuiltinBound,
|
|
|
|
recursion_depth: uint,
|
2014-09-29 14:11:30 -05:00
|
|
|
param_ty: Ty<'tcx>)
|
2014-12-07 10:10:48 -06:00
|
|
|
-> Result<PredicateObligation<'tcx>, ErrorReported>
|
2014-09-18 10:08:04 -05:00
|
|
|
{
|
2014-12-17 13:16:28 -06:00
|
|
|
let trait_ref = try!(trait_ref_for_builtin_bound(tcx, builtin_bound, param_ty));
|
2014-12-06 00:30:41 -06:00
|
|
|
Ok(Obligation {
|
|
|
|
cause: cause,
|
|
|
|
recursion_depth: recursion_depth,
|
2014-12-17 13:16:28 -06:00
|
|
|
predicate: trait_ref.as_predicate(),
|
2014-12-06 00:30:41 -06:00
|
|
|
})
|
2014-09-18 10:08:04 -05:00
|
|
|
}
|
|
|
|
|
2014-12-20 08:15:52 -06:00
|
|
|
/// Cast a trait reference into a reference to one of its super
|
|
|
|
/// traits; returns `None` if `target_trait_def_id` is not a
|
|
|
|
/// supertrait.
|
|
|
|
pub fn upcast<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|
|
|
source_trait_ref: ty::PolyTraitRef<'tcx>,
|
|
|
|
target_trait_def_id: ast::DefId)
|
|
|
|
-> Option<ty::PolyTraitRef<'tcx>>
|
|
|
|
{
|
|
|
|
if source_trait_ref.def_id() == target_trait_def_id {
|
|
|
|
return Some(source_trait_ref); // shorcut the most common case
|
|
|
|
}
|
|
|
|
|
|
|
|
for super_trait_ref in supertraits(tcx, source_trait_ref) {
|
|
|
|
if super_trait_ref.def_id() == target_trait_def_id {
|
|
|
|
return Some(super_trait_ref);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given an object of type `object_trait_ref`, returns the index of
|
|
|
|
/// the method `n_method` found in the trait `trait_def_id` (which
|
|
|
|
/// should be a supertrait of `object_trait_ref`) within the vtable
|
|
|
|
/// for `object_trait_ref`.
|
|
|
|
pub fn get_vtable_index_of_object_method<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|
|
|
object_trait_ref: ty::PolyTraitRef<'tcx>,
|
|
|
|
trait_def_id: ast::DefId,
|
|
|
|
method_index_in_trait: uint) -> uint {
|
|
|
|
// We need to figure the "real index" of the method in a
|
|
|
|
// listing of all the methods of an object. We do this by
|
|
|
|
// iterating down the supertraits of the object's trait until
|
|
|
|
// we find the trait the method came from, counting up the
|
|
|
|
// methods from them.
|
|
|
|
let mut method_count = 0;
|
|
|
|
ty::each_bound_trait_and_supertraits(tcx, &[object_trait_ref], |bound_ref| {
|
|
|
|
if bound_ref.def_id() == trait_def_id {
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
let trait_items = ty::trait_items(tcx, bound_ref.def_id());
|
|
|
|
for trait_item in trait_items.iter() {
|
|
|
|
match *trait_item {
|
|
|
|
ty::MethodTraitItem(_) => method_count += 1,
|
|
|
|
ty::TypeTraitItem(_) => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
method_count + method_index_in_trait
|
|
|
|
}
|
|
|
|
|
2015-01-10 10:54:15 -06:00
|
|
|
pub fn unboxed_closure_trait_ref_and_return_type<'tcx>(
|
|
|
|
closure_typer: &ty::UnboxedClosureTyper<'tcx>,
|
|
|
|
fn_trait_def_id: ast::DefId,
|
|
|
|
self_ty: Ty<'tcx>,
|
|
|
|
closure_def_id: ast::DefId,
|
|
|
|
substs: &Substs<'tcx>)
|
|
|
|
-> ty::Binder<(Rc<ty::TraitRef<'tcx>>, Ty<'tcx>)>
|
|
|
|
{
|
|
|
|
let tcx = closure_typer.param_env().tcx;
|
|
|
|
let closure_type = closure_typer.unboxed_closure_type(closure_def_id, substs);
|
|
|
|
|
|
|
|
debug!("unboxed_closure_trait_ref: closure_def_id={} closure_type={}",
|
|
|
|
closure_def_id.repr(tcx),
|
|
|
|
closure_type.repr(tcx));
|
|
|
|
|
|
|
|
let closure_sig = &closure_type.sig;
|
|
|
|
let arguments_tuple = closure_sig.0.inputs[0];
|
|
|
|
let trait_substs =
|
|
|
|
Substs::new_trait(
|
|
|
|
vec![arguments_tuple],
|
|
|
|
vec![],
|
|
|
|
self_ty);
|
|
|
|
let trait_ref = Rc::new(ty::TraitRef {
|
|
|
|
def_id: fn_trait_def_id,
|
|
|
|
substs: tcx.mk_substs(trait_substs),
|
|
|
|
});
|
|
|
|
|
|
|
|
ty::Binder((trait_ref, closure_sig.0.output.unwrap()))
|
|
|
|
}
|
|
|
|
|
2014-12-04 23:03:03 -06:00
|
|
|
impl<'tcx,O:Repr<'tcx>> Repr<'tcx> for super::Obligation<'tcx, O> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-12-17 15:00:34 -06:00
|
|
|
format!("Obligation(predicate={},depth={})",
|
|
|
|
self.predicate.repr(tcx),
|
2014-09-12 09:53:35 -05:00
|
|
|
self.recursion_depth)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::Vtable<'tcx, N> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
match *self {
|
|
|
|
super::VtableImpl(ref v) =>
|
|
|
|
v.repr(tcx),
|
|
|
|
|
2015-01-24 14:00:03 -06:00
|
|
|
super::VtableClosure(ref d, ref s) =>
|
|
|
|
format!("VtableClosure({},{})",
|
2014-11-06 01:50:10 -06:00
|
|
|
d.repr(tcx),
|
|
|
|
s.repr(tcx)),
|
2014-09-12 09:53:35 -05:00
|
|
|
|
2014-12-01 08:23:40 -06:00
|
|
|
super::VtableFnPointer(ref d) =>
|
|
|
|
format!("VtableFnPointer({})",
|
|
|
|
d.repr(tcx)),
|
|
|
|
|
2014-12-23 04:26:34 -06:00
|
|
|
super::VtableObject(ref d) =>
|
|
|
|
format!("VtableObject({})",
|
|
|
|
d.repr(tcx)),
|
|
|
|
|
2015-01-08 20:41:42 -06:00
|
|
|
super::VtableParam(ref n) =>
|
|
|
|
format!("VtableParam({})",
|
|
|
|
n.repr(tcx)),
|
2014-09-12 09:53:35 -05:00
|
|
|
|
2014-10-09 16:19:50 -05:00
|
|
|
super::VtableBuiltin(ref d) =>
|
|
|
|
d.repr(tcx)
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::VtableImplData<'tcx, N> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
format!("VtableImpl(impl_def_id={}, substs={}, nested={})",
|
|
|
|
self.impl_def_id.repr(tcx),
|
|
|
|
self.substs.repr(tcx),
|
|
|
|
self.nested.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, N:Repr<'tcx>> Repr<'tcx> for super::VtableBuiltinData<N> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-10-09 16:19:50 -05:00
|
|
|
format!("VtableBuiltin(nested={})",
|
|
|
|
self.nested.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-23 04:26:34 -06:00
|
|
|
impl<'tcx> Repr<'tcx> for super::VtableObjectData<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
|
|
|
format!("VtableObject(object_ty={})",
|
|
|
|
self.object_ty.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for super::SelectionError<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
match *self {
|
|
|
|
super::Overflow =>
|
|
|
|
format!("Overflow"),
|
|
|
|
|
2014-10-09 16:19:50 -05:00
|
|
|
super::Unimplemented =>
|
|
|
|
format!("Unimplemented"),
|
|
|
|
|
2014-12-07 10:10:48 -06:00
|
|
|
super::OutputTypeParameterMismatch(ref a, ref b, ref c) =>
|
|
|
|
format!("OutputTypeParameterMismatch({},{},{})",
|
|
|
|
a.repr(tcx),
|
|
|
|
b.repr(tcx),
|
2014-12-17 15:00:34 -06:00
|
|
|
c.repr(tcx)),
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for super::FulfillmentError<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
format!("FulfillmentError({},{})",
|
|
|
|
self.obligation.repr(tcx),
|
|
|
|
self.code.repr(tcx))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for super::FulfillmentErrorCode<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
match *self {
|
2014-09-11 00:07:49 -05:00
|
|
|
super::CodeSelectionError(ref o) => o.repr(tcx),
|
2014-12-17 13:16:28 -06:00
|
|
|
super::CodeProjectionError(ref o) => o.repr(tcx),
|
2014-09-11 00:07:49 -05:00
|
|
|
super::CodeAmbiguity => format!("Ambiguity")
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 17:45:07 -06:00
|
|
|
impl<'tcx> fmt::Debug for super::FulfillmentErrorCode<'tcx> {
|
2014-09-12 09:53:35 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2014-12-20 02:09:35 -06:00
|
|
|
super::CodeSelectionError(ref e) => write!(f, "{:?}", e),
|
|
|
|
super::CodeProjectionError(ref e) => write!(f, "{:?}", e),
|
2014-09-11 00:07:49 -05:00
|
|
|
super::CodeAmbiguity => write!(f, "Ambiguity")
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-30 07:59:33 -06:00
|
|
|
impl<'tcx> Repr<'tcx> for super::MismatchedProjectionTypes<'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-12-30 07:59:33 -06:00
|
|
|
self.err.repr(tcx)
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
2014-12-17 13:16:28 -06:00
|
|
|
|
2015-01-20 17:45:07 -06:00
|
|
|
impl<'tcx> fmt::Debug for super::MismatchedProjectionTypes<'tcx> {
|
2014-12-30 07:59:33 -06:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "MismatchedProjectionTypes(..)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|