diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2024-06-19 09:52:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-19 09:52:02 +0200 |
| commit | 2bc0cf2da5c4ad4e66958ed99f84b45c8f376f8b (patch) | |
| tree | c179269102bcecc532dc15e7ace43dd6ab4538e8 | |
| parent | ef062ea80d2edb7de8434650163d46a0e423fe73 (diff) | |
| parent | 1299aef92112945e9587c168caed8d6486ffbf30 (diff) | |
| download | rust-2bc0cf2da5c4ad4e66958ed99f84b45c8f376f8b.tar.gz rust-2bc0cf2da5c4ad4e66958ed99f84b45c8f376f8b.zip | |
Rollup merge of #126654 - tgross35:f16-f128-pretty-print, r=jackh726
Make pretty printing for `f16` and `f128` consistent
Currently the docs show e.g.
{transmute(0xfffeffffffffffffffffffffffffffff): f128}
for f128 constants. This should fix that to instead use apfloat for printing, as is done for `f32` and `f64`.
| -rw-r--r-- | compiler/rustc_middle/src/ty/print/pretty.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index de1796d4800..72cb3e13402 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -7,7 +7,7 @@ use crate::ty::{ ConstInt, Expr, ParamConst, ScalarInt, Term, TermKind, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, }; -use rustc_apfloat::ieee::{Double, Single}; +use rustc_apfloat::ieee::{Double, Half, Quad, Single}; use rustc_apfloat::Float; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::unord::UnordMap; @@ -1710,6 +1710,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { ty::Bool if int == ScalarInt::FALSE => p!("false"), ty::Bool if int == ScalarInt::TRUE => p!("true"), // Float + ty::Float(ty::FloatTy::F16) => { + let val = Half::try_from(int).unwrap(); + p!(write("{}{}f16", val, if val.is_finite() { "" } else { "_" })) + } ty::Float(ty::FloatTy::F32) => { let val = Single::try_from(int).unwrap(); p!(write("{}{}f32", val, if val.is_finite() { "" } else { "_" })) @@ -1718,6 +1722,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { let val = Double::try_from(int).unwrap(); p!(write("{}{}f64", val, if val.is_finite() { "" } else { "_" })) } + ty::Float(ty::FloatTy::F128) => { + let val = Quad::try_from(int).unwrap(); + p!(write("{}{}f128", val, if val.is_finite() { "" } else { "_" })) + } // Int ty::Uint(_) | ty::Int(_) => { let int = |
