1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use ty::{self, Ty, TyCtxt};
13 use syntax::symbol::Symbol;
15 pub(super) trait Value<'tcx>: Sized {
16 fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
19 impl<'tcx, T> Value<'tcx> for T {
20 default fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> T {
21 tcx.sess.abort_if_errors();
22 bug!("Value::from_cycle_error called without errors");
26 impl<'tcx, T: Default> Value<'tcx> for T {
27 default fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> T {
32 impl<'tcx> Value<'tcx> for Ty<'tcx> {
33 fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
38 impl<'tcx> Value<'tcx> for ty::DtorckConstraint<'tcx> {
39 fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
44 impl<'tcx> Value<'tcx> for ty::SymbolName {
45 fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
46 ty::SymbolName { name: Symbol::intern("<error>").as_str() }