diff options
-rw-r--r-- | crates/hir_def/src/find_path.rs | 24 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 68 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests.rs | 131 | ||||
-rw-r--r-- | crates/hir_def/src/nameres/tests/macros.rs | 32 | ||||
-rw-r--r-- | crates/hir_expand/src/name.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/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 | ||||
-rw-r--r-- | crates/ide_completion/src/completions/unqualified_path.rs | 37 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/famous_defs_fixture.rs | 22 |
12 files changed, 318 insertions, 141 deletions
diff --git a/crates/hir_def/src/find_path.rs b/crates/hir_def/src/find_path.rs index ee52794aa..219ed4c07 100644 --- a/crates/hir_def/src/find_path.rs +++ b/crates/hir_def/src/find_path.rs | |||
@@ -682,9 +682,11 @@ pub struct S; | |||
682 | //- /main.rs crate:main deps:std | 682 | //- /main.rs crate:main deps:std |
683 | $0 | 683 | $0 |
684 | //- /std.rs crate:std | 684 | //- /std.rs crate:std |
685 | pub mod prelude { pub struct S; } | 685 | pub mod prelude { |
686 | #[prelude_import] | 686 | pub mod rust_2018 { |
687 | pub use prelude::*; | 687 | pub struct S; |
688 | } | ||
689 | } | ||
688 | "#, | 690 | "#, |
689 | "S", | 691 | "S", |
690 | "S", | 692 | "S", |
@@ -700,11 +702,11 @@ pub use prelude::*; | |||
700 | $0 | 702 | $0 |
701 | //- /std.rs crate:std | 703 | //- /std.rs crate:std |
702 | pub mod prelude { | 704 | pub mod prelude { |
703 | pub enum Option<T> { Some(T), None } | 705 | pub mod rust_2018 { |
704 | pub use Option::*; | 706 | pub enum Option<T> { Some(T), None } |
707 | pub use Option::*; | ||
708 | } | ||
705 | } | 709 | } |
706 | #[prelude_import] | ||
707 | pub use prelude::*; | ||
708 | "#; | 710 | "#; |
709 | check_found_path(code, "None", "None", "None", "None"); | 711 | check_found_path(code, "None", "None", "None", "None"); |
710 | check_found_path(code, "Some", "Some", "Some", "Some"); | 712 | check_found_path(code, "Some", "Some", "Some", "Some"); |
@@ -1080,11 +1082,11 @@ fn f() { | |||
1080 | } | 1082 | } |
1081 | //- /std.rs crate:std | 1083 | //- /std.rs crate:std |
1082 | pub mod prelude { | 1084 | pub mod prelude { |
1083 | pub enum Option { None } | 1085 | pub mod rust_2018 { |
1084 | pub use Option::*; | 1086 | pub enum Option { None } |
1087 | pub use Option::*; | ||
1088 | } | ||
1085 | } | 1089 | } |
1086 | #[prelude_import] | ||
1087 | pub use prelude::*; | ||
1088 | "#, | 1090 | "#, |
1089 | "None", | 1091 | "None", |
1090 | "None", | 1092 | "None", |
diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 7f9fdb379..598424305 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs | |||
@@ -5,13 +5,13 @@ | |||
5 | 5 | ||
6 | use std::iter; | 6 | use std::iter; |
7 | 7 | ||
8 | use base_db::{CrateId, FileId, ProcMacroId}; | 8 | use base_db::{CrateId, Edition, FileId, ProcMacroId}; |
9 | use cfg::{CfgExpr, CfgOptions}; | 9 | use cfg::{CfgExpr, CfgOptions}; |
10 | use hir_expand::{ | 10 | use hir_expand::{ |
11 | ast_id_map::FileAstId, | 11 | ast_id_map::FileAstId, |
12 | builtin_derive::find_builtin_derive, | 12 | builtin_derive::find_builtin_derive, |
13 | builtin_macro::find_builtin_macro, | 13 | builtin_macro::find_builtin_macro, |
14 | name::{AsName, Name}, | 14 | name::{name, AsName, Name}, |
15 | proc_macro::ProcMacroExpander, | 15 | proc_macro::ProcMacroExpander, |
16 | FragmentKind, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, | 16 | FragmentKind, HirFileId, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, |
17 | }; | 17 | }; |
@@ -67,14 +67,6 @@ pub(super) fn collect_defs( | |||
67 | def_map | 67 | def_map |
68 | .extern_prelude | 68 | .extern_prelude |
69 | .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); | 69 | .insert(dep.as_name(), dep_def_map.module_id(dep_def_map.root).into()); |
70 | |||
71 | // look for the prelude | ||
72 | // If the dependency defines a prelude, we overwrite an already defined | ||
73 | // prelude. This is necessary to import the "std" prelude if a crate | ||
74 | // depends on both "core" and "std". | ||
75 | if dep_def_map.prelude.is_some() { | ||
76 | def_map.prelude = dep_def_map.prelude; | ||
77 | } | ||
78 | } | 70 | } |
79 | } | 71 | } |
80 | 72 | ||
@@ -283,6 +275,8 @@ impl DefCollector<'_> { | |||
283 | 275 | ||
284 | let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate); | 276 | let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate); |
285 | if attrs.cfg().map_or(true, |cfg| self.cfg_options.check(&cfg) != Some(false)) { | 277 | if attrs.cfg().map_or(true, |cfg| self.cfg_options.check(&cfg) != Some(false)) { |
278 | self.inject_prelude(&attrs); | ||
279 | |||
286 | // Process other crate-level attributes. | 280 | // Process other crate-level attributes. |
287 | for attr in &*attrs { | 281 | for attr in &*attrs { |
288 | let attr_name = match attr.path.as_ident() { | 282 | let attr_name = match attr.path.as_ident() { |
@@ -460,6 +454,58 @@ impl DefCollector<'_> { | |||
460 | } | 454 | } |
461 | } | 455 | } |
462 | 456 | ||
457 | fn inject_prelude(&mut self, crate_attrs: &Attrs) { | ||
458 | // See compiler/rustc_builtin_macros/src/standard_library_imports.rs | ||
459 | |||
460 | if crate_attrs.by_key("no_core").exists() { | ||
461 | // libcore does not get a prelude. | ||
462 | return; | ||
463 | } | ||
464 | |||
465 | let krate = if crate_attrs.by_key("no_std").exists() { | ||
466 | name![core] | ||
467 | } else { | ||
468 | let std = name![std]; | ||
469 | if self.def_map.extern_prelude().any(|(name, _)| *name == std) { | ||
470 | std | ||
471 | } else { | ||
472 | // If `std` does not exist for some reason, fall back to core. This mostly helps | ||
473 | // keep r-a's own tests minimal. | ||
474 | name![core] | ||
475 | } | ||
476 | }; | ||
477 | |||
478 | let edition = match self.def_map.edition { | ||
479 | Edition::Edition2015 => name![rust_2015], | ||
480 | Edition::Edition2018 => name![rust_2018], | ||
481 | Edition::Edition2021 => name![rust_2021], | ||
482 | }; | ||
483 | |||
484 | let path_kind = if self.def_map.edition == Edition::Edition2015 { | ||
485 | PathKind::Plain | ||
486 | } else { | ||
487 | PathKind::Abs | ||
488 | }; | ||
489 | let path = | ||
490 | ModPath::from_segments(path_kind, [krate, name![prelude], edition].iter().cloned()); | ||
491 | |||
492 | let (per_ns, _) = | ||
493 | self.def_map.resolve_path(self.db, self.def_map.root, &path, BuiltinShadowMode::Other); | ||
494 | |||
495 | match &per_ns.types { | ||
496 | Some((ModuleDefId::ModuleId(m), _)) => { | ||
497 | self.def_map.prelude = Some(*m); | ||
498 | } | ||
499 | _ => { | ||
500 | log::error!( | ||
501 | "could not resolve prelude path `{}` to module (resolved to {:?})", | ||
502 | path, | ||
503 | per_ns.types | ||
504 | ); | ||
505 | } | ||
506 | } | ||
507 | } | ||
508 | |||
463 | /// Adds a definition of procedural macro `name` to the root module. | 509 | /// Adds a definition of procedural macro `name` to the root module. |
464 | /// | 510 | /// |
465 | /// # Notes on procedural macro resolution | 511 | /// # Notes on procedural macro resolution |
@@ -718,6 +764,8 @@ impl DefCollector<'_> { | |||
718 | match def.take_types() { | 764 | match def.take_types() { |
719 | Some(ModuleDefId::ModuleId(m)) => { | 765 | Some(ModuleDefId::ModuleId(m)) => { |
720 | if import.is_prelude { | 766 | if import.is_prelude { |
767 | // Note: This dodgily overrides the injected prelude. The rustc | ||
768 | // implementation seems to work the same though. | ||
721 | cov_mark::hit!(std_prelude); | 769 | cov_mark::hit!(std_prelude); |
722 | self.def_map.prelude = Some(m); | 770 | self.def_map.prelude = Some(m); |
723 | } else if m.krate != self.def_map.krate { | 771 | } else if m.krate != self.def_map.krate { |
diff --git a/crates/hir_def/src/nameres/tests.rs b/crates/hir_def/src/nameres/tests.rs index 9f652731d..58c01354a 100644 --- a/crates/hir_def/src/nameres/tests.rs +++ b/crates/hir_def/src/nameres/tests.rs | |||
@@ -246,15 +246,16 @@ fn std_prelude() { | |||
246 | check( | 246 | check( |
247 | r#" | 247 | r#" |
248 | //- /main.rs crate:main deps:test_crate | 248 | //- /main.rs crate:main deps:test_crate |
249 | #[prelude_import] | ||
250 | use ::test_crate::prelude::*; | ||
251 | |||
249 | use Foo::*; | 252 | use Foo::*; |
250 | 253 | ||
251 | //- /lib.rs crate:test_crate | 254 | //- /lib.rs crate:test_crate |
252 | mod prelude; | 255 | pub mod prelude; |
253 | #[prelude_import] | ||
254 | use prelude::*; | ||
255 | 256 | ||
256 | //- /prelude.rs | 257 | //- /prelude.rs |
257 | pub enum Foo { Bar, Baz }; | 258 | pub enum Foo { Bar, Baz } |
258 | "#, | 259 | "#, |
259 | expect![[r#" | 260 | expect![[r#" |
260 | crate | 261 | crate |
@@ -467,6 +468,74 @@ pub struct Bar; | |||
467 | } | 468 | } |
468 | 469 | ||
469 | #[test] | 470 | #[test] |
471 | fn no_std_prelude() { | ||
472 | check( | ||
473 | r#" | ||
474 | //- /main.rs crate:main deps:core,std | ||
475 | #![cfg_attr(not(never), no_std)] | ||
476 | use Rust; | ||
477 | |||
478 | //- /core.rs crate:core | ||
479 | pub mod prelude { | ||
480 | pud mod rust_2018 { | ||
481 | pub struct Rust; | ||
482 | } | ||
483 | } | ||
484 | //- /std.rs crate:std deps:core | ||
485 | pub mod prelude { | ||
486 | pud mod rust_2018 { | ||
487 | } | ||
488 | } | ||
489 | "#, | ||
490 | expect![[r#" | ||
491 | crate | ||
492 | Rust: t v | ||
493 | "#]], | ||
494 | ); | ||
495 | } | ||
496 | |||
497 | #[test] | ||
498 | fn edition_specific_preludes() { | ||
499 | // We can't test the 2015 prelude here since you can't reexport its contents with 2015's | ||
500 | // absolute paths. | ||
501 | |||
502 | check( | ||
503 | r#" | ||
504 | //- /main.rs edition:2018 crate:main deps:std | ||
505 | use Rust2018; | ||
506 | |||
507 | //- /std.rs crate:std | ||
508 | pub mod prelude { | ||
509 | pud mod rust_2018 { | ||
510 | pub struct Rust2018; | ||
511 | } | ||
512 | } | ||
513 | "#, | ||
514 | expect![[r#" | ||
515 | crate | ||
516 | Rust2018: t v | ||
517 | "#]], | ||
518 | ); | ||
519 | check( | ||
520 | r#" | ||
521 | //- /main.rs edition:2021 crate:main deps:std | ||
522 | use Rust2021; | ||
523 | |||
524 | //- /std.rs crate:std | ||
525 | pub mod prelude { | ||
526 | pud mod rust_2021 { | ||
527 | pub struct Rust2021; | ||
528 | } | ||
529 | } | ||
530 | "#, | ||
531 | expect![[r#" | ||
532 | crate | ||
533 | Rust2021: t v | ||
534 | "#]], | ||
535 | ); | ||
536 | } | ||
537 | |||
538 | #[test] | ||
470 | fn std_prelude_takes_precedence_above_core_prelude() { | 539 | fn std_prelude_takes_precedence_above_core_prelude() { |
471 | check( | 540 | check( |
472 | r#" | 541 | r#" |
@@ -474,18 +543,18 @@ fn std_prelude_takes_precedence_above_core_prelude() { | |||
474 | use {Foo, Bar}; | 543 | use {Foo, Bar}; |
475 | 544 | ||
476 | //- /std.rs crate:std deps:core | 545 | //- /std.rs crate:std deps:core |
477 | #[prelude_import] | 546 | pub mod prelude { |
478 | pub use self::prelude::*; | 547 | pub mod rust_2018 { |
479 | mod prelude { | 548 | pub struct Foo; |
480 | pub struct Foo; | 549 | pub use core::prelude::rust_2018::Bar; |
481 | pub use core::prelude::Bar; | 550 | } |
482 | } | 551 | } |
483 | 552 | ||
484 | //- /core.rs crate:core | 553 | //- /core.rs crate:core |
485 | #[prelude_import] | 554 | pub mod prelude { |
486 | pub use self::prelude::*; | 555 | pub mod rust_2018 { |
487 | mod prelude { | 556 | pub struct Bar; |
488 | pub struct Bar; | 557 | } |
489 | } | 558 | } |
490 | "#, | 559 | "#, |
491 | expect![[r#" | 560 | expect![[r#" |
@@ -504,15 +573,15 @@ fn cfg_not_test() { | |||
504 | use {Foo, Bar, Baz}; | 573 | use {Foo, Bar, Baz}; |
505 | 574 | ||
506 | //- /lib.rs crate:std | 575 | //- /lib.rs crate:std |
507 | #[prelude_import] | 576 | pub mod prelude { |
508 | pub use self::prelude::*; | 577 | pub mod rust_2018 { |
509 | mod prelude { | 578 | #[cfg(test)] |
510 | #[cfg(test)] | 579 | pub struct Foo; |
511 | pub struct Foo; | 580 | #[cfg(not(test))] |
512 | #[cfg(not(test))] | 581 | pub struct Bar; |
513 | pub struct Bar; | 582 | #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] |
514 | #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] | 583 | pub struct Baz; |
515 | pub struct Baz; | 584 | } |
516 | } | 585 | } |
517 | "#, | 586 | "#, |
518 | expect![[r#" | 587 | expect![[r#" |
@@ -532,15 +601,15 @@ fn cfg_test() { | |||
532 | use {Foo, Bar, Baz}; | 601 | use {Foo, Bar, Baz}; |
533 | 602 | ||
534 | //- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42 | 603 | //- /lib.rs crate:std cfg:test,feature=foo,feature=bar,opt=42 |
535 | #[prelude_import] | 604 | pub mod prelude { |
536 | pub use self::prelude::*; | 605 | pub mod rust_2018 { |
537 | mod prelude { | 606 | #[cfg(test)] |
538 | #[cfg(test)] | 607 | pub struct Foo; |
539 | pub struct Foo; | 608 | #[cfg(not(test))] |
540 | #[cfg(not(test))] | 609 | pub struct Bar; |
541 | pub struct Bar; | 610 | #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] |
542 | #[cfg(all(not(any()), feature = "foo", feature = "bar", opt = "42"))] | 611 | pub struct Baz; |
543 | pub struct Baz; | 612 | } |
544 | } | 613 | } |
545 | "#, | 614 | "#, |
546 | expect![[r#" | 615 | expect![[r#" |
diff --git a/crates/hir_def/src/nameres/tests/macros.rs b/crates/hir_def/src/nameres/tests/macros.rs index 3065efd65..371618438 100644 --- a/crates/hir_def/src/nameres/tests/macros.rs +++ b/crates/hir_def/src/nameres/tests/macros.rs | |||
@@ -264,7 +264,7 @@ fn prelude_is_macro_use() { | |||
264 | cov_mark::check!(prelude_is_macro_use); | 264 | cov_mark::check!(prelude_is_macro_use); |
265 | check( | 265 | check( |
266 | r#" | 266 | r#" |
267 | //- /main.rs crate:main deps:foo | 267 | //- /main.rs crate:main deps:std |
268 | structs!(Foo); | 268 | structs!(Foo); |
269 | structs_priv!(Bar); | 269 | structs_priv!(Bar); |
270 | structs_outside!(Out); | 270 | structs_outside!(Out); |
@@ -276,21 +276,20 @@ mod bar; | |||
276 | structs!(Baz); | 276 | structs!(Baz); |
277 | crate::structs!(MacroNotResolved3); | 277 | crate::structs!(MacroNotResolved3); |
278 | 278 | ||
279 | //- /lib.rs crate:foo | 279 | //- /lib.rs crate:std |
280 | #[prelude_import] | 280 | pub mod prelude { |
281 | use self::prelude::*; | 281 | pub mod rust_2018 { |
282 | |||
283 | mod prelude { | ||
284 | #[macro_export] | ||
285 | macro_rules! structs { | ||
286 | ($i:ident) => { struct $i; } | ||
287 | } | ||
288 | |||
289 | mod priv_mod { | ||
290 | #[macro_export] | 282 | #[macro_export] |
291 | macro_rules! structs_priv { | 283 | macro_rules! structs { |
292 | ($i:ident) => { struct $i; } | 284 | ($i:ident) => { struct $i; } |
293 | } | 285 | } |
286 | |||
287 | mod priv_mod { | ||
288 | #[macro_export] | ||
289 | macro_rules! structs_priv { | ||
290 | ($i:ident) => { struct $i; } | ||
291 | } | ||
292 | } | ||
294 | } | 293 | } |
295 | } | 294 | } |
296 | 295 | ||
@@ -617,12 +616,11 @@ fn macro_dollar_crate_is_correct_in_indirect_deps() { | |||
617 | foo!(); | 616 | foo!(); |
618 | 617 | ||
619 | //- /std.rs crate:std deps:core | 618 | //- /std.rs crate:std deps:core |
620 | #[prelude_import] | ||
621 | use self::prelude::*; | ||
622 | |||
623 | pub use core::foo; | 619 | pub use core::foo; |
624 | 620 | ||
625 | mod prelude {} | 621 | pub mod prelude { |
622 | pub mod rust_2018 {} | ||
623 | } | ||
626 | 624 | ||
627 | #[macro_use] | 625 | #[macro_use] |
628 | mod std_macros; | 626 | mod std_macros; |
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs index b07fbf8b3..abc6753bf 100644 --- a/crates/hir_expand/src/name.rs +++ b/crates/hir_expand/src/name.rs | |||
@@ -176,6 +176,10 @@ pub mod known { | |||
176 | result, | 176 | result, |
177 | boxed, | 177 | boxed, |
178 | option, | 178 | option, |
179 | prelude, | ||
180 | rust_2015, | ||
181 | rust_2018, | ||
182 | rust_2021, | ||
179 | // Components of known path (type name) | 183 | // Components of known path (type name) |
180 | Iterator, | 184 | Iterator, |
181 | IntoIterator, | 185 | IntoIterator, |
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> { |
diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 20188a7dd..bd955aa85 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs | |||
@@ -385,10 +385,11 @@ fn foo() { | |||
385 | fn foo() { let x: $0 } | 385 | fn foo() { let x: $0 } |
386 | 386 | ||
387 | //- /std/lib.rs crate:std | 387 | //- /std/lib.rs crate:std |
388 | #[prelude_import] | 388 | pub mod prelude { |
389 | use prelude::*; | 389 | pub mod rust_2018 { |
390 | 390 | pub struct Option; | |
391 | mod prelude { struct Option; } | 391 | } |
392 | } | ||
392 | "#, | 393 | "#, |
393 | expect![[r#" | 394 | expect![[r#" |
394 | fn foo() fn() | 395 | fn foo() fn() |
@@ -406,12 +407,10 @@ mod prelude { struct Option; } | |||
406 | fn f() {$0} | 407 | fn f() {$0} |
407 | 408 | ||
408 | //- /std/lib.rs crate:std | 409 | //- /std/lib.rs crate:std |
409 | #[prelude_import] | 410 | pub mod prelude { |
410 | pub use prelude::*; | 411 | pub mod rust_2018 { |
411 | 412 | pub use crate::concat; | |
412 | #[macro_use] | 413 | } |
413 | mod prelude { | ||
414 | pub use crate::concat; | ||
415 | } | 414 | } |
416 | 415 | ||
417 | mod macros { | 416 | mod macros { |
@@ -436,16 +435,18 @@ mod macros { | |||
436 | fn foo() { let x: $0 } | 435 | fn foo() { let x: $0 } |
437 | 436 | ||
438 | //- /core/lib.rs crate:core | 437 | //- /core/lib.rs crate:core |
439 | #[prelude_import] | 438 | pub mod prelude { |
440 | use prelude::*; | 439 | pub mod rust_2018 { |
441 | 440 | pub struct Option; | |
442 | mod prelude { struct Option; } | 441 | } |
442 | } | ||
443 | 443 | ||
444 | //- /std/lib.rs crate:std deps:core | 444 | //- /std/lib.rs crate:std deps:core |
445 | #[prelude_import] | 445 | pub mod prelude { |
446 | use prelude::*; | 446 | pub mod rust_2018 { |
447 | 447 | pub struct String; | |
448 | mod prelude { struct String; } | 448 | } |
449 | } | ||
449 | "#, | 450 | "#, |
450 | expect![[r#" | 451 | expect![[r#" |
451 | fn foo() fn() | 452 | fn foo() fn() |
diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs index 29ae12dcf..312851966 100644 --- a/crates/ide_db/src/helpers/famous_defs_fixture.rs +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs | |||
@@ -128,17 +128,19 @@ pub mod option { | |||
128 | } | 128 | } |
129 | 129 | ||
130 | pub mod prelude { | 130 | pub mod prelude { |
131 | pub use crate::{ | 131 | pub mod rust_2018 { |
132 | cmp::Ord, | 132 | pub use crate::{ |
133 | convert::{From, Into}, | 133 | cmp::Ord, |
134 | default::Default, | 134 | convert::{From, Into}, |
135 | iter::{IntoIterator, Iterator}, | 135 | default::Default, |
136 | ops::{Fn, FnMut, FnOnce}, | 136 | iter::{IntoIterator, Iterator}, |
137 | option::Option::{self, *}, | 137 | ops::{Fn, FnMut, FnOnce}, |
138 | }; | 138 | option::Option::{self, *}, |
139 | }; | ||
140 | } | ||
139 | } | 141 | } |
140 | #[prelude_import] | 142 | #[prelude_import] |
141 | pub use prelude::*; | 143 | pub use prelude::rust_2018::*; |
142 | //- /libstd.rs crate:std deps:core | 144 | //- /libstd.rs crate:std deps:core |
143 | //! Signatures of traits, types and functions from the std lib for use in tests. | 145 | //! Signatures of traits, types and functions from the std lib for use in tests. |
144 | 146 | ||
@@ -148,4 +150,4 @@ mod return_keyword {} | |||
148 | /// Docs for prim_str | 150 | /// Docs for prim_str |
149 | mod prim_str {} | 151 | mod prim_str {} |
150 | 152 | ||
151 | pub use core::ops; \ No newline at end of file | 153 | pub use core::ops; |