mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
move builtin types to hir_def
This commit is contained in:
parent
6f4d5f7339
commit
b20d37cb49
8 changed files with 88 additions and 78 deletions
|
@ -6,13 +6,11 @@ pub(crate) mod docs;
|
|||
use std::sync::Arc;
|
||||
|
||||
use hir_def::{
|
||||
builtin_type::BuiltinType,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
CrateModuleId, ModuleId,
|
||||
};
|
||||
use hir_expand::name::{
|
||||
self, AsName, BOOL, CHAR, F32, F64, I128, I16, I32, I64, I8, ISIZE, SELF_TYPE, STR, U128, U16,
|
||||
U32, U64, U8, USIZE,
|
||||
};
|
||||
use hir_expand::name::{self, AsName};
|
||||
use ra_db::{CrateId, Edition};
|
||||
use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner};
|
||||
|
||||
|
@ -30,10 +28,7 @@ use crate::{
|
|||
nameres::{ImportId, ModuleScope, Namespace},
|
||||
resolve::{Resolver, Scope, TypeNs},
|
||||
traits::TraitData,
|
||||
ty::{
|
||||
primitive::{FloatBitness, FloatTy, IntBitness, IntTy, Signedness},
|
||||
InferenceResult, TraitRef,
|
||||
},
|
||||
ty::{InferenceResult, TraitRef},
|
||||
Either, HasSource, Name, Ty,
|
||||
};
|
||||
|
||||
|
@ -87,41 +82,6 @@ pub struct Module {
|
|||
pub(crate) id: ModuleId,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum BuiltinType {
|
||||
Char,
|
||||
Bool,
|
||||
Str,
|
||||
Int(IntTy),
|
||||
Float(FloatTy),
|
||||
}
|
||||
|
||||
impl BuiltinType {
|
||||
#[rustfmt::skip]
|
||||
pub(crate) const ALL: &'static [(Name, BuiltinType)] = &[
|
||||
(CHAR, BuiltinType::Char),
|
||||
(BOOL, BuiltinType::Bool),
|
||||
(STR, BuiltinType::Str),
|
||||
|
||||
(ISIZE, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::Xsize })),
|
||||
(I8, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X8 })),
|
||||
(I16, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X16 })),
|
||||
(I32, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X32 })),
|
||||
(I64, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X64 })),
|
||||
(I128, BuiltinType::Int(IntTy { signedness: Signedness::Signed, bitness: IntBitness::X128 })),
|
||||
|
||||
(USIZE, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize })),
|
||||
(U8, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X8 })),
|
||||
(U16, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X16 })),
|
||||
(U32, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X32 })),
|
||||
(U64, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X64 })),
|
||||
(U128, BuiltinType::Int(IntTy { signedness: Signedness::Unsigned, bitness: IntBitness::X128 })),
|
||||
|
||||
(F32, BuiltinType::Float(FloatTy { bitness: FloatBitness::X32 })),
|
||||
(F64, BuiltinType::Float(FloatTy { bitness: FloatBitness::X64 })),
|
||||
];
|
||||
}
|
||||
|
||||
/// The defs which can be visible in the module.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum ModuleDef {
|
||||
|
@ -625,7 +585,7 @@ impl FnData {
|
|||
let self_type = if let Some(type_ref) = self_param.ascribed_type() {
|
||||
TypeRef::from_ast(type_ref)
|
||||
} else {
|
||||
let self_type = TypeRef::Path(SELF_TYPE.into());
|
||||
let self_type = TypeRef::Path(name::SELF_TYPE.into());
|
||||
match self_param.kind() {
|
||||
ast::SelfParamKind::Owned => self_type,
|
||||
ast::SelfParamKind::Ref => {
|
||||
|
|
|
@ -63,9 +63,9 @@ pub use crate::{
|
|||
code_model::{
|
||||
docs::{DocDef, Docs, Documentation},
|
||||
src::{HasBodySource, HasSource, Source},
|
||||
Adt, AssocItem, BuiltinType, Const, ConstData, Container, Crate, CrateDependency,
|
||||
DefWithBody, Enum, EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module,
|
||||
ModuleDef, ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
Adt, AssocItem, Const, ConstData, Container, Crate, CrateDependency, DefWithBody, Enum,
|
||||
EnumVariant, FieldSource, FnData, Function, HasBody, MacroDef, Module, ModuleDef,
|
||||
ModuleSource, Static, Struct, StructField, Trait, TypeAlias, Union,
|
||||
},
|
||||
expr::ExprScopes,
|
||||
from_source::FromSource,
|
||||
|
@ -81,6 +81,7 @@ pub use crate::{
|
|||
};
|
||||
|
||||
pub use hir_def::{
|
||||
builtin_type::BuiltinType,
|
||||
path::{Path, PathKind},
|
||||
type_ref::Mutability,
|
||||
};
|
||||
|
|
|
@ -54,7 +54,7 @@ mod tests;
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use hir_def::CrateModuleId;
|
||||
use hir_def::{builtin_type::BuiltinType, CrateModuleId};
|
||||
use once_cell::sync::Lazy;
|
||||
use ra_arena::Arena;
|
||||
use ra_db::{Edition, FileId};
|
||||
|
@ -68,8 +68,7 @@ use crate::{
|
|||
diagnostics::DiagnosticSink,
|
||||
ids::MacroDefId,
|
||||
nameres::diagnostics::DefDiagnostic,
|
||||
Adt, AstId, BuiltinType, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind,
|
||||
Trait,
|
||||
Adt, AstId, Crate, HirFileId, MacroDef, Module, ModuleDef, Name, Path, PathKind, Trait,
|
||||
};
|
||||
|
||||
pub use self::per_ns::{Namespace, PerNs};
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use hir_def::{
|
||||
builtin_type::BuiltinType,
|
||||
path::{Path, PathKind},
|
||||
CrateModuleId,
|
||||
};
|
||||
|
@ -18,8 +19,7 @@ use crate::{
|
|||
generics::GenericParams,
|
||||
impl_block::ImplBlock,
|
||||
nameres::{CrateDefMap, PerNs},
|
||||
Adt, BuiltinType, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct,
|
||||
Trait, TypeAlias,
|
||||
Adt, Const, Enum, EnumVariant, Function, MacroDef, ModuleDef, Static, Struct, Trait, TypeAlias,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::iter;
|
|||
use std::sync::Arc;
|
||||
|
||||
use hir_def::{
|
||||
builtin_type::BuiltinType,
|
||||
path::{GenericArg, PathSegment},
|
||||
type_ref::{TypeBound, TypeRef},
|
||||
};
|
||||
|
@ -24,10 +25,13 @@ use crate::{
|
|||
generics::{GenericDef, WherePredicate},
|
||||
nameres::Namespace,
|
||||
resolve::{Resolver, TypeNs},
|
||||
ty::Adt,
|
||||
ty::{
|
||||
primitive::{FloatTy, IntTy},
|
||||
Adt,
|
||||
},
|
||||
util::make_mut_slice,
|
||||
BuiltinType, Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField,
|
||||
Trait, TypeAlias, Union,
|
||||
Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait,
|
||||
TypeAlias, Union,
|
||||
};
|
||||
|
||||
impl Ty {
|
||||
|
@ -643,8 +647,10 @@ fn type_for_builtin(def: BuiltinType) -> Ty {
|
|||
BuiltinType::Char => TypeCtor::Char,
|
||||
BuiltinType::Bool => TypeCtor::Bool,
|
||||
BuiltinType::Str => TypeCtor::Str,
|
||||
BuiltinType::Int(ty) => TypeCtor::Int(ty.into()),
|
||||
BuiltinType::Float(ty) => TypeCtor::Float(ty.into()),
|
||||
BuiltinType::Int { signedness, bitness } => {
|
||||
TypeCtor::Int(IntTy { signedness, bitness }.into())
|
||||
}
|
||||
BuiltinType::Float { bitness } => TypeCtor::Float(FloatTy { bitness }.into()),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -2,27 +2,7 @@
|
|||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum Signedness {
|
||||
Signed,
|
||||
Unsigned,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum IntBitness {
|
||||
Xsize,
|
||||
X8,
|
||||
X16,
|
||||
X32,
|
||||
X64,
|
||||
X128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum FloatBitness {
|
||||
X32,
|
||||
X64,
|
||||
}
|
||||
pub use hir_def::builtin_type::{FloatBitness, IntBitness, Signedness};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum UncertainIntTy {
|
||||
|
|
63
crates/ra_hir_def/src/builtin_type.rs
Normal file
63
crates/ra_hir_def/src/builtin_type.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
//! This module defines built-in types.
|
||||
//!
|
||||
//! A peculiarity of built-in types is that they are always available and are
|
||||
//! not associated with any particular crate.
|
||||
|
||||
use hir_expand::name::{self, Name};
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum Signedness {
|
||||
Signed,
|
||||
Unsigned,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum IntBitness {
|
||||
Xsize,
|
||||
X8,
|
||||
X16,
|
||||
X32,
|
||||
X64,
|
||||
X128,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||
pub enum FloatBitness {
|
||||
X32,
|
||||
X64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum BuiltinType {
|
||||
Char,
|
||||
Bool,
|
||||
Str,
|
||||
Int { signedness: Signedness, bitness: IntBitness },
|
||||
Float { bitness: FloatBitness },
|
||||
}
|
||||
|
||||
impl BuiltinType {
|
||||
#[rustfmt::skip]
|
||||
pub const ALL: &'static [(Name, BuiltinType)] = &[
|
||||
(name::CHAR, BuiltinType::Char),
|
||||
(name::BOOL, BuiltinType::Bool),
|
||||
(name::STR, BuiltinType::Str ),
|
||||
|
||||
(name::ISIZE, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::Xsize }),
|
||||
(name::I8, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X8 }),
|
||||
(name::I16, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X16 }),
|
||||
(name::I32, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X32 }),
|
||||
(name::I64, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X64 }),
|
||||
(name::I128, BuiltinType::Int { signedness: Signedness::Signed, bitness: IntBitness::X128 }),
|
||||
|
||||
(name::USIZE, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::Xsize }),
|
||||
(name::U8, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X8 }),
|
||||
(name::U16, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X16 }),
|
||||
(name::U32, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X32 }),
|
||||
(name::U64, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X64 }),
|
||||
(name::U128, BuiltinType::Int { signedness: Signedness::Unsigned, bitness: IntBitness::X128 }),
|
||||
|
||||
(name::F32, BuiltinType::Float { bitness: FloatBitness::X32 }),
|
||||
(name::F64, BuiltinType::Float { bitness: FloatBitness::X64 }),
|
||||
];
|
||||
}
|
|
@ -11,6 +11,7 @@ pub mod db;
|
|||
pub mod attr;
|
||||
pub mod path;
|
||||
pub mod type_ref;
|
||||
pub mod builtin_type;
|
||||
|
||||
// FIXME: this should be private
|
||||
pub mod nameres;
|
||||
|
|
Loading…
Reference in a new issue