Skip to content

Commit 0110073

Browse files
committed
Fully erase query values
1 parent 6d99dd9 commit 0110073

File tree

1 file changed

+135
-15
lines changed

1 file changed

+135
-15
lines changed

Diff for: compiler/rustc_middle/src/query/erase.rs

+135-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::ty;
1+
use crate::mir;
2+
use crate::traits;
3+
use crate::ty::{self, Ty};
24
use std::mem::{size_of, transmute_copy, MaybeUninit};
35

46
#[derive(Copy, Clone)]
@@ -53,32 +55,128 @@ impl<T> EraseType for &'_ ty::List<T> {
5355
type Result = [u8; size_of::<*const ()>()];
5456
}
5557

56-
impl<T: Copy, E: Copy> EraseType for Result<T, E> {
57-
type Result = Self;
58+
impl<T> EraseType for Result<&'_ T, traits::query::NoSolution> {
59+
type Result = [u8; size_of::<Result<&'static (), traits::query::NoSolution>>()];
5860
}
5961

60-
impl<T: Copy> EraseType for Option<T> {
61-
type Result = Self;
62+
impl<T> EraseType for Result<&'_ T, rustc_errors::ErrorGuaranteed> {
63+
type Result = [u8; size_of::<Result<&'static (), rustc_errors::ErrorGuaranteed>>()];
6264
}
6365

64-
impl<T: Copy> EraseType for rustc_hir::MaybeOwner<T> {
65-
type Result = Self;
66+
impl<T> EraseType for Result<&'_ T, traits::CodegenObligationError> {
67+
type Result = [u8; size_of::<Result<&'static (), traits::CodegenObligationError>>()];
6668
}
6769

68-
impl<T: Copy> EraseType for ty::Visibility<T> {
69-
type Result = Self;
70+
impl<T> EraseType for Result<&'_ T, ty::layout::FnAbiError<'_>> {
71+
type Result = [u8; size_of::<Result<&'static (), ty::layout::FnAbiError<'static>>>()];
7072
}
7173

72-
impl<T: Copy> EraseType for ty::Binder<'_, T> {
73-
type Result = Self;
74+
impl<T> EraseType for Result<(&'_ T, rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed> {
75+
type Result = [u8; size_of::<
76+
Result<(&'static (), rustc_middle::thir::ExprId), rustc_errors::ErrorGuaranteed>,
77+
>()];
7478
}
7579

76-
impl<T: Copy> EraseType for ty::EarlyBinder<T> {
77-
type Result = Self;
80+
impl EraseType for Result<Option<ty::Instance<'_>>, rustc_errors::ErrorGuaranteed> {
81+
type Result =
82+
[u8; size_of::<Result<Option<ty::Instance<'static>>, rustc_errors::ErrorGuaranteed>>()];
7883
}
7984

80-
impl<T0: Copy, T1: Copy> EraseType for (T0, T1) {
81-
type Result = Self;
85+
impl EraseType for Result<Option<ty::Const<'_>>, rustc_errors::ErrorGuaranteed> {
86+
type Result =
87+
[u8; size_of::<Result<Option<ty::Const<'static>>, rustc_errors::ErrorGuaranteed>>()];
88+
}
89+
90+
impl EraseType for Result<ty::GenericArg<'_>, traits::query::NoSolution> {
91+
type Result = [u8; size_of::<Result<ty::GenericArg<'static>, traits::query::NoSolution>>()];
92+
}
93+
94+
impl EraseType for Result<bool, ty::layout::LayoutError<'_>> {
95+
type Result = [u8; size_of::<Result<bool, ty::layout::LayoutError<'static>>>()];
96+
}
97+
98+
impl EraseType for Result<rustc_target::abi::TyAndLayout<'_, Ty<'_>>, ty::layout::LayoutError<'_>> {
99+
type Result = [u8; size_of::<
100+
Result<
101+
rustc_target::abi::TyAndLayout<'static, Ty<'static>>,
102+
ty::layout::LayoutError<'static>,
103+
>,
104+
>()];
105+
}
106+
107+
impl EraseType for Result<ty::Const<'_>, mir::interpret::LitToConstError> {
108+
type Result = [u8; size_of::<Result<ty::Const<'static>, mir::interpret::LitToConstError>>()];
109+
}
110+
111+
impl EraseType for Result<mir::ConstantKind<'_>, mir::interpret::LitToConstError> {
112+
type Result =
113+
[u8; size_of::<Result<mir::ConstantKind<'static>, mir::interpret::LitToConstError>>()];
114+
}
115+
116+
impl EraseType for Result<mir::interpret::ConstAlloc<'_>, mir::interpret::ErrorHandled> {
117+
type Result = [u8; size_of::<
118+
Result<mir::interpret::ConstAlloc<'static>, mir::interpret::ErrorHandled>,
119+
>()];
120+
}
121+
122+
impl EraseType for Result<mir::interpret::ConstValue<'_>, mir::interpret::ErrorHandled> {
123+
type Result = [u8; size_of::<
124+
Result<mir::interpret::ConstValue<'static>, mir::interpret::ErrorHandled>,
125+
>()];
126+
}
127+
128+
impl EraseType for Result<Option<ty::ValTree<'_>>, mir::interpret::ErrorHandled> {
129+
type Result =
130+
[u8; size_of::<Result<Option<ty::ValTree<'static>>, mir::interpret::ErrorHandled>>()];
131+
}
132+
133+
impl EraseType for Result<&'_ ty::List<Ty<'_>>, ty::util::AlwaysRequiresDrop> {
134+
type Result =
135+
[u8; size_of::<Result<&'static ty::List<Ty<'static>>, ty::util::AlwaysRequiresDrop>>()];
136+
}
137+
138+
impl<T> EraseType for Option<&'_ T> {
139+
type Result = [u8; size_of::<Option<&'static ()>>()];
140+
}
141+
142+
impl<T> EraseType for Option<&'_ [T]> {
143+
type Result = [u8; size_of::<Option<&'static [()]>>()];
144+
}
145+
146+
impl EraseType for Option<rustc_middle::hir::Owner<'_>> {
147+
type Result = [u8; size_of::<Option<rustc_middle::hir::Owner<'static>>>()];
148+
}
149+
150+
impl EraseType for Option<mir::DestructuredConstant<'_>> {
151+
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
152+
}
153+
154+
impl EraseType for Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
155+
type Result = [u8; size_of::<Option<ty::EarlyBinder<ty::TraitRef<'static>>>>()];
156+
}
157+
158+
impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {
159+
type Result = [u8; size_of::<Option<ty::EarlyBinder<Ty<'static>>>>()];
160+
}
161+
162+
impl<T> EraseType for rustc_hir::MaybeOwner<&'_ T> {
163+
type Result = [u8; size_of::<rustc_hir::MaybeOwner<&'static ()>>()];
164+
}
165+
166+
impl<T: EraseType> EraseType for ty::EarlyBinder<T> {
167+
type Result = T::Result;
168+
}
169+
170+
impl EraseType for ty::Binder<'_, ty::FnSig<'_>> {
171+
type Result = [u8; size_of::<ty::Binder<'static, ty::FnSig<'static>>>()];
172+
}
173+
174+
impl<T0, T1> EraseType for (&'_ T0, &'_ T1) {
175+
type Result = [u8; size_of::<(&'static (), &'static ())>()];
176+
}
177+
178+
impl<T0, T1> EraseType for (&'_ T0, &'_ [T1]) {
179+
type Result = [u8; size_of::<(&'static (), &'static [()])>()];
82180
}
83181

84182
macro_rules! trivial {
@@ -94,6 +192,27 @@ macro_rules! trivial {
94192
trivial! {
95193
(),
96194
bool,
195+
Option<(rustc_span::def_id::DefId, rustc_session::config::EntryFnType)>,
196+
Option<rustc_ast::expand::allocator::AllocatorKind>,
197+
Option<rustc_attr::ConstStability>,
198+
Option<rustc_attr::DefaultBodyStability>,
199+
Option<rustc_attr::Stability>,
200+
Option<rustc_data_structures::svh::Svh>,
201+
Option<rustc_hir::def::DefKind>,
202+
Option<rustc_hir::GeneratorKind>,
203+
Option<rustc_hir::HirId>,
204+
Option<rustc_middle::middle::stability::DeprecationEntry>,
205+
Option<rustc_middle::ty::Destructor>,
206+
Option<rustc_middle::ty::ImplTraitInTraitData>,
207+
Option<rustc_span::def_id::CrateNum>,
208+
Option<rustc_span::def_id::DefId>,
209+
Option<rustc_span::def_id::LocalDefId>,
210+
Option<rustc_span::Span>,
211+
Option<rustc_target::spec::PanicStrategy>,
212+
Option<usize>,
213+
Result<(), rustc_errors::ErrorGuaranteed>,
214+
Result<(), rustc_middle::traits::query::NoSolution>,
215+
Result<rustc_middle::traits::EvaluationResult, rustc_middle::traits::OverflowError>,
97216
rustc_ast::expand::allocator::AllocatorKind,
98217
rustc_attr::ConstStability,
99218
rustc_attr::DefaultBodyStability,
@@ -144,6 +263,7 @@ trivial! {
144263
rustc_middle::ty::ReprOptions,
145264
rustc_middle::ty::UnusedGenericParams,
146265
rustc_middle::ty::util::AlwaysRequiresDrop,
266+
rustc_middle::ty::Visibility<rustc_span::def_id::DefId>,
147267
rustc_session::config::CrateType,
148268
rustc_session::config::EntryFnType,
149269
rustc_session::config::OptLevel,

0 commit comments

Comments
 (0)