diff options
author | Benjamin Coenen <[email protected]> | 2020-04-18 16:14:24 +0100 |
---|---|---|
committer | Benjamin Coenen <[email protected]> | 2020-04-18 16:14:24 +0100 |
commit | af3c19e85f55db9277ce9ad5b784df2ccfe3c9e4 (patch) | |
tree | 7a777f22f5fa79704b8d2c9aa8d67255d12123be /crates/ra_hir_def/src/builtin_type.rs | |
parent | 379787858bbfb2691e134942d94fcbc70c5d1d7f (diff) | |
parent | 84e3304a9bf0d68e30d58b1e37a6db2e9ec97525 (diff) |
Merge branch 'master' of github.com:rust-analyzer/rust-analyzer
Diffstat (limited to 'crates/ra_hir_def/src/builtin_type.rs')
-rw-r--r-- | crates/ra_hir_def/src/builtin_type.rs | 54 |
1 files changed, 30 insertions, 24 deletions
diff --git a/crates/ra_hir_def/src/builtin_type.rs b/crates/ra_hir_def/src/builtin_type.rs index d14901a9b..0f872b5c0 100644 --- a/crates/ra_hir_def/src/builtin_type.rs +++ b/crates/ra_hir_def/src/builtin_type.rs | |||
@@ -5,7 +5,7 @@ | |||
5 | 5 | ||
6 | use std::fmt; | 6 | use std::fmt; |
7 | 7 | ||
8 | use hir_expand::name::{name, Name}; | 8 | use hir_expand::name::{name, AsName, Name}; |
9 | 9 | ||
10 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] | 10 | #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] |
11 | pub enum Signedness { | 11 | pub enum Signedness { |
@@ -75,33 +75,39 @@ impl BuiltinType { | |||
75 | ]; | 75 | ]; |
76 | } | 76 | } |
77 | 77 | ||
78 | impl fmt::Display for BuiltinType { | 78 | impl AsName for BuiltinType { |
79 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 79 | fn as_name(&self) -> Name { |
80 | let type_name = match self { | 80 | match self { |
81 | BuiltinType::Char => "char", | 81 | BuiltinType::Char => name![char], |
82 | BuiltinType::Bool => "bool", | 82 | BuiltinType::Bool => name![bool], |
83 | BuiltinType::Str => "str", | 83 | BuiltinType::Str => name![str], |
84 | BuiltinType::Int(BuiltinInt { signedness, bitness }) => match (signedness, bitness) { | 84 | BuiltinType::Int(BuiltinInt { signedness, bitness }) => match (signedness, bitness) { |
85 | (Signedness::Signed, IntBitness::Xsize) => "isize", | 85 | (Signedness::Signed, IntBitness::Xsize) => name![isize], |
86 | (Signedness::Signed, IntBitness::X8) => "i8", | 86 | (Signedness::Signed, IntBitness::X8) => name![i8], |
87 | (Signedness::Signed, IntBitness::X16) => "i16", | 87 | (Signedness::Signed, IntBitness::X16) => name![i16], |
88 | (Signedness::Signed, IntBitness::X32) => "i32", | 88 | (Signedness::Signed, IntBitness::X32) => name![i32], |
89 | (Signedness::Signed, IntBitness::X64) => "i64", | 89 | (Signedness::Signed, IntBitness::X64) => name![i64], |
90 | (Signedness::Signed, IntBitness::X128) => "i128", | 90 | (Signedness::Signed, IntBitness::X128) => name![i128], |
91 | 91 | ||
92 | (Signedness::Unsigned, IntBitness::Xsize) => "usize", | 92 | (Signedness::Unsigned, IntBitness::Xsize) => name![usize], |
93 | (Signedness::Unsigned, IntBitness::X8) => "u8", | 93 | (Signedness::Unsigned, IntBitness::X8) => name![u8], |
94 | (Signedness::Unsigned, IntBitness::X16) => "u16", | 94 | (Signedness::Unsigned, IntBitness::X16) => name![u16], |
95 | (Signedness::Unsigned, IntBitness::X32) => "u32", | 95 | (Signedness::Unsigned, IntBitness::X32) => name![u32], |
96 | (Signedness::Unsigned, IntBitness::X64) => "u64", | 96 | (Signedness::Unsigned, IntBitness::X64) => name![u64], |
97 | (Signedness::Unsigned, IntBitness::X128) => "u128", | 97 | (Signedness::Unsigned, IntBitness::X128) => name![u128], |
98 | }, | 98 | }, |
99 | BuiltinType::Float(BuiltinFloat { bitness }) => match bitness { | 99 | BuiltinType::Float(BuiltinFloat { bitness }) => match bitness { |
100 | FloatBitness::X32 => "f32", | 100 | FloatBitness::X32 => name![f32], |
101 | FloatBitness::X64 => "f64", | 101 | FloatBitness::X64 => name![f64], |
102 | }, | 102 | }, |
103 | }; | 103 | } |
104 | f.write_str(type_name) | 104 | } |
105 | } | ||
106 | |||
107 | impl fmt::Display for BuiltinType { | ||
108 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
109 | let type_name = self.as_name(); | ||
110 | type_name.fmt(f) | ||
105 | } | 111 | } |
106 | } | 112 | } |
107 | 113 | ||