about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeón Orell Valerian Liehr <me@fmease.dev>2023-11-25 10:21:08 +0100
committerGitHub <noreply@github.com>2023-11-25 10:21:08 +0100
commita663bb946f0ef0598ae7c288e60784fa9ef5dadb (patch)
tree53fb29ba548372a5c11af985a0cd07361eec2978
parent3f513bd9cefd34979038b05e18450b96bc4cf10d (diff)
parentb601b40b402028639cac8d6b87e6a9cabd11b457 (diff)
downloadrust-a663bb946f0ef0598ae7c288e60784fa9ef5dadb.tar.gz
rust-a663bb946f0ef0598ae7c288e60784fa9ef5dadb.zip
Rollup merge of #118271 - compiler-errors:float, r=RalfJung
Separate `NaN`/`Inf` floats with `_`

r? RalfJung

Fixes #118221

No test 🤷 unless you know a good way to print an `ImmTy` in a unit test?
-rw-r--r--compiler/rustc_middle/src/ty/print/pretty.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index 25a151443d5..2bde339ec77 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -8,6 +8,7 @@ use crate::ty::{
 };
 use crate::ty::{GenericArg, GenericArgKind};
 use rustc_apfloat::ieee::{Double, Single};
+use rustc_apfloat::Float;
 use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
 use rustc_data_structures::sso::SsoHashSet;
 use rustc_hir as hir;
@@ -1477,10 +1478,12 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
             ty::Bool if int == ScalarInt::TRUE => p!("true"),
             // Float
             ty::Float(ty::FloatTy::F32) => {
-                p!(write("{}f32", Single::try_from(int).unwrap()))
+                let val = Single::try_from(int).unwrap();
+                p!(write("{}{}f32", val, if val.is_finite() { "" } else { "_" }))
             }
             ty::Float(ty::FloatTy::F64) => {
-                p!(write("{}f64", Double::try_from(int).unwrap()))
+                let val = Double::try_from(int).unwrap();
+                p!(write("{}{}f64", val, if val.is_finite() { "" } else { "_" }))
             }
             // Int
             ty::Uint(_) | ty::Int(_) => {