forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalues.rs
More file actions
33 lines (27 loc) · 972 Bytes
/
values.rs
File metadata and controls
33 lines (27 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use crate::ty::{self, AdtSizedConstraint, Ty, TyCtxt};
use rustc_errors::ErrorProof;
use rustc_span::symbol::Symbol;
pub(super) trait Value<'tcx>: Sized {
fn from_cycle_error(tcx: TyCtxt<'tcx>, proof: ErrorProof) -> Self;
}
impl<'tcx, T> Value<'tcx> for T {
default fn from_cycle_error(tcx: TyCtxt<'tcx>, _: ErrorProof) -> T {
tcx.sess.abort_if_errors();
bug!("Value::from_cycle_error called without errors");
}
}
impl<'tcx> Value<'tcx> for Ty<'tcx> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, proof: ErrorProof) -> Ty<'tcx> {
tcx.err(proof)
}
}
impl<'tcx> Value<'tcx> for ty::SymbolName {
fn from_cycle_error(_: TyCtxt<'tcx>, _: ErrorProof) -> Self {
ty::SymbolName { name: Symbol::intern("<error>") }
}
}
impl<'tcx> Value<'tcx> for AdtSizedConstraint<'tcx> {
fn from_cycle_error(tcx: TyCtxt<'tcx>, proof: ErrorProof) -> Self {
AdtSizedConstraint(tcx.intern_type_list(&[tcx.err(proof)]))
}
}