aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/find_path.rs24
-rw-r--r--crates/hir_def/src/nameres/collector.rs68
-rw-r--r--crates/hir_def/src/nameres/tests.rs131
-rw-r--r--crates/hir_def/src/nameres/tests/macros.rs32
-rw-r--r--crates/hir_expand/src/name.rs4
-rw-r--r--crates/hir_ty/src/tests/macros.rs50
-rw-r--r--crates/hir_ty/src/tests/method_resolution.rs14
-rw-r--r--crates/hir_ty/src/tests/regression.rs9
-rw-r--r--crates/hir_ty/src/tests/simple.rs20
-rw-r--r--crates/hir_ty/src/tests/traits.rs48
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs37
-rw-r--r--crates/ide_db/src/helpers/famous_defs_fixture.rs22
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
685pub mod prelude { pub struct S; } 685pub mod prelude {
686#[prelude_import] 686 pub mod rust_2018 {
687pub 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
702pub mod prelude { 704pub 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]
707pub 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
1082pub mod prelude { 1084pub 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]
1087pub 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
6use std::iter; 6use std::iter;
7 7
8use base_db::{CrateId, FileId, ProcMacroId}; 8use base_db::{CrateId, Edition, FileId, ProcMacroId};
9use cfg::{CfgExpr, CfgOptions}; 9use cfg::{CfgExpr, CfgOptions};
10use hir_expand::{ 10use 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]
250use ::test_crate::prelude::*;
251
249use Foo::*; 252use Foo::*;
250 253
251//- /lib.rs crate:test_crate 254//- /lib.rs crate:test_crate
252mod prelude; 255pub mod prelude;
253#[prelude_import]
254use prelude::*;
255 256
256//- /prelude.rs 257//- /prelude.rs
257pub enum Foo { Bar, Baz }; 258pub 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]
471fn 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]
498fn 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]
470fn std_prelude_takes_precedence_above_core_prelude() { 539fn 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() {
474use {Foo, Bar}; 543use {Foo, Bar};
475 544
476//- /std.rs crate:std deps:core 545//- /std.rs crate:std deps:core
477#[prelude_import] 546pub mod prelude {
478pub use self::prelude::*; 547 pub mod rust_2018 {
479mod 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] 554pub mod prelude {
486pub use self::prelude::*; 555 pub mod rust_2018 {
487mod 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() {
504use {Foo, Bar, Baz}; 573use {Foo, Bar, Baz};
505 574
506//- /lib.rs crate:std 575//- /lib.rs crate:std
507#[prelude_import] 576pub mod prelude {
508pub use self::prelude::*; 577 pub mod rust_2018 {
509mod 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() {
532use {Foo, Bar, Baz}; 601use {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] 604pub mod prelude {
536pub use self::prelude::*; 605 pub mod rust_2018 {
537mod 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
268structs!(Foo); 268structs!(Foo);
269structs_priv!(Bar); 269structs_priv!(Bar);
270structs_outside!(Out); 270structs_outside!(Out);
@@ -276,21 +276,20 @@ mod bar;
276structs!(Baz); 276structs!(Baz);
277crate::structs!(MacroNotResolved3); 277crate::structs!(MacroNotResolved3);
278 278
279//- /lib.rs crate:foo 279//- /lib.rs crate:std
280#[prelude_import] 280pub mod prelude {
281use self::prelude::*; 281 pub mod rust_2018 {
282
283mod 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() {
617foo!(); 616foo!();
618 617
619//- /std.rs crate:std deps:core 618//- /std.rs crate:std deps:core
620#[prelude_import]
621use self::prelude::*;
622
623pub use core::foo; 619pub use core::foo;
624 620
625mod prelude {} 621pub mod prelude {
622 pub mod rust_2018 {}
623}
626 624
627#[macro_use] 625#[macro_use]
628mod std_macros; 626mod 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] 985pub mod prelude {
986use clone::*; 986 pub mod rust_2018 {
987mod clone { 987 #[rustc_builtin_macro]
988 trait Clone { 988 pub macro Clone {}
989 pub use crate::clone::Clone;
990 }
991}
992
993pub 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]
1004use clone::*; 1008use prelude::rust_2018::*;
1005mod clone { 1009
1006 trait Clone { 1010pub mod prelude {
1011 pub mod rust_2018 {
1012 #[rustc_builtin_macro]
1013 pub macro Clone {}
1014 pub use crate::clone::Clone;
1015 }
1016}
1017
1018pub 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)]
1013pub struct S; 1025pub 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] 1052pub mod prelude {
1041use clone::*; 1053 pub mod rust_2018 {
1042mod clone { 1054 #[rustc_builtin_macro]
1043 trait Clone { 1055 pub macro Clone {}
1056 pub use crate::clone::Clone;
1057 }
1058}
1059
1060pub 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() {
796fn method_resolution_trait_from_prelude() { 796fn 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
800struct S; 800struct S;
801impl Clone for S {} 801impl 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::*; 809pub mod prelude {
810 810 pub mod rust_2018 {
811mod 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]
429use prelude::*; 429use self::prelude::rust_2018::*;
430
431pub mod prelude { 430pub 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
436pub mod iter { 437pub 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]
2717fn prelude_2015() {
2718 check_types(
2719 r#"
2720//- /main.rs edition:2015 crate:main deps:core
2721fn f() {
2722 Rust;
2723 //^ Rust
2724}
2725
2726//- /core.rs crate:core
2727pub 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::*; 23pub mod prelude {
24mod 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::*; 140pub mod ops {
140mod 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::*; 147pub mod result {
148mod 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
159pub 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::*; 198pub mod result {
194mod 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
216pub 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]
220use alloc::collections::Vec; 231use alloc::collections::Vec;
221 232
222fn test() { 233fn 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::*; 242pub mod iter {
232mod iter { 243 pub trait IntoIterator {
233 trait IntoIterator {
234 type Item; 244 type Item;
235 } 245 }
236} 246}
247pub 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]
239mod collections { 255mod 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() {
385fn foo() { let x: $0 } 385fn foo() { let x: $0 }
386 386
387//- /std/lib.rs crate:std 387//- /std/lib.rs crate:std
388#[prelude_import] 388pub mod prelude {
389use prelude::*; 389 pub mod rust_2018 {
390 390 pub struct Option;
391mod 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; }
406fn f() {$0} 407fn f() {$0}
407 408
408//- /std/lib.rs crate:std 409//- /std/lib.rs crate:std
409#[prelude_import] 410pub mod prelude {
410pub use prelude::*; 411 pub mod rust_2018 {
411 412 pub use crate::concat;
412#[macro_use] 413 }
413mod prelude {
414 pub use crate::concat;
415} 414}
416 415
417mod macros { 416mod macros {
@@ -436,16 +435,18 @@ mod macros {
436fn foo() { let x: $0 } 435fn foo() { let x: $0 }
437 436
438//- /core/lib.rs crate:core 437//- /core/lib.rs crate:core
439#[prelude_import] 438pub mod prelude {
440use prelude::*; 439 pub mod rust_2018 {
441 440 pub struct Option;
442mod 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] 445pub mod prelude {
446use prelude::*; 446 pub mod rust_2018 {
447 447 pub struct String;
448mod 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
130pub mod prelude { 130pub 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]
141pub use prelude::*; 143pub 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
149mod prim_str {} 151mod prim_str {}
150 152
151pub use core::ops; \ No newline at end of file 153pub use core::ops;