mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Add f16
and f128
support
This commit is contained in:
parent
da27b89ca5
commit
d5db933f9d
28 changed files with 384 additions and 73 deletions
|
@ -28,6 +28,10 @@ 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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue