]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_query_impl/src/values.rs
consistently use VTable over Vtable (matching stable stdlib API RawWakerVTable)
[rust.git] / compiler / rustc_query_impl / src / values.rs
1 use super::QueryCtxt;
2 use rustc_middle::ty::{self, AdtSizedConstraint, Ty};
3
4 pub(super) trait Value<'tcx>: Sized {
5     fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self;
6 }
7
8 impl<'tcx, T> Value<'tcx> for T {
9     default fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> T {
10         tcx.sess.abort_if_errors();
11         bug!("Value::from_cycle_error called without errors");
12     }
13 }
14
15 impl<'tcx> Value<'tcx> for Ty<'_> {
16     fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
17         // SAFETY: This is never called when `Self` is not `Ty<'tcx>`.
18         // FIXME: Represent the above fact in the trait system somehow.
19         unsafe { std::mem::transmute::<Ty<'tcx>, Ty<'_>>(tcx.ty_error()) }
20     }
21 }
22
23 impl<'tcx> Value<'tcx> for ty::SymbolName<'_> {
24     fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
25         // SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`.
26         // FIXME: Represent the above fact in the trait system somehow.
27         unsafe {
28             std::mem::transmute::<ty::SymbolName<'tcx>, ty::SymbolName<'_>>(ty::SymbolName::new(
29                 *tcx, "<error>",
30             ))
31         }
32     }
33 }
34
35 impl<'tcx> Value<'tcx> for AdtSizedConstraint<'_> {
36     fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
37         // SAFETY: This is never called when `Self` is not `AdtSizedConstraint<'tcx>`.
38         // FIXME: Represent the above fact in the trait system somehow.
39         unsafe {
40             std::mem::transmute::<AdtSizedConstraint<'tcx>, AdtSizedConstraint<'_>>(
41                 AdtSizedConstraint(tcx.intern_type_list(&[tcx.ty_error()])),
42             )
43         }
44     }
45 }