]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/maps/values.rs
Rollup merge of #45281 - GuillaumeGomez:tab-selection, r=QuietMisdreavus
[rust.git] / src / librustc / ty / maps / values.rs
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.
4 //
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.
10
11 use ty::{self, Ty, TyCtxt};
12
13 use syntax::symbol::Symbol;
14
15 pub(super) trait Value<'tcx>: Sized {
16     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Self;
17 }
18
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");
23     }
24 }
25
26 impl<'tcx, T: Default> Value<'tcx> for T {
27     default fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> T {
28         T::default()
29     }
30 }
31
32 impl<'tcx> Value<'tcx> for Ty<'tcx> {
33     fn from_cycle_error<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Ty<'tcx> {
34         tcx.types.err
35     }
36 }
37
38 impl<'tcx> Value<'tcx> for ty::DtorckConstraint<'tcx> {
39     fn from_cycle_error<'a>(_: TyCtxt<'a, 'tcx, 'tcx>) -> Self {
40         Self::empty()
41     }
42 }
43
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() }
47     }
48 }
49