diff options
Diffstat (limited to 'crates/ra_hir/src/ty')
-rw-r--r-- | crates/ra_hir/src/ty/infer.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/infer/expr.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/lower.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 84 |
4 files changed, 32 insertions, 72 deletions
diff --git a/crates/ra_hir/src/ty/infer.rs b/crates/ra_hir/src/ty/infer.rs index 6694467a3..2370e8d4f 100644 --- a/crates/ra_hir/src/ty/infer.rs +++ b/crates/ra_hir/src/ty/infer.rs | |||
@@ -25,7 +25,7 @@ use hir_def::{ | |||
25 | path::known, | 25 | path::known, |
26 | type_ref::{Mutability, TypeRef}, | 26 | type_ref::{Mutability, TypeRef}, |
27 | }; | 27 | }; |
28 | use hir_expand::name; | 28 | use hir_expand::{diagnostics::DiagnosticSink, name}; |
29 | use ra_arena::map::ArenaMap; | 29 | use ra_arena::map::ArenaMap; |
30 | use ra_prof::profile; | 30 | use ra_prof::profile; |
31 | use test_utils::tested_by; | 31 | use test_utils::tested_by; |
@@ -40,7 +40,6 @@ use crate::{ | |||
40 | adt::VariantDef, | 40 | adt::VariantDef, |
41 | code_model::TypeAlias, | 41 | code_model::TypeAlias, |
42 | db::HirDatabase, | 42 | db::HirDatabase, |
43 | diagnostics::DiagnosticSink, | ||
44 | expr::{BindingAnnotation, Body, ExprId, PatId}, | 43 | expr::{BindingAnnotation, Body, ExprId, PatId}, |
45 | resolve::{Resolver, TypeNs}, | 44 | resolve::{Resolver, TypeNs}, |
46 | ty::infer::diagnostics::InferenceDiagnostic, | 45 | ty::infer::diagnostics::InferenceDiagnostic, |
@@ -719,12 +718,9 @@ impl Expectation { | |||
719 | } | 718 | } |
720 | 719 | ||
721 | mod diagnostics { | 720 | mod diagnostics { |
722 | use crate::{ | 721 | use hir_expand::diagnostics::DiagnosticSink; |
723 | db::HirDatabase, | 722 | |
724 | diagnostics::{DiagnosticSink, NoSuchField}, | 723 | use crate::{db::HirDatabase, diagnostics::NoSuchField, expr::ExprId, Function, HasSource}; |
725 | expr::ExprId, | ||
726 | Function, HasSource, | ||
727 | }; | ||
728 | 724 | ||
729 | #[derive(Debug, PartialEq, Eq, Clone)] | 725 | #[derive(Debug, PartialEq, Eq, Clone)] |
730 | pub(super) enum InferenceDiagnostic { | 726 | pub(super) enum InferenceDiagnostic { |
diff --git a/crates/ra_hir/src/ty/infer/expr.rs b/crates/ra_hir/src/ty/infer/expr.rs index fed52df39..a09ef5c5d 100644 --- a/crates/ra_hir/src/ty/infer/expr.rs +++ b/crates/ra_hir/src/ty/infer/expr.rs | |||
@@ -11,12 +11,11 @@ use crate::{ | |||
11 | db::HirDatabase, | 11 | db::HirDatabase, |
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 | nameres::Namespace, | ||
15 | ty::{ | 14 | ty::{ |
16 | autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, | 15 | autoderef, method_resolution, op, primitive, CallableDef, InferTy, Mutability, Obligation, |
17 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, | 16 | ProjectionPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk, |
18 | }, | 17 | }, |
19 | Adt, Name, | 18 | Adt, Name, Namespace, |
20 | }; | 19 | }; |
21 | 20 | ||
22 | impl<'a, D: HirDatabase> InferenceContext<'a, D> { | 21 | impl<'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 8e2834307..e29ab8492 100644 --- a/crates/ra_hir/src/ty/lower.rs +++ b/crates/ra_hir/src/ty/lower.rs | |||
@@ -23,15 +23,14 @@ use crate::{ | |||
23 | db::HirDatabase, | 23 | db::HirDatabase, |
24 | generics::HasGenericParams, | 24 | generics::HasGenericParams, |
25 | generics::{GenericDef, WherePredicate}, | 25 | generics::{GenericDef, WherePredicate}, |
26 | nameres::Namespace, | ||
27 | resolve::{Resolver, TypeNs}, | 26 | resolve::{Resolver, TypeNs}, |
28 | ty::{ | 27 | ty::{ |
29 | primitive::{FloatTy, IntTy}, | 28 | primitive::{FloatTy, IntTy}, |
30 | Adt, | 29 | Adt, |
31 | }, | 30 | }, |
32 | util::make_mut_slice, | 31 | util::make_mut_slice, |
33 | Const, Enum, EnumVariant, Function, ModuleDef, Path, Static, Struct, StructField, Trait, | 32 | Const, Enum, EnumVariant, Function, ModuleDef, Namespace, Path, Static, Struct, StructField, |
34 | TypeAlias, Union, | 33 | Trait, TypeAlias, Union, |
35 | }; | 34 | }; |
36 | 35 | ||
37 | impl Ty { | 36 | impl Ty { |
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index bfef48b16..4b7e34878 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -2,8 +2,7 @@ use std::fmt::Write; | |||
2 | use std::sync::Arc; | 2 | use std::sync::Arc; |
3 | 3 | ||
4 | use insta::assert_snapshot; | 4 | use insta::assert_snapshot; |
5 | 5 | use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase}; | |
6 | use ra_db::{salsa::Database, FilePosition, SourceDatabase}; | ||
7 | use ra_syntax::{ | 6 | use ra_syntax::{ |
8 | algo, | 7 | algo, |
9 | ast::{self, AstNode}, | 8 | ast::{self, AstNode}, |
@@ -25,9 +24,9 @@ mod coercion; | |||
25 | 24 | ||
26 | #[test] | 25 | #[test] |
27 | fn cfg_impl_block() { | 26 | fn cfg_impl_block() { |
28 | let (mut db, pos) = MockDatabase::with_position( | 27 | let (db, pos) = MockDatabase::with_position( |
29 | r#" | 28 | r#" |
30 | //- /main.rs | 29 | //- /main.rs crate:main deps:foo cfg:test |
31 | use foo::S as T; | 30 | use foo::S as T; |
32 | struct S; | 31 | struct S; |
33 | 32 | ||
@@ -46,7 +45,7 @@ fn test() { | |||
46 | t<|>; | 45 | t<|>; |
47 | } | 46 | } |
48 | 47 | ||
49 | //- /foo.rs | 48 | //- /foo.rs crate:foo |
50 | struct S; | 49 | struct S; |
51 | 50 | ||
52 | #[cfg(not(test))] | 51 | #[cfg(not(test))] |
@@ -60,18 +59,14 @@ impl S { | |||
60 | } | 59 | } |
61 | "#, | 60 | "#, |
62 | ); | 61 | ); |
63 | db.set_crate_graph_from_fixture(crate_graph! { | ||
64 | "main": ("/main.rs", ["foo"], cfg = { "test" }), | ||
65 | "foo": ("/foo.rs", []), | ||
66 | }); | ||
67 | assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos)); | 62 | assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos)); |
68 | } | 63 | } |
69 | 64 | ||
70 | #[test] | 65 | #[test] |
71 | fn infer_await() { | 66 | fn infer_await() { |
72 | let (mut db, pos) = MockDatabase::with_position( | 67 | let (db, pos) = MockDatabase::with_position( |
73 | r#" | 68 | r#" |
74 | //- /main.rs | 69 | //- /main.rs crate:main deps:std |
75 | 70 | ||
76 | struct IntFuture; | 71 | struct IntFuture; |
77 | 72 | ||
@@ -85,7 +80,7 @@ fn test() { | |||
85 | v<|>; | 80 | v<|>; |
86 | } | 81 | } |
87 | 82 | ||
88 | //- /std.rs | 83 | //- /std.rs crate:std |
89 | #[prelude_import] use future::*; | 84 | #[prelude_import] use future::*; |
90 | mod future { | 85 | mod future { |
91 | trait Future { | 86 | trait Future { |
@@ -95,18 +90,14 @@ mod future { | |||
95 | 90 | ||
96 | "#, | 91 | "#, |
97 | ); | 92 | ); |
98 | db.set_crate_graph_from_fixture(crate_graph! { | ||
99 | "main": ("/main.rs", ["std"]), | ||
100 | "std": ("/std.rs", []), | ||
101 | }); | ||
102 | assert_eq!("u64", type_at_pos(&db, pos)); | 93 | assert_eq!("u64", type_at_pos(&db, pos)); |
103 | } | 94 | } |
104 | 95 | ||
105 | #[test] | 96 | #[test] |
106 | fn infer_box() { | 97 | fn infer_box() { |
107 | let (mut db, pos) = MockDatabase::with_position( | 98 | let (db, pos) = MockDatabase::with_position( |
108 | r#" | 99 | r#" |
109 | //- /main.rs | 100 | //- /main.rs crate:main deps:std |
110 | 101 | ||
111 | fn test() { | 102 | fn test() { |
112 | let x = box 1; | 103 | let x = box 1; |
@@ -114,7 +105,7 @@ fn test() { | |||
114 | t<|>; | 105 | t<|>; |
115 | } | 106 | } |
116 | 107 | ||
117 | //- /std.rs | 108 | //- /std.rs crate:std |
118 | #[prelude_import] use prelude::*; | 109 | #[prelude_import] use prelude::*; |
119 | mod prelude {} | 110 | mod prelude {} |
120 | 111 | ||
@@ -126,10 +117,6 @@ mod boxed { | |||
126 | 117 | ||
127 | "#, | 118 | "#, |
128 | ); | 119 | ); |
129 | db.set_crate_graph_from_fixture(crate_graph! { | ||
130 | "main": ("/main.rs", ["std"]), | ||
131 | "std": ("/std.rs", []), | ||
132 | }); | ||
133 | assert_eq!("(Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32;_]>)", type_at_pos(&db, pos)); | 120 | assert_eq!("(Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32;_]>)", type_at_pos(&db, pos)); |
134 | } | 121 | } |
135 | 122 | ||
@@ -154,9 +141,9 @@ fn test() { | |||
154 | 141 | ||
155 | #[test] | 142 | #[test] |
156 | fn infer_try() { | 143 | fn infer_try() { |
157 | let (mut db, pos) = MockDatabase::with_position( | 144 | let (db, pos) = MockDatabase::with_position( |
158 | r#" | 145 | r#" |
159 | //- /main.rs | 146 | //- /main.rs crate:main deps:std |
160 | 147 | ||
161 | fn test() { | 148 | fn test() { |
162 | let r: Result<i32, u64> = Result::Ok(1); | 149 | let r: Result<i32, u64> = Result::Ok(1); |
@@ -164,7 +151,7 @@ fn test() { | |||
164 | v<|>; | 151 | v<|>; |
165 | } | 152 | } |
166 | 153 | ||
167 | //- /std.rs | 154 | //- /std.rs crate:std |
168 | 155 | ||
169 | #[prelude_import] use ops::*; | 156 | #[prelude_import] use ops::*; |
170 | mod ops { | 157 | mod ops { |
@@ -189,18 +176,14 @@ mod result { | |||
189 | 176 | ||
190 | "#, | 177 | "#, |
191 | ); | 178 | ); |
192 | db.set_crate_graph_from_fixture(crate_graph! { | ||
193 | "main": ("/main.rs", ["std"]), | ||
194 | "std": ("/std.rs", []), | ||
195 | }); | ||
196 | assert_eq!("i32", type_at_pos(&db, pos)); | 179 | assert_eq!("i32", type_at_pos(&db, pos)); |
197 | } | 180 | } |
198 | 181 | ||
199 | #[test] | 182 | #[test] |
200 | fn infer_for_loop() { | 183 | fn infer_for_loop() { |
201 | let (mut db, pos) = MockDatabase::with_position( | 184 | let (db, pos) = MockDatabase::with_position( |
202 | r#" | 185 | r#" |
203 | //- /main.rs | 186 | //- /main.rs crate:main deps:std |
204 | 187 | ||
205 | use std::collections::Vec; | 188 | use std::collections::Vec; |
206 | 189 | ||
@@ -212,7 +195,7 @@ fn test() { | |||
212 | } | 195 | } |
213 | } | 196 | } |
214 | 197 | ||
215 | //- /std.rs | 198 | //- /std.rs crate:std |
216 | 199 | ||
217 | #[prelude_import] use iter::*; | 200 | #[prelude_import] use iter::*; |
218 | mod iter { | 201 | mod iter { |
@@ -234,10 +217,6 @@ mod collections { | |||
234 | } | 217 | } |
235 | "#, | 218 | "#, |
236 | ); | 219 | ); |
237 | db.set_crate_graph_from_fixture(crate_graph! { | ||
238 | "main": ("/main.rs", ["std"]), | ||
239 | "std": ("/std.rs", []), | ||
240 | }); | ||
241 | assert_eq!("&str", type_at_pos(&db, pos)); | 220 | assert_eq!("&str", type_at_pos(&db, pos)); |
242 | } | 221 | } |
243 | 222 | ||
@@ -2505,15 +2484,15 @@ pub fn main_loop() { | |||
2505 | 2484 | ||
2506 | #[test] | 2485 | #[test] |
2507 | fn cross_crate_associated_method_call() { | 2486 | fn cross_crate_associated_method_call() { |
2508 | let (mut db, pos) = MockDatabase::with_position( | 2487 | let (db, pos) = MockDatabase::with_position( |
2509 | r#" | 2488 | r#" |
2510 | //- /main.rs | 2489 | //- /main.rs crate:main deps:other_crate |
2511 | fn test() { | 2490 | fn test() { |
2512 | let x = other_crate::foo::S::thing(); | 2491 | let x = other_crate::foo::S::thing(); |
2513 | x<|>; | 2492 | x<|>; |
2514 | } | 2493 | } |
2515 | 2494 | ||
2516 | //- /lib.rs | 2495 | //- /lib.rs crate:other_crate |
2517 | mod foo { | 2496 | mod foo { |
2518 | struct S; | 2497 | struct S; |
2519 | impl S { | 2498 | impl S { |
@@ -2522,10 +2501,6 @@ mod foo { | |||
2522 | } | 2501 | } |
2523 | "#, | 2502 | "#, |
2524 | ); | 2503 | ); |
2525 | db.set_crate_graph_from_fixture(crate_graph! { | ||
2526 | "main": ("/main.rs", ["other_crate"]), | ||
2527 | "other_crate": ("/lib.rs", []), | ||
2528 | }); | ||
2529 | assert_eq!("i128", type_at_pos(&db, pos)); | 2504 | assert_eq!("i128", type_at_pos(&db, pos)); |
2530 | } | 2505 | } |
2531 | 2506 | ||
@@ -3403,16 +3378,15 @@ fn test() { S.foo()<|>; } | |||
3403 | 3378 | ||
3404 | #[test] | 3379 | #[test] |
3405 | fn infer_macro_with_dollar_crate_is_correct_in_expr() { | 3380 | fn infer_macro_with_dollar_crate_is_correct_in_expr() { |
3406 | covers!(macro_dollar_crate_other); | 3381 | let (db, pos) = MockDatabase::with_position( |
3407 | let (mut db, pos) = MockDatabase::with_position( | ||
3408 | r#" | 3382 | r#" |
3409 | //- /main.rs | 3383 | //- /main.rs crate:main deps:foo |
3410 | fn test() { | 3384 | fn test() { |
3411 | let x = (foo::foo!(1), foo::foo!(2)); | 3385 | let x = (foo::foo!(1), foo::foo!(2)); |
3412 | x<|>; | 3386 | x<|>; |
3413 | } | 3387 | } |
3414 | 3388 | ||
3415 | //- /lib.rs | 3389 | //- /lib.rs crate:foo |
3416 | #[macro_export] | 3390 | #[macro_export] |
3417 | macro_rules! foo { | 3391 | macro_rules! foo { |
3418 | (1) => { $crate::bar!() }; | 3392 | (1) => { $crate::bar!() }; |
@@ -3427,10 +3401,6 @@ macro_rules! bar { | |||
3427 | pub fn baz() -> usize { 31usize } | 3401 | pub fn baz() -> usize { 31usize } |
3428 | "#, | 3402 | "#, |
3429 | ); | 3403 | ); |
3430 | db.set_crate_graph_from_fixture(crate_graph! { | ||
3431 | "main": ("/main.rs", ["foo"]), | ||
3432 | "foo": ("/lib.rs", []), | ||
3433 | }); | ||
3434 | assert_eq!("(i32, usize)", type_at_pos(&db, pos)); | 3404 | assert_eq!("(i32, usize)", type_at_pos(&db, pos)); |
3435 | } | 3405 | } |
3436 | 3406 | ||
@@ -3512,9 +3482,9 @@ fn test() { (&S).foo()<|>; } | |||
3512 | 3482 | ||
3513 | #[test] | 3483 | #[test] |
3514 | fn method_resolution_trait_from_prelude() { | 3484 | fn method_resolution_trait_from_prelude() { |
3515 | let (mut db, pos) = MockDatabase::with_position( | 3485 | let (db, pos) = MockDatabase::with_position( |
3516 | r#" | 3486 | r#" |
3517 | //- /main.rs | 3487 | //- /main.rs crate:main deps:other_crate |
3518 | struct S; | 3488 | struct S; |
3519 | impl Clone for S {} | 3489 | impl Clone for S {} |
3520 | 3490 | ||
@@ -3522,7 +3492,7 @@ fn test() { | |||
3522 | S.clone()<|>; | 3492 | S.clone()<|>; |
3523 | } | 3493 | } |
3524 | 3494 | ||
3525 | //- /lib.rs | 3495 | //- /lib.rs crate:other_crate |
3526 | #[prelude_import] use foo::*; | 3496 | #[prelude_import] use foo::*; |
3527 | 3497 | ||
3528 | mod foo { | 3498 | mod foo { |
@@ -3532,10 +3502,6 @@ mod foo { | |||
3532 | } | 3502 | } |
3533 | "#, | 3503 | "#, |
3534 | ); | 3504 | ); |
3535 | db.set_crate_graph_from_fixture(crate_graph! { | ||
3536 | "main": ("/main.rs", ["other_crate"]), | ||
3537 | "other_crate": ("/lib.rs", []), | ||
3538 | }); | ||
3539 | assert_eq!("S", type_at_pos(&db, pos)); | 3505 | assert_eq!("S", type_at_pos(&db, pos)); |
3540 | } | 3506 | } |
3541 | 3507 | ||