add tests for primitive types
This commit is contained in:
parent
97158f5c8a
commit
c6ee9d681c
@ -1,6 +1,7 @@
|
|||||||
mod macros;
|
mod macros;
|
||||||
mod globs;
|
mod globs;
|
||||||
mod incremental;
|
mod incremental;
|
||||||
|
mod primitives;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
24
crates/ra_hir/src/nameres/tests/primitives.rs
Normal file
24
crates/ra_hir/src/nameres/tests/primitives.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn primitive_reexport() {
|
||||||
|
let map = def_map(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod foo;
|
||||||
|
use foo::int;
|
||||||
|
|
||||||
|
//- /foo.rs
|
||||||
|
pub use i32 as int;
|
||||||
|
",
|
||||||
|
);
|
||||||
|
assert_snapshot_matches!(map, @r###"
|
||||||
|
⋮crate
|
||||||
|
⋮foo: t
|
||||||
|
⋮int: t
|
||||||
|
⋮
|
||||||
|
⋮crate::foo
|
||||||
|
⋮int: t
|
||||||
|
"###
|
||||||
|
);
|
||||||
|
}
|
@ -12,7 +12,6 @@ use crate::{
|
|||||||
Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static,
|
Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static,
|
||||||
HirDatabase, BuiltinType,
|
HirDatabase, BuiltinType,
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
name::KnownName,
|
|
||||||
nameres::Namespace,
|
nameres::Namespace,
|
||||||
resolve::{Resolver, Resolution},
|
resolve::{Resolver, Resolution},
|
||||||
path::{PathSegment, GenericArg},
|
path::{PathSegment, GenericArg},
|
||||||
@ -22,7 +21,7 @@ use crate::{
|
|||||||
generics::{WherePredicate, GenericDef},
|
generics::{WherePredicate, GenericDef},
|
||||||
ty::AdtDef,
|
ty::AdtDef,
|
||||||
};
|
};
|
||||||
use super::{Ty, primitive, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate};
|
use super::{Ty, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate};
|
||||||
|
|
||||||
impl Ty {
|
impl Ty {
|
||||||
pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self {
|
pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self {
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use crate::{Name, KnownName};
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
||||||
pub enum Signedness {
|
pub enum Signedness {
|
||||||
Signed,
|
Signed,
|
||||||
@ -150,24 +148,6 @@ impl IntTy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_type_name(name: &Name) -> Option<IntTy> {
|
|
||||||
match name.as_known_name()? {
|
|
||||||
KnownName::Isize => Some(IntTy::isize()),
|
|
||||||
KnownName::I8 => Some(IntTy::i8()),
|
|
||||||
KnownName::I16 => Some(IntTy::i16()),
|
|
||||||
KnownName::I32 => Some(IntTy::i32()),
|
|
||||||
KnownName::I64 => Some(IntTy::i64()),
|
|
||||||
KnownName::I128 => Some(IntTy::i128()),
|
|
||||||
KnownName::Usize => Some(IntTy::usize()),
|
|
||||||
KnownName::U8 => Some(IntTy::u8()),
|
|
||||||
KnownName::U16 => Some(IntTy::u16()),
|
|
||||||
KnownName::U32 => Some(IntTy::u32()),
|
|
||||||
KnownName::U64 => Some(IntTy::u64()),
|
|
||||||
KnownName::U128 => Some(IntTy::u128()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_suffix(suffix: &str) -> Option<IntTy> {
|
pub(crate) fn from_suffix(suffix: &str) -> Option<IntTy> {
|
||||||
match suffix {
|
match suffix {
|
||||||
"isize" => Some(IntTy::isize()),
|
"isize" => Some(IntTy::isize()),
|
||||||
@ -220,14 +200,6 @@ impl FloatTy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_type_name(name: &Name) -> Option<FloatTy> {
|
|
||||||
match name.as_known_name()? {
|
|
||||||
KnownName::F32 => Some(FloatTy::f32()),
|
|
||||||
KnownName::F64 => Some(FloatTy::f64()),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_suffix(suffix: &str) -> Option<FloatTy> {
|
pub(crate) fn from_suffix(suffix: &str) -> Option<FloatTy> {
|
||||||
match suffix {
|
match suffix {
|
||||||
"f32" => Some(FloatTy::f32()),
|
"f32" => Some(FloatTy::f32()),
|
||||||
|
@ -2717,6 +2717,24 @@ fn test() { (S {}).method()<|>; }
|
|||||||
assert_eq!(t, "{unknown}");
|
assert_eq!(t, "{unknown}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shadowing_primitive() {
|
||||||
|
let t = type_at(
|
||||||
|
r#"
|
||||||
|
//- /main.rs
|
||||||
|
struct i32;
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
impl i32 { fn foo(&self) -> Foo { Foo } }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x: i32 = i32;
|
||||||
|
x.foo()<|>;
|
||||||
|
}"#,
|
||||||
|
);
|
||||||
|
assert_eq!(t, "Foo");
|
||||||
|
}
|
||||||
|
|
||||||
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
|
||||||
let file = db.parse(pos.file_id).ok().unwrap();
|
let file = db.parse(pos.file_id).ok().unwrap();
|
||||||
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
|
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user