]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_query_impl/src/values.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / compiler / rustc_query_impl / src / values.rs
CommitLineData
6a06907d 1use super::QueryCtxt;
5099ac24 2use rustc_middle::ty::{self, AdtSizedConstraint, Ty};
ea8adc8c 3
ea8adc8c 4pub(super) trait Value<'tcx>: Sized {
6a06907d 5 fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self;
ea8adc8c
XL
6}
7
8impl<'tcx, T> Value<'tcx> for T {
6a06907d 9 default fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> T {
ea8adc8c
XL
10 tcx.sess.abort_if_errors();
11 bug!("Value::from_cycle_error called without errors");
12 }
13}
14
5099ac24 15impl<'tcx> Value<'tcx> for Ty<'_> {
6a06907d 16 fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
f035d41b
XL
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()) }
ea8adc8c
XL
20 }
21}
22
3dfed10e 23impl<'tcx> Value<'tcx> for ty::SymbolName<'_> {
6a06907d 24 fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
3dfed10e
XL
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(
6a06907d 29 *tcx, "<error>",
3dfed10e
XL
30 ))
31 }
ea8adc8c
XL
32 }
33}
34
f035d41b 35impl<'tcx> Value<'tcx> for AdtSizedConstraint<'_> {
6a06907d 36 fn from_cycle_error(tcx: QueryCtxt<'tcx>) -> Self {
f035d41b
XL
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 }
9fa01778
XL
44 }
45}