From f96c1a0414ee302fe96503d89f2998483345c8a9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 1 Jun 2021 13:39:19 +0200 Subject: Implement per-edition preludes --- crates/hir_ty/src/tests/macros.rs | 50 ++++++++++++++++++---------- crates/hir_ty/src/tests/method_resolution.rs | 14 ++++---- crates/hir_ty/src/tests/regression.rs | 9 ++--- crates/hir_ty/src/tests/simple.rs | 20 +++++++++++ crates/hir_ty/src/tests/traits.rs | 48 +++++++++++++++++--------- 5 files changed, 97 insertions(+), 44 deletions(-) (limited to 'crates/hir_ty') 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() { } //^ S //- /lib.rs crate:core -#[prelude_import] -use clone::*; -mod clone { - trait Clone { +pub mod prelude { + pub mod rust_2018 { + #[rustc_builtin_macro] + pub macro Clone {} + pub use crate::clone::Clone; + } +} + +pub mod clone { + pub trait Clone { fn clone(&self) -> Self; } - #[rustc_builtin_macro] - macro Clone {} } "#, ); @@ -1001,14 +1005,22 @@ fn infer_derive_clone_in_core() { r#" //- /lib.rs crate:core #[prelude_import] -use clone::*; -mod clone { - trait Clone { +use prelude::rust_2018::*; + +pub mod prelude { + pub mod rust_2018 { + #[rustc_builtin_macro] + pub macro Clone {} + pub use crate::clone::Clone; + } +} + +pub mod clone { + pub trait Clone { fn clone(&self) -> Self; } - #[rustc_builtin_macro] - macro Clone {} } + #[derive(Clone)] pub struct S; @@ -1037,14 +1049,18 @@ fn test() { } //- /lib.rs crate:core -#[prelude_import] -use clone::*; -mod clone { - trait Clone { +pub mod prelude { + pub mod rust_2018 { + #[rustc_builtin_macro] + pub macro Clone {} + pub use crate::clone::Clone; + } +} + +pub mod clone { + pub trait Clone { fn clone(&self) -> Self; } - #[rustc_builtin_macro] - macro Clone {} } "#, ); 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() { fn method_resolution_trait_from_prelude() { check_types( r#" -//- /main.rs crate:main deps:other_crate +//- /main.rs crate:main deps:core struct S; impl Clone for S {} @@ -805,12 +805,12 @@ fn test() { //^ S } -//- /lib.rs crate:other_crate -#[prelude_import] use foo::*; - -mod foo { - trait Clone { - fn clone(&self) -> Self; +//- /lib.rs crate:core +pub mod prelude { + pub mod rust_2018 { + pub trait Clone { + fn clone(&self) -> Self; + } } } "#, 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() { //- /std.rs crate:std #[prelude_import] -use prelude::*; - +use self::prelude::rust_2018::*; pub mod prelude { - pub use crate::iter::Iterator; - pub use crate::option::Option; + pub mod rust_2018 { + pub use crate::iter::Iterator; + pub use crate::option::Option; + } } 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() { "#]], ); } + +#[test] +fn prelude_2015() { + check_types( + r#" +//- /main.rs edition:2015 crate:main deps:core +fn f() { + Rust; + //^ Rust +} + +//- /core.rs crate:core +pub mod prelude { + pub mod rust_2015 { + pub struct Rust; + } +} + "#, + ); +} 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() { } //^ u64 //- /core.rs crate:core -#[prelude_import] use future::*; -mod future { - #[lang = "future_trait"] - trait Future { - type Output; +pub mod prelude { + pub mod rust_2018 { + #[lang = "future_trait"] + pub trait Future { + type Output; + } } } "#, @@ -136,17 +137,15 @@ fn test() { } //^ i32 //- /core.rs crate:core -#[prelude_import] use ops::*; -mod ops { - trait Try { +pub mod ops { + pub trait Try { type Ok; type Error; } } -#[prelude_import] use result::*; -mod result { - enum Result { +pub mod result { + pub enum Result { Ok(O), Err(E) } @@ -156,6 +155,12 @@ mod result { type Error = E; } } + +pub mod prelude { + pub mod rust_2018 { + pub use crate::{result::*, ops::*}; + } +} "#, ); } @@ -190,8 +195,7 @@ mov convert { impl From for T {} } -#[prelude_import] use result::*; -mod result { +pub mod result { use crate::convert::From; use crate::ops::{Try, FromResidual}; @@ -208,6 +212,12 @@ mod result { impl> FromResidual> for Result {} } + +pub mod prelude { + pub mod rust_2018 { + pub use crate::result::*; + } +} "#, ); } @@ -217,6 +227,7 @@ fn infer_for_loop() { check_types( r#" //- /main.rs crate:main deps:core,alloc +#![no_std] use alloc::collections::Vec; fn test() { @@ -228,14 +239,19 @@ fn test() { } //- /core.rs crate:core -#[prelude_import] use iter::*; -mod iter { - trait IntoIterator { +pub mod iter { + pub trait IntoIterator { type Item; } } +pub mod prelude { + pub mod rust_2018 { + pub use crate::iter::*; + } +} //- /alloc.rs crate:alloc deps:core +#![no_std] mod collections { struct Vec {} impl Vec { -- cgit v1.2.3