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.
|
|
|
|
|
|
|
|
use middle::subst;
|
2014-11-28 22:08:30 -06:00
|
|
|
use middle::subst::{ParamSpace, Substs, VecPerParamSpace, Subst};
|
2014-11-25 15:59:02 -06:00
|
|
|
use middle::infer::InferCtxt;
|
2014-09-13 13:09:25 -05:00
|
|
|
use middle::ty::{mod, Ty};
|
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-11-08 05:59:10 -06:00
|
|
|
use super::{Obligation, ObligationCause, VtableImpl,
|
2014-09-23 00:18:54 -05:00
|
|
|
VtableParam, VtableParamData, VtableImplData};
|
2014-09-12 09:53:35 -05:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// Supertrait iterator
|
|
|
|
|
|
|
|
pub struct Supertraits<'cx, 'tcx:'cx> {
|
|
|
|
tcx: &'cx ty::ctxt<'tcx>,
|
2014-09-29 14:11:30 -05:00
|
|
|
stack: Vec<SupertraitEntry<'tcx>>,
|
|
|
|
visited: HashSet<Rc<ty::TraitRef<'tcx>>>,
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
struct SupertraitEntry<'tcx> {
|
2014-09-12 09:53:35 -05:00
|
|
|
position: uint,
|
2014-09-29 14:11:30 -05:00
|
|
|
supertraits: Vec<Rc<ty::TraitRef<'tcx>>>,
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn supertraits<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
|
2014-09-29 14:11:30 -05:00
|
|
|
trait_ref: Rc<ty::TraitRef<'tcx>>)
|
2014-09-12 09:53:35 -05:00
|
|
|
-> Supertraits<'cx, 'tcx>
|
|
|
|
{
|
2014-11-26 13:17:23 -06:00
|
|
|
//! Returns an iterator over the trait reference `T` and all of its supertrait references. May
|
|
|
|
//! contain duplicates. In general the ordering is not defined.
|
|
|
|
//!
|
|
|
|
//! Example:
|
|
|
|
//!
|
|
|
|
//! ```
|
|
|
|
//! trait Foo { ... }
|
|
|
|
//! trait Bar : Foo { ... }
|
|
|
|
//! trait Baz : Bar+Foo { ... }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! `supertraits(Baz)` yields `[Baz, Bar, Foo, Foo]` in some order.
|
|
|
|
|
2014-11-17 02:39:01 -06:00
|
|
|
transitive_bounds(tcx, &[trait_ref])
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn transitive_bounds<'cx, 'tcx>(tcx: &'cx ty::ctxt<'tcx>,
|
2014-09-29 14:11:30 -05:00
|
|
|
bounds: &[Rc<ty::TraitRef<'tcx>>])
|
2014-09-12 09:53:35 -05:00
|
|
|
-> Supertraits<'cx, 'tcx>
|
|
|
|
{
|
|
|
|
let bounds = Vec::from_fn(bounds.len(), |i| bounds[i].clone());
|
2014-09-18 10:08:04 -05:00
|
|
|
|
|
|
|
let visited: HashSet<Rc<ty::TraitRef>> =
|
|
|
|
bounds.iter()
|
|
|
|
.map(|b| (*b).clone())
|
|
|
|
.collect();
|
|
|
|
|
2014-09-12 09:53:35 -05:00
|
|
|
let entry = SupertraitEntry { position: 0, supertraits: bounds };
|
2014-09-18 10:08:04 -05:00
|
|
|
Supertraits { tcx: tcx, stack: vec![entry], visited: visited }
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'cx, 'tcx> Supertraits<'cx, 'tcx> {
|
2014-09-29 14:11:30 -05:00
|
|
|
fn push(&mut self, trait_ref: &ty::TraitRef<'tcx>) {
|
2014-09-18 10:08:04 -05:00
|
|
|
let ty::ParamBounds { builtin_bounds, mut trait_bounds, .. } =
|
|
|
|
ty::bounds_for_trait_ref(self.tcx, trait_ref);
|
|
|
|
for builtin_bound in builtin_bounds.iter() {
|
|
|
|
let bound_trait_ref = trait_ref_for_builtin_bound(self.tcx,
|
|
|
|
builtin_bound,
|
|
|
|
trait_ref.self_ty());
|
2014-09-23 00:18:54 -05:00
|
|
|
bound_trait_ref.map(|trait_ref| trait_bounds.push(trait_ref));
|
2014-09-18 10:08:04 -05: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 people define `trait Sized { }`
|
|
|
|
// rather than `trait Sized for Sized? { }`.
|
|
|
|
trait_bounds.retain(|r| self.visited.insert((*r).clone()));
|
|
|
|
|
|
|
|
let entry = SupertraitEntry { position: 0, supertraits: trait_bounds };
|
2014-09-12 09:53:35 -05:00
|
|
|
self.stack.push(entry);
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// Returns the path taken through the trait supertraits to reach the current point.
|
2014-09-12 09:53:35 -05:00
|
|
|
pub fn indices(&self) -> Vec<uint> {
|
|
|
|
self.stack.iter().map(|e| e.position).collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'cx, 'tcx> Iterator<Rc<ty::TraitRef<'tcx>>> for Supertraits<'cx, 'tcx> {
|
|
|
|
fn next(&mut self) -> Option<Rc<ty::TraitRef<'tcx>>> {
|
2014-09-12 09:53:35 -05:00
|
|
|
loop {
|
|
|
|
// Extract next item from top-most stack frame, if any.
|
2014-10-15 01:05:01 -05:00
|
|
|
let next_trait = 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;
|
|
|
|
if p < entry.supertraits.len() {
|
|
|
|
// Still more supertraits left in the top stack frame.
|
|
|
|
entry.position += 1;
|
|
|
|
|
2014-10-15 01:05:01 -05:00
|
|
|
let next_trait = entry.supertraits[p].clone();
|
2014-09-12 09:53:35 -05:00
|
|
|
Some(next_trait)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
match next_trait {
|
|
|
|
Some(next_trait) => {
|
|
|
|
self.push(&*next_trait);
|
|
|
|
return Some(next_trait);
|
|
|
|
}
|
|
|
|
|
|
|
|
None => {
|
|
|
|
// Top stack frame is exhausted, pop it.
|
|
|
|
self.stack.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine the `self` type, using fresh variables for all variables
|
|
|
|
// declared on the impl declaration e.g., `impl<A,B> for ~[(A,B)]`
|
|
|
|
// 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-11-28 22:08:30 -06:00
|
|
|
let input_substs = infcx.fresh_substs_for_generics(span, &impl_generics);
|
|
|
|
|
|
|
|
// Add substs for the associated types bound in the impl.
|
|
|
|
let ref items = tcx.impl_items.borrow()[impl_def_id];
|
|
|
|
let mut assoc_tys = Vec::new();
|
|
|
|
for item in items.iter() {
|
|
|
|
if let &ty::ImplOrTraitItemId::TypeTraitItemId(id) = item {
|
|
|
|
assoc_tys.push(tcx.tcache.borrow()[id].ty.subst(tcx, &input_substs));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
input_substs.with_assoc_tys(assoc_tys)
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx, N> fmt::Show for VtableImplData<'tcx, N> {
|
2014-09-12 09:53:35 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableImpl({})", self.impl_def_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> fmt::Show for VtableParamData<'tcx> {
|
2014-09-12 09:53:35 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "VtableParam(...)")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// See `super::obligations_for_generics`
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn obligations_for_generics<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
|
|
|
recursion_depth: uint,
|
|
|
|
generic_bounds: &ty::GenericBounds<'tcx>,
|
|
|
|
type_substs: &VecPerParamSpace<Ty<'tcx>>)
|
|
|
|
-> VecPerParamSpace<Obligation<'tcx>>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
|
|
|
|
2014-11-15 16:25:05 -06:00
|
|
|
debug!("obligations_for_generics(generic_bounds={}, type_substs={})",
|
|
|
|
generic_bounds.repr(tcx), type_substs.repr(tcx));
|
2014-09-12 09:53:35 -05:00
|
|
|
|
|
|
|
let mut obligations = VecPerParamSpace::empty();
|
|
|
|
|
2014-11-15 16:25:05 -06:00
|
|
|
for (space, index, bounds) in generic_bounds.types.iter_enumerated() {
|
2014-09-12 09:53:35 -05:00
|
|
|
push_obligations_for_param_bounds(tcx,
|
|
|
|
cause,
|
|
|
|
recursion_depth,
|
2014-11-15 16:25:05 -06:00
|
|
|
space,
|
|
|
|
index,
|
|
|
|
bounds,
|
|
|
|
type_substs,
|
2014-09-12 09:53:35 -05:00
|
|
|
&mut obligations);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug!("obligations() ==> {}", obligations.repr(tcx));
|
|
|
|
|
|
|
|
return obligations;
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
fn push_obligations_for_param_bounds<'tcx>(
|
|
|
|
tcx: &ty::ctxt<'tcx>,
|
|
|
|
cause: ObligationCause<'tcx>,
|
2014-09-12 09:53:35 -05:00
|
|
|
recursion_depth: uint,
|
|
|
|
space: subst::ParamSpace,
|
|
|
|
index: uint,
|
2014-09-29 14:11:30 -05:00
|
|
|
param_bounds: &ty::ParamBounds<'tcx>,
|
|
|
|
param_type_substs: &VecPerParamSpace<Ty<'tcx>>,
|
|
|
|
obligations: &mut VecPerParamSpace<Obligation<'tcx>>)
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
2014-11-15 16:25:05 -06:00
|
|
|
let param_ty = *param_type_substs.get(space, index);
|
2014-09-12 09:53:35 -05:00
|
|
|
for builtin_bound in param_bounds.builtin_bounds.iter() {
|
2014-09-23 00:18:54 -05:00
|
|
|
let obligation = obligation_for_builtin_bound(tcx,
|
|
|
|
cause,
|
|
|
|
builtin_bound,
|
|
|
|
recursion_depth,
|
|
|
|
param_ty);
|
2014-11-29 15:41:21 -06:00
|
|
|
if let Ok(ob) = obligation {
|
|
|
|
obligations.push(space, ob);
|
2014-09-23 00:18:54 -05:00
|
|
|
}
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for bound_trait_ref in param_bounds.trait_bounds.iter() {
|
|
|
|
obligations.push(
|
|
|
|
space,
|
|
|
|
Obligation { cause: cause,
|
|
|
|
recursion_depth: recursion_depth,
|
2014-11-15 16:25:05 -06:00
|
|
|
trait_ref: (*bound_trait_ref).clone() });
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn trait_ref_for_builtin_bound<'tcx>(
|
|
|
|
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>)
|
|
|
|
-> Option<Rc<ty::TraitRef<'tcx>>>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
|
|
|
match tcx.lang_items.from_builtin_kind(builtin_bound) {
|
|
|
|
Ok(def_id) => {
|
2014-09-23 00:18:54 -05:00
|
|
|
Some(Rc::new(ty::TraitRef {
|
2014-09-18 10:08:04 -05:00
|
|
|
def_id: def_id,
|
|
|
|
substs: Substs::empty().with_self_ty(param_ty)
|
2014-09-23 00:18:54 -05: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());
|
|
|
|
None
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn obligation_for_builtin_bound<'tcx>(
|
|
|
|
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>)
|
|
|
|
-> Result<Obligation<'tcx>, ErrorReported>
|
2014-09-18 10:08:04 -05:00
|
|
|
{
|
|
|
|
let trait_ref = trait_ref_for_builtin_bound(tcx, builtin_bound, param_ty);
|
2014-09-23 00:18:54 -05:00
|
|
|
match trait_ref {
|
|
|
|
Some(trait_ref) => Ok(Obligation {
|
|
|
|
cause: cause,
|
|
|
|
recursion_depth: recursion_depth,
|
|
|
|
trait_ref: trait_ref
|
|
|
|
}),
|
|
|
|
None => Err(ErrorReported)
|
2014-09-18 10:08:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-25 20:17:11 -06:00
|
|
|
/// Starting from a caller obligation `caller_bound` (which has coordinates `space`/`i` in the list
|
|
|
|
/// of caller obligations), search through the trait and supertraits to find one where `test(d)` is
|
|
|
|
/// true, where `d` is the def-id of the trait/supertrait. If any is found, return `Some(p)` where
|
|
|
|
/// `p` is the path to that trait/supertrait. Else `None`.
|
2014-09-29 14:11:30 -05:00
|
|
|
pub fn search_trait_and_supertraits_from_bound<'tcx>(tcx: &ty::ctxt<'tcx>,
|
|
|
|
caller_bound: Rc<ty::TraitRef<'tcx>>,
|
|
|
|
test: |ast::DefId| -> bool)
|
|
|
|
-> Option<VtableParamData<'tcx>>
|
2014-09-12 09:53:35 -05:00
|
|
|
{
|
2014-09-17 11:26:26 -05:00
|
|
|
for bound in transitive_bounds(tcx, &[caller_bound]) {
|
2014-09-12 09:53:35 -05:00
|
|
|
if test(bound.def_id) {
|
2014-09-11 00:07:49 -05:00
|
|
|
let vtable_param = VtableParamData { bound: bound };
|
2014-09-12 09:53:35 -05:00
|
|
|
return Some(vtable_param);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for super::Obligation<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
format!("Obligation(trait_ref={},depth={})",
|
|
|
|
self.trait_ref.repr(tcx),
|
|
|
|
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),
|
|
|
|
|
2014-11-06 01:50:10 -06:00
|
|
|
super::VtableUnboxedClosure(ref d, ref s) =>
|
|
|
|
format!("VtableUnboxedClosure({},{})",
|
|
|
|
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-09-12 09:53:35 -05:00
|
|
|
super::VtableParam(ref v) =>
|
|
|
|
format!("VtableParam({})", v.repr(tcx)),
|
|
|
|
|
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-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for super::VtableParamData<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
format!("VtableParam(bound={})",
|
|
|
|
self.bound.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-09-12 09:53:35 -05:00
|
|
|
super::OutputTypeParameterMismatch(ref t, ref e) =>
|
|
|
|
format!("OutputTypeParameterMismatch({}, {})",
|
|
|
|
t.repr(tcx),
|
|
|
|
e.repr(tcx)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
super::CodeAmbiguity => format!("Ambiguity")
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> fmt::Show for super::FulfillmentErrorCode<'tcx> {
|
2014-09-12 09:53:35 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
match *self {
|
2014-09-11 00:07:49 -05:00
|
|
|
super::CodeSelectionError(ref e) => write!(f, "{}", e),
|
|
|
|
super::CodeAmbiguity => write!(f, "Ambiguity")
|
2014-09-12 09:53:35 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:11:30 -05:00
|
|
|
impl<'tcx> Repr<'tcx> for ty::type_err<'tcx> {
|
|
|
|
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
|
2014-09-12 09:53:35 -05:00
|
|
|
ty::type_err_to_str(tcx, self)
|
|
|
|
}
|
|
|
|
}
|