From c6ee9d681c7c745e95f19badef271fec34ec2e36 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 30 May 2019 15:14:11 +0300 Subject: add tests for primitive types --- crates/ra_hir/src/ty/lower.rs | 3 +-- crates/ra_hir/src/ty/primitive.rs | 28 ---------------------------- crates/ra_hir/src/ty/tests.rs | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 30 deletions(-) (limited to 'crates/ra_hir/src/ty') 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::{ Function, Struct, Union, StructField, Enum, EnumVariant, Path, ModuleDef, TypeAlias, Const, Static, HirDatabase, BuiltinType, type_ref::TypeRef, - name::KnownName, nameres::Namespace, resolve::{Resolver, Resolution}, path::{PathSegment, GenericArg}, @@ -22,7 +21,7 @@ use crate::{ generics::{WherePredicate, GenericDef}, ty::AdtDef, }; -use super::{Ty, primitive, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate}; +use super::{Ty, FnSig, Substs, TypeCtor, TraitRef, GenericPredicate}; impl Ty { 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 @@ use std::fmt; -use crate::{Name, KnownName}; - #[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Signedness { Signed, @@ -150,24 +148,6 @@ impl IntTy { } } - pub(crate) fn from_type_name(name: &Name) -> Option { - 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 { match suffix { "isize" => Some(IntTy::isize()), @@ -220,14 +200,6 @@ impl FloatTy { } } - pub(crate) fn from_type_name(name: &Name) -> Option { - match name.as_known_name()? { - KnownName::F32 => Some(FloatTy::f32()), - KnownName::F64 => Some(FloatTy::f64()), - _ => None, - } - } - pub(crate) fn from_suffix(suffix: &str) -> Option { match suffix { "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()<|>; } 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 { let file = db.parse(pos.file_id).ok().unwrap(); let expr = algo::find_node_at_offset::(file.syntax(), pos.offset).unwrap(); -- cgit v1.2.3