mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 14:43:58 +00:00
Minor refactoring
This commit is contained in:
parent
fc055281a5
commit
f5e1b0f97c
2 changed files with 32 additions and 21 deletions
|
@ -9,7 +9,7 @@ use std::iter;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
builtin_type::BuiltinType,
|
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinType},
|
||||||
path::{GenericArg, PathSegment},
|
path::{GenericArg, PathSegment},
|
||||||
type_ref::{TypeBound, TypeRef},
|
type_ref::{TypeBound, TypeRef},
|
||||||
};
|
};
|
||||||
|
@ -657,10 +657,10 @@ fn type_for_builtin(def: BuiltinType) -> Ty {
|
||||||
BuiltinType::Char => TypeCtor::Char,
|
BuiltinType::Char => TypeCtor::Char,
|
||||||
BuiltinType::Bool => TypeCtor::Bool,
|
BuiltinType::Bool => TypeCtor::Bool,
|
||||||
BuiltinType::Str => TypeCtor::Str,
|
BuiltinType::Str => TypeCtor::Str,
|
||||||
BuiltinType::Int { signedness, bitness } => {
|
BuiltinType::Int(BuiltinInt { signedness, bitness }) => {
|
||||||
TypeCtor::Int(IntTy { signedness, bitness }.into())
|
TypeCtor::Int(IntTy { signedness, bitness }.into())
|
||||||
}
|
}
|
||||||
BuiltinType::Float { bitness } => TypeCtor::Float(FloatTy { bitness }.into()),
|
BuiltinType::Float(BuiltinFloat { bitness }) => TypeCtor::Float(FloatTy { bitness }.into()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,24 @@ pub enum FloatBitness {
|
||||||
X64,
|
X64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct BuiltinInt {
|
||||||
|
pub signedness: Signedness,
|
||||||
|
pub bitness: IntBitness,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
|
pub struct BuiltinFloat {
|
||||||
|
pub bitness: FloatBitness,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum BuiltinType {
|
pub enum BuiltinType {
|
||||||
Char,
|
Char,
|
||||||
Bool,
|
Bool,
|
||||||
Str,
|
Str,
|
||||||
Int { signedness: Signedness, bitness: IntBitness },
|
Int(BuiltinInt),
|
||||||
Float { bitness: FloatBitness },
|
Float(BuiltinFloat),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuiltinType {
|
impl BuiltinType {
|
||||||
|
@ -45,22 +56,22 @@ impl BuiltinType {
|
||||||
(name::BOOL, BuiltinType::Bool),
|
(name::BOOL, BuiltinType::Bool),
|
||||||
(name::STR, BuiltinType::Str ),
|
(name::STR, BuiltinType::Str ),
|
||||||
|
|
||||||
(name::ISIZE, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::Xsize }),
|
(name::ISIZE, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::Xsize })),
|
||||||
(name::I8, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X8 }),
|
(name::I8, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X8 })),
|
||||||
(name::I16, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X16 }),
|
(name::I16, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X16 })),
|
||||||
(name::I32, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X32 }),
|
(name::I32, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X32 })),
|
||||||
(name::I64, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X64 }),
|
(name::I64, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X64 })),
|
||||||
(name::I128, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X128 }),
|
(name::I128, BuiltinType::Int(BuiltinInt { signedness: Signedness::Signed, bitness: IntBitness::X128 })),
|
||||||
|
|
||||||
(name::USIZE, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize }),
|
(name::USIZE, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })),
|
||||||
(name::U8, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X8 }),
|
(name::U8, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })),
|
||||||
(name::U16, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X16 }),
|
(name::U16, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })),
|
||||||
(name::U32, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X32 }),
|
(name::U32, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })),
|
||||||
(name::U64, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X64 }),
|
(name::U64, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })),
|
||||||
(name::U128, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X128 }),
|
(name::U128, BuiltinType::Int(BuiltinInt { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })),
|
||||||
|
|
||||||
(name::F32, BuiltinType::Float { bitness: FloatBitness::X32 }),
|
(name::F32, BuiltinType::Float(BuiltinFloat { bitness: FloatBitness::X32 })),
|
||||||
(name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }),
|
(name::F64, BuiltinType::Float(BuiltinFloat { bitness: FloatBitness::X64 })),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +81,7 @@ impl fmt::Display for BuiltinType {
|
||||||
BuiltinType::Char => "char",
|
BuiltinType::Char => "char",
|
||||||
BuiltinType::Bool => "bool",
|
BuiltinType::Bool => "bool",
|
||||||
BuiltinType::Str => "str",
|
BuiltinType::Str => "str",
|
||||||
BuiltinType::Int { signedness, bitness } => match (signedness, bitness) {
|
BuiltinType::Int(BuiltinInt { signedness, bitness }) => match (signedness, bitness) {
|
||||||
(Signedness::Signed, IntBitness::Xsize) => "isize",
|
(Signedness::Signed, IntBitness::Xsize) => "isize",
|
||||||
(Signedness::Signed, IntBitness::X8) => "i8",
|
(Signedness::Signed, IntBitness::X8) => "i8",
|
||||||
(Signedness::Signed, IntBitness::X16) => "i16",
|
(Signedness::Signed, IntBitness::X16) => "i16",
|
||||||
|
@ -85,7 +96,7 @@ impl fmt::Display for BuiltinType {
|
||||||
(Signedness::Unsigned, IntBitness::X64) => "u64",
|
(Signedness::Unsigned, IntBitness::X64) => "u64",
|
||||||
(Signedness::Unsigned, IntBitness::X128) => "u128",
|
(Signedness::Unsigned, IntBitness::X128) => "u128",
|
||||||
},
|
},
|
||||||
BuiltinType::Float { bitness } => match bitness {
|
BuiltinType::Float(BuiltinFloat { bitness }) => match bitness {
|
||||||
FloatBitness::X32 => "f32",
|
FloatBitness::X32 => "f32",
|
||||||
FloatBitness::X64 => "f64",
|
FloatBitness::X64 => "f64",
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue