diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/infer/pat.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/macros.rs | 50 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/method_resolution.rs | 14 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/patterns.rs | 47 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/regression.rs | 9 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/simple.rs | 20 | ||||
-rw-r--r-- | crates/hir_ty/src/tests/traits.rs | 48 |
7 files changed, 129 insertions, 63 deletions
diff --git a/crates/hir_ty/src/infer/pat.rs b/crates/hir_ty/src/infer/pat.rs index a21f44d6a..25dff7e49 100644 --- a/crates/hir_ty/src/infer/pat.rs +++ b/crates/hir_ty/src/infer/pat.rs | |||
@@ -297,6 +297,10 @@ fn is_non_ref_pat(body: &hir_def::body::Body, pat: PatId) -> bool { | |||
297 | Expr::Literal(Literal::String(..)) => false, | 297 | Expr::Literal(Literal::String(..)) => false, |
298 | _ => true, | 298 | _ => true, |
299 | }, | 299 | }, |
300 | Pat::Bind { mode: BindingAnnotation::Mutable, subpat: Some(subpat), .. } | ||
301 | | Pat::Bind { mode: BindingAnnotation::Unannotated, subpat: Some(subpat), .. } => { | ||
302 | is_non_ref_pat(body, *subpat) | ||
303 | } | ||
300 | Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false, | 304 | Pat::Wild | Pat::Bind { .. } | Pat::Ref { .. } | Pat::Box { .. } | Pat::Missing => false, |
301 | } | 305 | } |
302 | } | 306 | } |
diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 7647bb08b..d14103aab 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs | |||
@@ -982,14 +982,18 @@ fn test() { | |||
982 | } //^ S | 982 | } //^ S |
983 | 983 | ||
984 | //- /lib.rs crate:core | 984 | //- /lib.rs crate:core |
985 | #[prelude_import] | 985 | pub mod prelude { |
986 | use clone::*; | 986 | pub mod rust_2018 { |
987 | mod clone { | 987 | #[rustc_builtin_macro] |
988 | trait Clone { | 988 | pub macro Clone {} |
989 | pub use crate::clone::Clone; | ||
990 | } | ||
991 | } | ||
992 | |||
993 | pub mod clone { | ||
994 | pub trait Clone { | ||
989 | fn clone(&self) -> Self; | 995 | fn clone(&self) -> Self; |
990 | } | 996 | } |
991 | #[rustc_builtin_macro] | ||
992 | macro Clone {} | ||
993 | } | 997 | } |
994 | "#, | 998 | "#, |
995 | ); | 999 | ); |
@@ -1001,14 +1005,22 @@ fn infer_derive_clone_in_core() { | |||
1001 | r#" | 1005 | r#" |
1002 | //- /lib.rs crate:core | 1006 | //- /lib.rs crate:core |
1003 | #[prelude_import] | 1007 | #[prelude_import] |
1004 | use clone::*; | 1008 | use prelude::rust_2018::*; |
1005 | mod clone { | 1009 | |
1006 | trait Clone { | 1010 | pub mod prelude { |
1011 | pub mod rust_2018 { | ||
1012 | #[rustc_builtin_macro] | ||
1013 | pub macro Clone {} | ||
1014 | pub use crate::clone::Clone; | ||
1015 | } | ||
1016 | } | ||
1017 | |||
1018 | pub mod clone { | ||
1019 | pub trait Clone { | ||
1007 | fn clone(&self) -> Self; | 1020 | fn clone(&self) -> Self; |
1008 | } | 1021 | } |
1009 | #[rustc_builtin_macro] | ||
1010 | macro Clone {} | ||
1011 | } | 1022 | } |
1023 | |||
1012 | #[derive(Clone)] | 1024 | #[derive(Clone)] |
1013 | pub struct S; | 1025 | pub struct S; |
1014 | 1026 | ||
@@ -1037,14 +1049,18 @@ fn test() { | |||
1037 | } | 1049 | } |
1038 | 1050 | ||
1039 | //- /lib.rs crate:core | 1051 | //- /lib.rs crate:core |
1040 | #[prelude_import] | 1052 | pub mod prelude { |
1041 | use clone::*; | 1053 | pub mod rust_2018 { |
1042 | mod clone { | 1054 | #[rustc_builtin_macro] |
1043 | trait Clone { | 1055 | pub macro Clone {} |
1056 | pub use crate::clone::Clone; | ||
1057 | } | ||
1058 | } | ||
1059 | |||
1060 | pub mod clone { | ||
1061 | pub trait Clone { | ||
1044 | fn clone(&self) -> Self; | 1062 | fn clone(&self) -> Self; |
1045 | } | 1063 | } |
1046 | #[rustc_builtin_macro] | ||
1047 | macro Clone {} | ||
1048 | } | 1064 | } |
1049 | "#, | 1065 | "#, |
1050 | ); | 1066 | ); |
diff --git a/crates/hir_ty/src/tests/method_resolution.rs b/crates/hir_ty/src/tests/method_resolution.rs index a4c132bc5..058eb9129 100644 --- a/crates/hir_ty/src/tests/method_resolution.rs +++ b/crates/hir_ty/src/tests/method_resolution.rs | |||
@@ -796,7 +796,7 @@ fn test() { | |||
796 | fn method_resolution_trait_from_prelude() { | 796 | fn method_resolution_trait_from_prelude() { |
797 | check_types( | 797 | check_types( |
798 | r#" | 798 | r#" |
799 | //- /main.rs crate:main deps:other_crate | 799 | //- /main.rs crate:main deps:core |
800 | struct S; | 800 | struct S; |
801 | impl Clone for S {} | 801 | impl Clone for S {} |
802 | 802 | ||
@@ -805,12 +805,12 @@ fn test() { | |||
805 | //^ S | 805 | //^ S |
806 | } | 806 | } |
807 | 807 | ||
808 | //- /lib.rs crate:other_crate | 808 | //- /lib.rs crate:core |
809 | #[prelude_import] use foo::*; | 809 | pub mod prelude { |
810 | 810 | pub mod rust_2018 { | |
811 | mod foo { | 811 | pub trait Clone { |
812 | trait Clone { | 812 | fn clone(&self) -> Self; |
813 | fn clone(&self) -> Self; | 813 | } |
814 | } | 814 | } |
815 | } | 815 | } |
816 | "#, | 816 | "#, |
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index cd08b5c7a..7d00cee9b 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs | |||
@@ -20,6 +20,8 @@ fn infer_pattern() { | |||
20 | let h = val; | 20 | let h = val; |
21 | } | 21 | } |
22 | 22 | ||
23 | if let x @ true = &true {} | ||
24 | |||
23 | let lambda = |a: u64, b, c: i32| { a + b; c }; | 25 | let lambda = |a: u64, b, c: i32| { a + b; c }; |
24 | 26 | ||
25 | let ref ref_to_x = x; | 27 | let ref ref_to_x = x; |
@@ -30,7 +32,7 @@ fn infer_pattern() { | |||
30 | "#, | 32 | "#, |
31 | expect![[r#" | 33 | expect![[r#" |
32 | 8..9 'x': &i32 | 34 | 8..9 'x': &i32 |
33 | 17..368 '{ ...o_x; }': () | 35 | 17..400 '{ ...o_x; }': () |
34 | 27..28 'y': &i32 | 36 | 27..28 'y': &i32 |
35 | 31..32 'x': &i32 | 37 | 31..32 'x': &i32 |
36 | 42..44 '&z': &i32 | 38 | 42..44 '&z': &i32 |
@@ -59,24 +61,31 @@ fn infer_pattern() { | |||
59 | 176..204 '{ ... }': () | 61 | 176..204 '{ ... }': () |
60 | 190..191 'h': {unknown} | 62 | 190..191 'h': {unknown} |
61 | 194..197 'val': {unknown} | 63 | 194..197 'val': {unknown} |
62 | 214..220 'lambda': |u64, u64, i32| -> i32 | 64 | 210..236 'if let...rue {}': () |
63 | 223..255 '|a: u6...b; c }': |u64, u64, i32| -> i32 | 65 | 217..225 'x @ true': &bool |
64 | 224..225 'a': u64 | 66 | 221..225 'true': bool |
65 | 232..233 'b': u64 | 67 | 221..225 'true': bool |
66 | 235..236 'c': i32 | 68 | 228..233 '&true': &bool |
67 | 243..255 '{ a + b; c }': i32 | 69 | 229..233 'true': bool |
68 | 245..246 'a': u64 | 70 | 234..236 '{}': () |
69 | 245..250 'a + b': u64 | 71 | 246..252 'lambda': |u64, u64, i32| -> i32 |
70 | 249..250 'b': u64 | 72 | 255..287 '|a: u6...b; c }': |u64, u64, i32| -> i32 |
71 | 252..253 'c': i32 | 73 | 256..257 'a': u64 |
72 | 266..278 'ref ref_to_x': &&i32 | 74 | 264..265 'b': u64 |
73 | 281..282 'x': &i32 | 75 | 267..268 'c': i32 |
74 | 292..301 'mut mut_x': &i32 | 76 | 275..287 '{ a + b; c }': i32 |
75 | 304..305 'x': &i32 | 77 | 277..278 'a': u64 |
76 | 315..335 'ref mu...f_to_x': &mut &i32 | 78 | 277..282 'a + b': u64 |
77 | 338..339 'x': &i32 | 79 | 281..282 'b': u64 |
78 | 349..350 'k': &mut &i32 | 80 | 284..285 'c': i32 |
79 | 353..365 'mut_ref_to_x': &mut &i32 | 81 | 298..310 'ref ref_to_x': &&i32 |
82 | 313..314 'x': &i32 | ||
83 | 324..333 'mut mut_x': &i32 | ||
84 | 336..337 'x': &i32 | ||
85 | 347..367 'ref mu...f_to_x': &mut &i32 | ||
86 | 370..371 'x': &i32 | ||
87 | 381..382 'k': &mut &i32 | ||
88 | 385..397 'mut_ref_to_x': &mut &i32 | ||
80 | "#]], | 89 | "#]], |
81 | ); | 90 | ); |
82 | } | 91 | } |
diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index ad9edf11c..1019e783b 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs | |||
@@ -426,11 +426,12 @@ fn test() { | |||
426 | 426 | ||
427 | //- /std.rs crate:std | 427 | //- /std.rs crate:std |
428 | #[prelude_import] | 428 | #[prelude_import] |
429 | use prelude::*; | 429 | use self::prelude::rust_2018::*; |
430 | |||
431 | pub mod prelude { | 430 | pub mod prelude { |
432 | pub use crate::iter::Iterator; | 431 | pub mod rust_2018 { |
433 | pub use crate::option::Option; | 432 | pub use crate::iter::Iterator; |
433 | pub use crate::option::Option; | ||
434 | } | ||
434 | } | 435 | } |
435 | 436 | ||
436 | pub mod iter { | 437 | pub mod iter { |
diff --git a/crates/hir_ty/src/tests/simple.rs b/crates/hir_ty/src/tests/simple.rs index ac312981d..3418ed21e 100644 --- a/crates/hir_ty/src/tests/simple.rs +++ b/crates/hir_ty/src/tests/simple.rs | |||
@@ -2712,3 +2712,23 @@ fn main() { | |||
2712 | "#]], | 2712 | "#]], |
2713 | ); | 2713 | ); |
2714 | } | 2714 | } |
2715 | |||
2716 | #[test] | ||
2717 | fn prelude_2015() { | ||
2718 | check_types( | ||
2719 | r#" | ||
2720 | //- /main.rs edition:2015 crate:main deps:core | ||
2721 | fn f() { | ||
2722 | Rust; | ||
2723 | //^ Rust | ||
2724 | } | ||
2725 | |||
2726 | //- /core.rs crate:core | ||
2727 | pub mod prelude { | ||
2728 | pub mod rust_2015 { | ||
2729 | pub struct Rust; | ||
2730 | } | ||
2731 | } | ||
2732 | "#, | ||
2733 | ); | ||
2734 | } | ||
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 49add4ab9..588f0d1d4 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs | |||
@@ -20,11 +20,12 @@ fn test() { | |||
20 | } //^ u64 | 20 | } //^ u64 |
21 | 21 | ||
22 | //- /core.rs crate:core | 22 | //- /core.rs crate:core |
23 | #[prelude_import] use future::*; | 23 | pub mod prelude { |
24 | mod future { | 24 | pub mod rust_2018 { |
25 | #[lang = "future_trait"] | 25 | #[lang = "future_trait"] |
26 | trait Future { | 26 | pub trait Future { |
27 | type Output; | 27 | type Output; |
28 | } | ||
28 | } | 29 | } |
29 | } | 30 | } |
30 | "#, | 31 | "#, |
@@ -136,17 +137,15 @@ fn test() { | |||
136 | } //^ i32 | 137 | } //^ i32 |
137 | 138 | ||
138 | //- /core.rs crate:core | 139 | //- /core.rs crate:core |
139 | #[prelude_import] use ops::*; | 140 | pub mod ops { |
140 | mod ops { | 141 | pub trait Try { |
141 | trait Try { | ||
142 | type Ok; | 142 | type Ok; |
143 | type Error; | 143 | type Error; |
144 | } | 144 | } |
145 | } | 145 | } |
146 | 146 | ||
147 | #[prelude_import] use result::*; | 147 | pub mod result { |
148 | mod result { | 148 | pub enum Result<O, E> { |
149 | enum Result<O, E> { | ||
150 | Ok(O), | 149 | Ok(O), |
151 | Err(E) | 150 | Err(E) |
152 | } | 151 | } |
@@ -156,6 +155,12 @@ mod result { | |||
156 | type Error = E; | 155 | type Error = E; |
157 | } | 156 | } |
158 | } | 157 | } |
158 | |||
159 | pub mod prelude { | ||
160 | pub mod rust_2018 { | ||
161 | pub use crate::{result::*, ops::*}; | ||
162 | } | ||
163 | } | ||
159 | "#, | 164 | "#, |
160 | ); | 165 | ); |
161 | } | 166 | } |
@@ -190,8 +195,7 @@ mov convert { | |||
190 | impl<T> From<T> for T {} | 195 | impl<T> From<T> for T {} |
191 | } | 196 | } |
192 | 197 | ||
193 | #[prelude_import] use result::*; | 198 | pub mod result { |
194 | mod result { | ||
195 | use crate::convert::From; | 199 | use crate::convert::From; |
196 | use crate::ops::{Try, FromResidual}; | 200 | use crate::ops::{Try, FromResidual}; |
197 | 201 | ||
@@ -208,6 +212,12 @@ mod result { | |||
208 | 212 | ||
209 | impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {} | 213 | impl<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {} |
210 | } | 214 | } |
215 | |||
216 | pub mod prelude { | ||
217 | pub mod rust_2018 { | ||
218 | pub use crate::result::*; | ||
219 | } | ||
220 | } | ||
211 | "#, | 221 | "#, |
212 | ); | 222 | ); |
213 | } | 223 | } |
@@ -217,6 +227,7 @@ fn infer_for_loop() { | |||
217 | check_types( | 227 | check_types( |
218 | r#" | 228 | r#" |
219 | //- /main.rs crate:main deps:core,alloc | 229 | //- /main.rs crate:main deps:core,alloc |
230 | #![no_std] | ||
220 | use alloc::collections::Vec; | 231 | use alloc::collections::Vec; |
221 | 232 | ||
222 | fn test() { | 233 | fn test() { |
@@ -228,14 +239,19 @@ fn test() { | |||
228 | } | 239 | } |
229 | 240 | ||
230 | //- /core.rs crate:core | 241 | //- /core.rs crate:core |
231 | #[prelude_import] use iter::*; | 242 | pub mod iter { |
232 | mod iter { | 243 | pub trait IntoIterator { |
233 | trait IntoIterator { | ||
234 | type Item; | 244 | type Item; |
235 | } | 245 | } |
236 | } | 246 | } |
247 | pub mod prelude { | ||
248 | pub mod rust_2018 { | ||
249 | pub use crate::iter::*; | ||
250 | } | ||
251 | } | ||
237 | 252 | ||
238 | //- /alloc.rs crate:alloc deps:core | 253 | //- /alloc.rs crate:alloc deps:core |
254 | #![no_std] | ||
239 | mod collections { | 255 | mod collections { |
240 | struct Vec<T> {} | 256 | struct Vec<T> {} |
241 | impl<T> Vec<T> { | 257 | impl<T> Vec<T> { |