diff options
| author | Lukas Markeffsky <@> | 2025-01-30 17:22:45 +0100 |
|---|---|---|
| committer | Lukas Markeffsky <@> | 2025-01-30 18:13:16 +0100 |
| commit | ca3ff832e34cc32d93c9e940d8f6d3e4034203fa (patch) | |
| tree | a423654529a019b358ea809cacf967ae5f1f3533 /compiler/rustc_middle/src | |
| parent | 0055fb92db2fcfb8c74d1bf9063f14f65d5dcce0 (diff) | |
add comments
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/ty/consts.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 1 |
2 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 4ad5d8443b2..d77fb1cc91e 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -222,6 +222,8 @@ impl<'tcx> Const<'tcx> { } /// Attempts to convert to a value. + /// + /// Note that this does not evaluate the constant. pub fn try_to_value(self) -> Option<ty::Value<'tcx>> { match self.kind() { ty::ConstKind::Value(cv) => Some(cv), @@ -229,6 +231,10 @@ impl<'tcx> Const<'tcx> { } } + /// Convenience method to extract the value of a usize constant, + /// useful to get the length of an array type. + /// + /// Note that this does not evaluate the constant. #[inline] pub fn try_to_target_usize(self, tcx: TyCtxt<'tcx>) -> Option<u64> { self.try_to_value()?.try_to_target_usize(tcx) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 19a39b3a29e..018fcc66aee 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1785,6 +1785,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { Ok(()) } + // FIXME(valtrees): Accept `ty::Value` instead of `Ty` and `ty::ValTree` separately. fn pretty_print_const_valtree( &mut self, valtree: ty::ValTree<'tcx>, |
