mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
internal: introduce minicore -- a subset of libcore for testing
This commit is contained in:
parent
3f5eead9e3
commit
f521e41853
6 changed files with 271 additions and 42 deletions
69
crates/test_utils/src/minicore.rs
Normal file
69
crates/test_utils/src/minicore.rs
Normal file
|
@ -0,0 +1,69 @@
|
|||
//! This is a fixture we use for tests that need lang items.
|
||||
//!
|
||||
//! We want to include the minimal subset of core for each test, so this file
|
||||
//! supports "conditional compilation". Tests use the following syntax to include minicore:
|
||||
//!
|
||||
//! //- minicore: flag1, flag2
|
||||
//!
|
||||
//! We then strip all the code marked with other flags.
|
||||
//!
|
||||
//! Available flags:
|
||||
//! sized:
|
||||
//! coerce_unsized: sized
|
||||
|
||||
pub mod marker {
|
||||
// region:sized
|
||||
#[lang = "sized"]
|
||||
#[fundamental]
|
||||
#[rustc_specialization_trait]
|
||||
pub trait Sized {}
|
||||
|
||||
#[lang = "unsize"]
|
||||
pub trait Unsize<T: ?Sized> {}
|
||||
// endregion:sized
|
||||
}
|
||||
|
||||
pub mod ops {
|
||||
mod unsize {
|
||||
// region:coerce_unsized
|
||||
use crate::marker::Unsize;
|
||||
|
||||
#[lang = "coerce_unsized"]
|
||||
pub trait CoerceUnsized<T: ?Sized> {}
|
||||
|
||||
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
|
||||
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
|
||||
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
|
||||
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
|
||||
|
||||
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
||||
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
|
||||
|
||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
|
||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
|
||||
// endregion:coerce_unsized
|
||||
}
|
||||
}
|
||||
|
||||
pub mod prelude {
|
||||
pub mod v1 {
|
||||
pub use crate::marker::Sized; // :sized
|
||||
}
|
||||
|
||||
pub mod rust_2015 {
|
||||
pub use super::v1::*;
|
||||
}
|
||||
|
||||
pub mod rust_2018 {
|
||||
pub use super::v1::*;
|
||||
}
|
||||
|
||||
pub mod rust_2021 {
|
||||
pub use super::v1::*;
|
||||
}
|
||||
}
|
||||
|
||||
#[prelude_import]
|
||||
#[allow(unused)]
|
||||
use prelude::v1::*;
|
Loading…
Add table
Add a link
Reference in a new issue