aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-05-30 13:14:11 +0100
committerAleksey Kladov <[email protected]>2019-05-30 13:14:11 +0100
commitc6ee9d681c7c745e95f19badef271fec34ec2e36 (patch)
treeed0511c6c0927b14ea39bf9f34032260b588b2d4
parent97158f5c8a6dadf3bcf28601f739ab6b7c4464aa (diff)
add tests for primitive types
-rw-r--r--crates/ra_hir/src/nameres/tests.rs1
-rw-r--r--crates/ra_hir/src/nameres/tests/primitives.rs24
-rw-r--r--crates/ra_hir/src/ty/lower.rs3
-rw-r--r--crates/ra_hir/src/ty/primitive.rs28
-rw-r--r--crates/ra_hir/src/ty/tests.rs18
5 files changed, 44 insertions, 30 deletions
diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs
index ffb627c02..a15e62bbe 100644
--- a/crates/ra_hir/src/nameres/tests.rs
+++ b/crates/ra_hir/src/nameres/tests.rs
@@ -1,6 +1,7 @@
1mod macros; 1mod macros;
2mod globs; 2mod globs;
3mod incremental; 3mod incremental;
4mod primitives;
4 5
5use std::sync::Arc; 6use std::sync::Arc;
6 7
diff --git a/crates/ra_hir/src/nameres/tests/primitives.rs b/crates/ra_hir/src/nameres/tests/primitives.rs
new file mode 100644
index 000000000..734744835
--- /dev/null
+++ b/crates/ra_hir/src/nameres/tests/primitives.rs
@@ -0,0 +1,24 @@
1use super::*;
2
3#[test]
4fn primitive_reexport() {
5 let map = def_map(
6 "
7 //- /lib.rs
8 mod foo;
9 use foo::int;
10
11 //- /foo.rs
12 pub use i32 as int;
13 ",
14 );
15 assert_snapshot_matches!(map, @r###"
16 ⋮crate
17 ⋮foo: t
18 ⋮int: t
19
20 ⋮crate::foo
21 ⋮int: t
22 "###
23 );
24}
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index d2ba01826..71cd72234 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -12,7 +12,6 @@ use crate::{
12 Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static, 12 Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static,
13 HirDatabase, BuiltinType, 13 HirDatabase, BuiltinType,
14 type_ref::TypeRef, 14 type_ref::TypeRef,
15 name::KnownName,
16 nameres::Namespace, 15 nameres::Namespace,
17 resolve::{Resolver, Resolution}, 16 resolve::{Resolver, Resolution},
18 path::{PathSegment, GenericArg}, 17 path::{PathSegment, GenericArg},
@@ -22,7 +21,7 @@ use crate::{
22 generics::{WherePredicate, GenericDef}, 21 generics::{WherePredicate, GenericDef},
23 ty::AdtDef, 22 ty::AdtDef,
24}; 23};
25use super::{Ty, primitive, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate}; 24use super::{Ty, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate};
26 25
27impl Ty { 26impl Ty {
28 pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { 27 pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self {
diff --git a/crates/ra_hir/src/ty/primitive.rs b/crates/ra_hir/src/ty/primitive.rs
index e1ab16a6f..62b75b764 100644
--- a/crates/ra_hir/src/ty/primitive.rs
+++ b/crates/ra_hir/src/ty/primitive.rs
@@ -1,7 +1,5 @@
1use std::fmt; 1use std::fmt;
2 2
3use crate::{Name, KnownName};
4
5#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] 3#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
6pub enum Signedness { 4pub enum Signedness {
7 Signed, 5 Signed,
@@ -150,24 +148,6 @@ impl IntTy {
150 } 148 }
151 } 149 }
152 150
153 pub(crate) fn from_type_name(name: &Name) -> Option<IntTy> {
154 match name.as_known_name()? {
155 KnownName::Isize => Some(IntTy::isize()),
156 KnownName::I8 => Some(IntTy::i8()),
157 KnownName::I16 => Some(IntTy::i16()),
158 KnownName::I32 => Some(IntTy::i32()),
159 KnownName::I64 => Some(IntTy::i64()),
160 KnownName::I128 => Some(IntTy::i128()),
161 KnownName::Usize => Some(IntTy::usize()),
162 KnownName::U8 => Some(IntTy::u8()),
163 KnownName::U16 => Some(IntTy::u16()),
164 KnownName::U32 => Some(IntTy::u32()),
165 KnownName::U64 => Some(IntTy::u64()),
166 KnownName::U128 => Some(IntTy::u128()),
167 _ => None,
168 }
169 }
170
171 pub(crate) fn from_suffix(suffix: &str) -> Option<IntTy> { 151 pub(crate) fn from_suffix(suffix: &str) -> Option<IntTy> {
172 match suffix { 152 match suffix {
173 "isize" => Some(IntTy::isize()), 153 "isize" => Some(IntTy::isize()),
@@ -220,14 +200,6 @@ impl FloatTy {
220 } 200 }
221 } 201 }
222 202
223 pub(crate) fn from_type_name(name: &Name) -> Option<FloatTy> {
224 match name.as_known_name()? {
225 KnownName::F32 => Some(FloatTy::f32()),
226 KnownName::F64 => Some(FloatTy::f64()),
227 _ => None,
228 }
229 }
230
231 pub(crate) fn from_suffix(suffix: &str) -> Option<FloatTy> { 203 pub(crate) fn from_suffix(suffix: &str) -> Option<FloatTy> {
232 match suffix { 204 match suffix {
233 "f32" => Some(FloatTy::f32()), 205 "f32" => Some(FloatTy::f32()),
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index da9aeec6d..c34e89af7 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2717,6 +2717,24 @@ fn test() { (S {}).method()<|>; }
2717 assert_eq!(t, "{unknown}"); 2717 assert_eq!(t, "{unknown}");
2718} 2718}
2719 2719
2720#[test]
2721fn shadowing_primitive() {
2722 let t = type_at(
2723 r#"
2724//- /main.rs
2725struct i32;
2726struct Foo;
2727
2728impl i32 { fn foo(&self) -> Foo { Foo } }
2729
2730fn main() {
2731 let x: i32 = i32;
2732 x.foo()<|>;
2733}"#,
2734 );
2735 assert_eq!(t, "Foo");
2736}
2737
2720fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 2738fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
2721 let file = db.parse(pos.file_id).ok().unwrap(); 2739 let file = db.parse(pos.file_id).ok().unwrap();
2722 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); 2740 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();