]> git.lizzy.rs Git - rust.git/blob - src/librustc/ty/query/values.rs
Rollup merge of #60772 - timvermeulen:slice_iter_nth_back, r=scottmcm
[rust.git] / src / librustc / ty / query / values.rs
1 use crate::ty::{self, Ty, TyCtxt, AdtSizedConstraint};
2 use crate::ty::util::NeedsDrop;
3
4 use syntax::symbol::InternedString;
5
6 pub(super) trait Value<'tcx>: Sized {
7     fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self;
8 }
9
10 impl<'tcx, T> Value<'tcx> for T {
11     default fn from_cycle_error(tcx: TyCtxt<'tcx>) -> T {
12         tcx.sess.abort_if_errors();
13         bug!("Value::from_cycle_error called without errors");
14     }
15 }
16
17 impl<'tcx> Value<'tcx> for Ty<'tcx> {
18     fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
19         tcx.types.err
20     }
21 }
22
23 impl<'tcx> Value<'tcx> for ty::SymbolName {
24     fn from_cycle_error(_: TyCtxt<'tcx>) -> Self {
25         ty::SymbolName { name: InternedString::intern("<error>") }
26     }
27 }
28
29 impl<'tcx> Value<'tcx> for NeedsDrop {
30     fn from_cycle_error(_: TyCtxt<'tcx>) -> Self {
31         NeedsDrop(false)
32     }
33 }
34
35 impl<'tcx> Value<'tcx> for AdtSizedConstraint<'tcx> {
36     fn from_cycle_error(tcx: TyCtxt<'tcx>) -> Self {
37         AdtSizedConstraint(tcx.intern_type_list(&[tcx.types.err]))
38     }
39 }