mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-23 20:34:06 +00:00
impl fmt::Display for BuiltinType
This commit is contained in:
parent
113d7e44b7
commit
5bb92c2d1a
@ -3,6 +3,8 @@
|
||||
//! A peculiarity of built-in types is that they are always available and are
|
||||
//! not associated with any particular crate.
|
||||
|
||||
use std::fmt;
|
||||
|
||||
use hir_expand::name::{self, Name};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
@ -61,3 +63,33 @@ impl BuiltinType {
|
||||
(name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }),
|
||||
];
|
||||
}
|
||||
|
||||
impl fmt::Display for BuiltinType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let type_name = match self {
|
||||
BuiltinType::Char => "char",
|
||||
BuiltinType::Bool => "bool",
|
||||
BuiltinType::Str => "str",
|
||||
BuiltinType::Int { signedness, bitness } => match (signedness, bitness) {
|
||||
(Signedness::Signed, IntBitness::Xsize) => "isize",
|
||||
(Signedness::Signed, IntBitness::X8) => "i8",
|
||||
(Signedness::Signed, IntBitness::X16) => "i16",
|
||||
(Signedness::Signed, IntBitness::X32) => "i32",
|
||||
(Signedness::Signed, IntBitness::X64) => "i64",
|
||||
(Signedness::Signed, IntBitness::X128) => "i128",
|
||||
|
||||
(Signedness::Unsigned, IntBitness::Xsize) => "usize",
|
||||
(Signedness::Unsigned, IntBitness::X8) => "u8",
|
||||
(Signedness::Unsigned, IntBitness::X16) => "u16",
|
||||
(Signedness::Unsigned, IntBitness::X32) => "u32",
|
||||
(Signedness::Unsigned, IntBitness::X64) => "u64",
|
||||
(Signedness::Unsigned, IntBitness::X128) => "u128",
|
||||
},
|
||||
BuiltinType::Float { bitness } => match bitness {
|
||||
FloatBitness::X32 => "f32",
|
||||
FloatBitness::X64 => "f64",
|
||||
},
|
||||
};
|
||||
f.write_str(type_name)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
use hir::{Adt, BuiltinType, HasSource, HirDisplay};
|
||||
use hir::{Adt, HasSource, HirDisplay};
|
||||
use ra_db::SourceDatabase;
|
||||
use ra_syntax::{
|
||||
algo::{ancestors_at_offset, find_covering_element, find_node_at_offset},
|
||||
@ -132,11 +132,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
|
||||
hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)),
|
||||
hir::ModuleDef::BuiltinType(it) => {
|
||||
if let Some(b) = BuiltinType::ALL.iter().find(|(_, ty)| *ty == it) {
|
||||
res.extend(Some(b.0.to_string()))
|
||||
}
|
||||
}
|
||||
hir::ModuleDef::BuiltinType(it) => res.extend(Some(it.to_string())),
|
||||
},
|
||||
Some(SelfType(ty)) => {
|
||||
if let Some((adt_def, _)) = ty.as_adt() {
|
||||
|
Loading…
Reference in New Issue
Block a user