From 2870d2bade94ae276cba56caf8c35feaacd49422 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jun 2021 22:59:51 +0300 Subject: internal: add option to minicore --- crates/hir_ty/src/tests/traits.rs | 46 +++++---------------------------------- crates/test_utils/src/fixture.rs | 2 ++ crates/test_utils/src/minicore.rs | 18 ++++++++++++++- 3 files changed, 25 insertions(+), 41 deletions(-) (limited to 'crates') diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 33689e081..6df8181ed 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -26,25 +26,14 @@ fn test() { fn infer_async() { check_types( r#" -//- /main.rs crate:main deps:core -async fn foo() -> u64 { - 128 -} +//- minicore: future +async fn foo() -> u64 { 128 } fn test() { let r = foo(); let v = r.await; v; } //^ u64 - -//- /core.rs crate:core -#[prelude_import] use future::*; -mod future { - #[lang = "future_trait"] - trait Future { - type Output; - } -} "#, ); } @@ -53,24 +42,13 @@ mod future { fn infer_desugar_async() { check_types( r#" -//- /main.rs crate:main deps:core -async fn foo() -> u64 { - 128 -} +//- minicore: future +async fn foo() -> u64 { 128 } fn test() { let r = foo(); r; } //^ impl Future - -//- /core.rs crate:core -#[prelude_import] use future::*; -mod future { - trait Future { - type Output; - } -} - "#, ); } @@ -79,7 +57,7 @@ mod future { fn infer_async_block() { check_types( r#" -//- /main.rs crate:main deps:core +//- minicore: future, option async fn test() { let a = async { 42 }; a; @@ -91,7 +69,7 @@ async fn test() { b; // ^ () let c = async { - let y = Option::None; + let y = None; y // ^ Option }; @@ -99,18 +77,6 @@ async fn test() { c; // ^ impl Future> } - -enum Option { None, Some(T) } - -//- /core.rs crate:core -#[prelude_import] use future::*; -mod future { - #[lang = "future_trait"] - trait Future { - type Output; - } -} - "#, ); } diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 779146084..6ba112de8 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -198,6 +198,7 @@ impl MiniCore { self.activated_flags.iter().any(|it| it == flag) } + #[track_caller] fn assert_valid_flag(&self, flag: &str) { if !self.valid_flags.iter().any(|it| it == flag) { panic!("invalid flag: {:?}, valid flags: {:?}", flag, self.valid_flags); @@ -299,6 +300,7 @@ impl MiniCore { let skip = if flag == "" { false } else { + assert!(!flag.starts_with(' '), "region marker starts with a space: {:?}", flag); self.assert_valid_flag(flag); !self.has_flag(flag) }; diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 127d06e59..cb18c8796 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -16,6 +16,7 @@ //! coerce_unsized: unsize //! pin: //! future: pin +//! option: pub mod marker { // region:sized @@ -115,6 +116,17 @@ pub mod slice { } // endregion:slice +// region:option +pub mod option { + pub enum Option { + #[lang = "None"] + None, + #[lang = "Some"] + Some(T), + } +} +// endregion:option + // region:pin pub mod pin { #[lang = "pin"] @@ -127,7 +139,10 @@ pub mod pin { // region:future pub mod future { - use crate::{pin::Pin, task::{Poll, Context}}; + use crate::{ + pin::Pin, + task::{Context, Poll}, + }; #[lang = "future_trait"] pub trait Future { @@ -153,6 +168,7 @@ pub mod task { pub mod prelude { pub mod v1 { pub use crate::marker::Sized; // :sized + pub use crate::option::Option::{self, None, Some}; // :option } pub mod rust_2015 { -- cgit v1.2.3