aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r--crates/ra_hir/src/ty/infer/expr.rs6
-rw-r--r--crates/ra_hir/src/ty/infer/path.rs4
-rw-r--r--crates/ra_hir/src/ty/lower.rs15
-rw-r--r--crates/ra_hir/src/ty/tests.rs32
-rw-r--r--crates/ra_hir/src/ty/traits/chalk.rs7
5 files changed, 39 insertions, 25 deletions
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs
index a09ef5c5d..4af1d65ee 100644
--- a/crates/ra_hir/src/ty/infer/expr.rs
+++ b/crates/ra_hir/src/ty/infer/expr.rs
@@ -12,10 +12,10 @@ use crate::{
12 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp}, 12 expr::{self, Array, BinaryOp, Expr, ExprId, Literal, Statement, UnaryOp},
13 generics::{GenericParams, HasGenericParams}, 13 generics::{GenericParams, HasGenericParams},
14 ty::{ 14 ty::{
15 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, 15 autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Namespace,
16 ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, 16 Obligation, ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk,
17 }, 17 },
18 Adt, Name, Namespace, 18 Adt, Name,
19}; 19};
20 20
21impl<'a, D: HirDatabase> InferenceContext<'a, D> { 21impl<'a, D: HirDatabase> InferenceContext<'a, D> {
diff --git a/crates/ra_hir/src/ty/infer/path.rs b/crates/ra_hir/src/ty/infer/path.rs
index 59b7f7eb6..865ced5a1 100644
--- a/crates/ra_hir/src/ty/infer/path.rs
+++ b/crates/ra_hir/src/ty/infer/path.rs
@@ -6,8 +6,8 @@ use super::{ExprOrPatId, InferenceContext, TraitRef};
6use crate::{ 6use crate::{
7 db::HirDatabase, 7 db::HirDatabase,
8 resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs}, 8 resolve::{ResolveValueResult, Resolver, TypeNs, ValueNs},
9 ty::{method_resolution, Substs, Ty, TypableDef, TypeWalk}, 9 ty::{method_resolution, Namespace, Substs, Ty, TypableDef, TypeWalk},
10 AssocItem, Container, HasGenericParams, Name, Namespace, Path, 10 AssocItem, Container, HasGenericParams, Name, Path,
11}; 11};
12 12
13impl<'a, D: HirDatabase> InferenceContext<'a, D> { 13impl<'a, D: HirDatabase> InferenceContext<'a, D> {
diff --git a/crates/ra_hir/src/ty/lower.rs b/crates/ra_hir/src/ty/lower.rs
index e29ab8492..d26b16cb2 100644
--- a/crates/ra_hir/src/ty/lower.rs
+++ b/crates/ra_hir/src/ty/lower.rs
@@ -29,10 +29,21 @@ use crate::{
29 Adt, 29 Adt,
30 }, 30 },
31 util::make_mut_slice, 31 util::make_mut_slice,
32 Const, Enum, EnumVariant, Function, ModuleDef, Namespace, Path, Static, Struct, StructField, 32 Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait,
33 Trait, TypeAlias, Union, 33 TypeAlias, Union,
34}; 34};
35 35
36// FIXME: this is only really used in `type_for_def`, which contains a bunch of
37// impossible cases. Perhaps we should recombine `TypeableDef` and `Namespace`
38// into a `AsTypeDef`, `AsValueDef` enums?
39#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
40pub enum Namespace {
41 Types,
42 Values,
43 // Note that only type inference uses this enum, and it doesn't care about macros.
44 // Macro,
45}
46
36impl Ty { 47impl Ty {
37 pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self { 48 pub(crate) fn from_hir(db: &impl HirDatabase, resolver: &Resolver, type_ref: &TypeRef) -> Self {
38 match type_ref { 49 match type_ref {
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 4b7e34878..e56b9356e 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -11,7 +11,7 @@ use ra_syntax::{
11use test_utils::covers; 11use test_utils::covers;
12 12
13use crate::{ 13use crate::{
14 expr::BodySourceMap, mock::MockDatabase, ty::display::HirDisplay, ty::InferenceResult, 14 expr::BodySourceMap, test_db::TestDB, ty::display::HirDisplay, ty::InferenceResult,
15 SourceAnalyzer, 15 SourceAnalyzer,
16}; 16};
17 17
@@ -24,7 +24,7 @@ mod coercion;
24 24
25#[test] 25#[test]
26fn cfg_impl_block() { 26fn cfg_impl_block() {
27 let (db, pos) = MockDatabase::with_position( 27 let (db, pos) = TestDB::with_position(
28 r#" 28 r#"
29//- /main.rs crate:main deps:foo cfg:test 29//- /main.rs crate:main deps:foo cfg:test
30use foo::S as T; 30use foo::S as T;
@@ -64,7 +64,7 @@ impl S {
64 64
65#[test] 65#[test]
66fn infer_await() { 66fn infer_await() {
67 let (db, pos) = MockDatabase::with_position( 67 let (db, pos) = TestDB::with_position(
68 r#" 68 r#"
69//- /main.rs crate:main deps:std 69//- /main.rs crate:main deps:std
70 70
@@ -95,7 +95,7 @@ mod future {
95 95
96#[test] 96#[test]
97fn infer_box() { 97fn infer_box() {
98 let (db, pos) = MockDatabase::with_position( 98 let (db, pos) = TestDB::with_position(
99 r#" 99 r#"
100//- /main.rs crate:main deps:std 100//- /main.rs crate:main deps:std
101 101
@@ -122,7 +122,7 @@ mod boxed {
122 122
123#[test] 123#[test]
124fn infer_adt_self() { 124fn infer_adt_self() {
125 let (db, pos) = MockDatabase::with_position( 125 let (db, pos) = TestDB::with_position(
126 r#" 126 r#"
127//- /main.rs 127//- /main.rs
128enum Nat { Succ(Self), Demo(Nat), Zero } 128enum Nat { Succ(Self), Demo(Nat), Zero }
@@ -141,7 +141,7 @@ fn test() {
141 141
142#[test] 142#[test]
143fn infer_try() { 143fn infer_try() {
144 let (db, pos) = MockDatabase::with_position( 144 let (db, pos) = TestDB::with_position(
145 r#" 145 r#"
146//- /main.rs crate:main deps:std 146//- /main.rs crate:main deps:std
147 147
@@ -181,7 +181,7 @@ mod result {
181 181
182#[test] 182#[test]
183fn infer_for_loop() { 183fn infer_for_loop() {
184 let (db, pos) = MockDatabase::with_position( 184 let (db, pos) = TestDB::with_position(
185 r#" 185 r#"
186//- /main.rs crate:main deps:std 186//- /main.rs crate:main deps:std
187 187
@@ -223,7 +223,7 @@ mod collections {
223#[test] 223#[test]
224fn infer_while_let() { 224fn infer_while_let() {
225 covers!(infer_while_let); 225 covers!(infer_while_let);
226 let (db, pos) = MockDatabase::with_position( 226 let (db, pos) = TestDB::with_position(
227 r#" 227 r#"
228//- /main.rs 228//- /main.rs
229enum Option<T> { Some(T), None } 229enum Option<T> { Some(T), None }
@@ -2484,7 +2484,7 @@ pub fn main_loop() {
2484 2484
2485#[test] 2485#[test]
2486fn cross_crate_associated_method_call() { 2486fn cross_crate_associated_method_call() {
2487 let (db, pos) = MockDatabase::with_position( 2487 let (db, pos) = TestDB::with_position(
2488 r#" 2488 r#"
2489//- /main.rs crate:main deps:other_crate 2489//- /main.rs crate:main deps:other_crate
2490fn test() { 2490fn test() {
@@ -3378,7 +3378,7 @@ fn test() { S.foo()<|>; }
3378 3378
3379#[test] 3379#[test]
3380fn infer_macro_with_dollar_crate_is_correct_in_expr() { 3380fn infer_macro_with_dollar_crate_is_correct_in_expr() {
3381 let (db, pos) = MockDatabase::with_position( 3381 let (db, pos) = TestDB::with_position(
3382 r#" 3382 r#"
3383//- /main.rs crate:main deps:foo 3383//- /main.rs crate:main deps:foo
3384fn test() { 3384fn test() {
@@ -3482,7 +3482,7 @@ fn test() { (&S).foo()<|>; }
3482 3482
3483#[test] 3483#[test]
3484fn method_resolution_trait_from_prelude() { 3484fn method_resolution_trait_from_prelude() {
3485 let (db, pos) = MockDatabase::with_position( 3485 let (db, pos) = TestDB::with_position(
3486 r#" 3486 r#"
3487//- /main.rs crate:main deps:other_crate 3487//- /main.rs crate:main deps:other_crate
3488struct S; 3488struct S;
@@ -4651,7 +4651,7 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
4651 assert_eq!(t, "{unknown}"); 4651 assert_eq!(t, "{unknown}");
4652} 4652}
4653 4653
4654fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { 4654fn type_at_pos(db: &TestDB, pos: FilePosition) -> String {
4655 let file = db.parse(pos.file_id).ok().unwrap(); 4655 let file = db.parse(pos.file_id).ok().unwrap();
4656 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap(); 4656 let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();
4657 let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset)); 4657 let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset));
@@ -4660,12 +4660,12 @@ fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
4660} 4660}
4661 4661
4662fn type_at(content: &str) -> String { 4662fn type_at(content: &str) -> String {
4663 let (db, file_pos) = MockDatabase::with_position(content); 4663 let (db, file_pos) = TestDB::with_position(content);
4664 type_at_pos(&db, file_pos) 4664 type_at_pos(&db, file_pos)
4665} 4665}
4666 4666
4667fn infer(content: &str) -> String { 4667fn infer(content: &str) -> String {
4668 let (db, _, file_id) = MockDatabase::with_single_file(content); 4668 let (db, file_id) = TestDB::with_single_file(content);
4669 let source_file = db.parse(file_id).ok().unwrap(); 4669 let source_file = db.parse(file_id).ok().unwrap();
4670 4670
4671 let mut acc = String::new(); 4671 let mut acc = String::new();
@@ -4748,7 +4748,7 @@ fn ellipsize(mut text: String, max_len: usize) -> String {
4748 4748
4749#[test] 4749#[test]
4750fn typing_whitespace_inside_a_function_should_not_invalidate_types() { 4750fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
4751 let (mut db, pos) = MockDatabase::with_position( 4751 let (mut db, pos) = TestDB::with_position(
4752 " 4752 "
4753 //- /lib.rs 4753 //- /lib.rs
4754 fn foo() -> i32 { 4754 fn foo() -> i32 {
@@ -4788,7 +4788,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
4788 4788
4789#[test] 4789#[test]
4790fn no_such_field_diagnostics() { 4790fn no_such_field_diagnostics() {
4791 let diagnostics = MockDatabase::with_files( 4791 let diagnostics = TestDB::with_files(
4792 r" 4792 r"
4793 //- /lib.rs 4793 //- /lib.rs
4794 struct S { foo: i32, bar: () } 4794 struct S { foo: i32, bar: () }
diff --git a/crates/ra_hir/src/ty/traits/chalk.rs b/crates/ra_hir/src/ty/traits/chalk.rs
index 39ef92182..c694952f3 100644
--- a/crates/ra_hir/src/ty/traits/chalk.rs
+++ b/crates/ra_hir/src/ty/traits/chalk.rs
@@ -18,7 +18,10 @@ use crate::{
18 db::HirDatabase, 18 db::HirDatabase,
19 generics::GenericDef, 19 generics::GenericDef,
20 ty::display::HirDisplay, 20 ty::display::HirDisplay,
21 ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk}, 21 ty::{
22 ApplicationTy, GenericPredicate, Namespace, ProjectionTy, Substs, TraitRef, Ty, TypeCtor,
23 TypeWalk,
24 },
22 AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias, 25 AssocItem, Crate, HasGenericParams, ImplBlock, Trait, TypeAlias,
23}; 26};
24 27
@@ -652,7 +655,7 @@ fn impl_block_datum(
652 }) 655 })
653 .filter_map(|t| { 656 .filter_map(|t| {
654 let assoc_ty = trait_.associated_type_by_name(db, &t.name(db))?; 657 let assoc_ty = trait_.associated_type_by_name(db, &t.name(db))?;
655 let ty = db.type_for_def(t.into(), crate::Namespace::Types).subst(&bound_vars); 658 let ty = db.type_for_def(t.into(), Namespace::Types).subst(&bound_vars);
656 Some(chalk_rust_ir::AssociatedTyValue { 659 Some(chalk_rust_ir::AssociatedTyValue {
657 impl_id, 660 impl_id,
658 associated_ty_id: assoc_ty.to_chalk(db), 661 associated_ty_id: assoc_ty.to_chalk(db),