Skip to content

Commit 9421f74

Browse files
committed
Allow direct field accesses through Const to the ConstKind and the Ty fields without the helper method
1 parent 8a75c5a commit 9421f74

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

compiler/rustc_middle/src/ty/consts.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ pub use valtree::*;
1919
#[rustc_pass_by_value]
2020
pub struct Const<'tcx>(pub Interned<'tcx, ConstS<'tcx>>);
2121

22+
impl<'tcx> std::ops::Deref for Const<'tcx> {
23+
type Target = ConstS<'tcx>;
24+
25+
fn deref(&self) -> &Self::Target {
26+
&self.0.0
27+
}
28+
}
29+
2230
impl<'tcx> fmt::Debug for Const<'tcx> {
2331
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2432
// This reflects what `Const` looked liked before `Interned` was
@@ -41,12 +49,12 @@ static_assert_size!(ConstS<'_>, 40);
4149
impl<'tcx> Const<'tcx> {
4250
#[inline]
4351
pub fn ty(self) -> Ty<'tcx> {
44-
self.0.ty
52+
self.ty
4553
}
4654

4755
#[inline]
4856
pub fn kind(self) -> ConstKind<'tcx> {
49-
self.0.kind
57+
self.kind
5058
}
5159

5260
/// Literals and const generic parameters are eagerly converted to a constant, everything else

0 commit comments

Comments
 (0)