aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/find_path.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-01 12:46:59 +0100
committerGitHub <[email protected]>2021-06-01 12:46:59 +0100
commit4f63e79eb30a0695675a560dfe7ebae6f1dd8a94 (patch)
tree6de19b3c128809cd56641f70873c35f17974aced /crates/hir_def/src/find_path.rs
parent71117e6812f87e014bc8e984e195a75e222ac227 (diff)
parentf96c1a0414ee302fe96503d89f2998483345c8a9 (diff)
Merge #9097
9097: feat: Implement per-edition preludes r=jonas-schievink a=jonas-schievink Part of https://github.com/rust-analyzer/rust-analyzer/issues/9056 Our previous implementation was incorrect (presumably because of the misleading comment in libstd [here](https://github.com/rust-lang/rust/blob/a7890c7952bdc9445eb6c63dc671fa7a1ab0260d/library/std/src/lib.rs#L339-L343)). `#[prelude_import]` does not define the prelude, it can only override the implicit prelude for the current crate. This PR fixes that, which also makes the prelude imports in `rustc_span` work. Closes https://github.com/rust-analyzer/rust-analyzer/issues/8815. bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/hir_def/src/find_path.rs')
-rw-r--r--crates/hir_def/src/find_path.rs24
1 files changed, 13 insertions, 11 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",