diff options
Diffstat (limited to 'crates/hir_ty/src/tests')
-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/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 |
5 files changed, 97 insertions, 44 deletions
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/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> { |