mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Implement per-edition preludes
This commit is contained in:
parent
71117e6812
commit
f96c1a0414
12 changed files with 318 additions and 141 deletions
|
@ -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 {}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<O, E> {
|
||||
pub mod result {
|
||||
pub enum Result<O, E> {
|
||||
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<T> From<T> 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<T, E, F: From<E>> FromResidual<Result<Infallible, E>> for Result<T, F> {}
|
||||
}
|
||||
|
||||
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<T> {}
|
||||
impl<T> Vec<T> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue