diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-11 09:00:27 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-11 09:00:27 +0000 |
commit | 2ccc45979cd2057bb88e209474698090fb32bb40 (patch) | |
tree | b3cbebc3d63e1ab1af73cf17434809057a25ec6a /crates | |
parent | 113d7e44b7d4dee1be6a3d9fd8c724a3fff37b26 (diff) | |
parent | 5bb92c2d1af5f3045617a665d4e5c676700eb3c1 (diff) |
Merge #2209
2209: impl fmt::Display for BuiltinType r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/builtin_type.rs | 32 | ||||
-rw-r--r-- | crates/ra_ide_api/src/hover.rs | 8 |
2 files changed, 34 insertions, 6 deletions
diff --git a/crates/ra_hir_def/src/builtin_type.rs b/crates/ra_hir_def/src/builtin_type.rs index 12929caa9..2ec0c83fe 100644 --- a/crates/ra_hir_def/src/builtin_type.rs +++ b/crates/ra_hir_def/src/builtin_type.rs | |||
@@ -3,6 +3,8 @@ | |||
3 | //! A peculiarity of built-in types is that they are always available and are | 3 | //! A peculiarity of built-in types is that they are always available and are |
4 | //! not associated with any particular crate. | 4 | //! not associated with any particular crate. |
5 | 5 | ||
6 | use std::fmt; | ||
7 | |||
6 | use hir_expand::name::{self, Name}; | 8 | use hir_expand::name::{self, Name}; |
7 | 9 | ||
8 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | 10 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] |
@@ -61,3 +63,33 @@ impl BuiltinType { | |||
61 | (name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }), | 63 | (name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }), |
62 | ]; | 64 | ]; |
63 | } | 65 | } |
66 | |||
67 | impl fmt::Display for BuiltinType { | ||
68 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
69 | let type_name = match self { | ||
70 | BuiltinType::Char => "char", | ||
71 | BuiltinType::Bool => "bool", | ||
72 | BuiltinType::Str => "str", | ||
73 | BuiltinType::Int { signedness, bitness } => match (signedness, bitness) { | ||
74 | (Signedness::Signed, IntBitness::Xsize) => "isize", | ||
75 | (Signedness::Signed, IntBitness::X8) => "i8", | ||
76 | (Signedness::Signed, IntBitness::X16) => "i16", | ||
77 | (Signedness::Signed, IntBitness::X32) => "i32", | ||
78 | (Signedness::Signed, IntBitness::X64) => "i64", | ||
79 | (Signedness::Signed, IntBitness::X128) => "i128", | ||
80 | |||
81 | (Signedness::Unsigned, IntBitness::Xsize) => "usize", | ||
82 | (Signedness::Unsigned, IntBitness::X8) => "u8", | ||
83 | (Signedness::Unsigned, IntBitness::X16) => "u16", | ||
84 | (Signedness::Unsigned, IntBitness::X32) => "u32", | ||
85 | (Signedness::Unsigned, IntBitness::X64) => "u64", | ||
86 | (Signedness::Unsigned, IntBitness::X128) => "u128", | ||
87 | }, | ||
88 | BuiltinType::Float { bitness } => match bitness { | ||
89 | FloatBitness::X32 => "f32", | ||
90 | FloatBitness::X64 => "f64", | ||
91 | }, | ||
92 | }; | ||
93 | f.write_str(type_name) | ||
94 | } | ||
95 | } | ||
diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index 244c65814..cc41390b2 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{Adt, BuiltinType, HasSource, HirDisplay}; | 3 | use hir::{Adt, HasSource, HirDisplay}; |
4 | use ra_db::SourceDatabase; | 4 | use ra_db::SourceDatabase; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | algo::{ancestors_at_offset, find_covering_element, find_node_at_offset}, | 6 | 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 | |||
132 | hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), | 132 | hir::ModuleDef::Static(it) => res.extend(from_def_source(db, it)), |
133 | hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)), | 133 | hir::ModuleDef::Trait(it) => res.extend(from_def_source(db, it)), |
134 | hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), | 134 | hir::ModuleDef::TypeAlias(it) => res.extend(from_def_source(db, it)), |
135 | hir::ModuleDef::BuiltinType(it) => { | 135 | hir::ModuleDef::BuiltinType(it) => res.extend(Some(it.to_string())), |
136 | if let Some(b) = BuiltinType::ALL.iter().find(|(_, ty)| *ty == it) { | ||
137 | res.extend(Some(b.0.to_string())) | ||
138 | } | ||
139 | } | ||
140 | }, | 136 | }, |
141 | Some(SelfType(ty)) => { | 137 | Some(SelfType(ty)) => { |
142 | if let Some((adt_def, _)) = ty.as_adt() { | 138 | if let Some((adt_def, _)) = ty.as_adt() { |