Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-ty/src/display.rs')
-rw-r--r--crates/hir-ty/src/display.rs44
1 files changed, 38 insertions, 6 deletions
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index 66b5398b88..a9a5d829f5 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -21,13 +21,17 @@ use hir_def::{
path::{Path, PathKind},
type_ref::{TraitBoundModifier, TypeBound, TypeRef},
visibility::Visibility,
- HasModule, ImportPathConfig, ItemContainerId, LocalFieldId, Lookup, ModuleDefId, ModuleId,
- TraitId,
+ GenericDefId, HasModule, ImportPathConfig, ItemContainerId, LocalFieldId, Lookup, ModuleDefId,
+ ModuleId, TraitId,
};
use hir_expand::name::Name;
use intern::{Internable, Interned};
use itertools::Itertools;
use la_arena::ArenaMap;
+use rustc_apfloat::{
+ ieee::{Half as f16, Quad as f128},
+ Float,
+};
use smallvec::SmallVec;
use stdx::{never, IsNoneOr};
use triomphe::Arc;
@@ -545,6 +549,17 @@ fn render_const_scalar(
write!(f, "{it}")
}
Scalar::Float(fl) => match fl {
+ chalk_ir::FloatTy::F16 => {
+ // FIXME(#17451): Replace with builtins once they are stabilised.
+ let it = f16::from_bits(u16::from_le_bytes(b.try_into().unwrap()).into());
+ let s = it.to_string();
+ if s.strip_prefix('-').unwrap_or(&s).chars().all(|c| c.is_ascii_digit()) {
+ // Match Rust debug formatting
+ write!(f, "{s}.0")
+ } else {
+ write!(f, "{s}")
+ }
+ }
chalk_ir::FloatTy::F32 => {
let it = f32::from_le_bytes(b.try_into().unwrap());
write!(f, "{it:?}")
@@ -553,6 +568,17 @@ fn render_const_scalar(
let it = f64::from_le_bytes(b.try_into().unwrap());
write!(f, "{it:?}")
}
+ chalk_ir::FloatTy::F128 => {
+ // FIXME(#17451): Replace with builtins once they are stabilised.
+ let it = f128::from_bits(u128::from_le_bytes(b.try_into().unwrap()));
+ let s = it.to_string();
+ if s.strip_prefix('-').unwrap_or(&s).chars().all(|c| c.is_ascii_digit()) {
+ // Match Rust debug formatting
+ write!(f, "{s}.0")
+ } else {
+ write!(f, "{s}")
+ }
+ }
},
},
TyKind::Ref(_, _, t) => match t.kind(Interner) {
@@ -988,7 +1014,8 @@ impl HirDisplay for Ty {
f.end_location_link();
if parameters.len(Interner) > 0 {
- let generics = generics(db.upcast(), def.into());
+ let generic_def_id = GenericDefId::from_callable(db.upcast(), def);
+ let generics = generics(db.upcast(), generic_def_id);
let (parent_len, self_param, type_, const_, impl_, lifetime) =
generics.provenance_split();
let parameters = parameters.as_slice(Interner);
@@ -1002,8 +1029,9 @@ impl HirDisplay for Ty {
debug_assert_eq!(parent_params.len(), parent_len);
let parent_params =
- generic_args_sans_defaults(f, Some(def.into()), parent_params);
- let fn_params = generic_args_sans_defaults(f, Some(def.into()), fn_params);
+ generic_args_sans_defaults(f, Some(generic_def_id), parent_params);
+ let fn_params =
+ generic_args_sans_defaults(f, Some(generic_def_id), fn_params);
write!(f, "<")?;
hir_fmt_generic_arguments(f, parent_params, None)?;
@@ -1041,7 +1069,11 @@ impl HirDisplay for Ty {
module_id,
PrefixKind::Plain,
false,
- ImportPathConfig { prefer_no_std: false, prefer_prelude: true },
+ ImportPathConfig {
+ prefer_no_std: false,
+ prefer_prelude: true,
+ prefer_absolute: false,
+ },
) {
write!(f, "{}", path.display(f.db.upcast()))?;
} else {