From e9e3ab549d5a73f85e19eed5b915d78870f8892c Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 12 Jan 2021 17:26:08 +0100 Subject: Move FamousDefs fixture out into its own file --- crates/ide_db/src/helpers/famous_defs_fixture.rs | 119 +++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 crates/ide_db/src/helpers/famous_defs_fixture.rs (limited to 'crates/ide_db/src/helpers/famous_defs_fixture.rs') diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs new file mode 100644 index 000000000..f3d355861 --- /dev/null +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs @@ -0,0 +1,119 @@ +//- /libcore.rs crate:core +pub mod convert { + pub trait From { + fn from(t: T) -> Self; + } +} + +pub mod default { + pub trait Default { + fn default() -> Self; + } +} + +pub mod iter { + pub use self::traits::{collect::IntoIterator, iterator::Iterator}; + mod traits { + pub(crate) mod iterator { + use crate::option::Option; + pub trait Iterator { + type Item; + fn next(&mut self) -> Option; + fn by_ref(&mut self) -> &mut Self { + self + } + fn take(self, n: usize) -> crate::iter::Take { + crate::iter::Take { inner: self } + } + } + + impl Iterator for &mut I { + type Item = I::Item; + fn next(&mut self) -> Option { + (**self).next() + } + } + } + pub(crate) mod collect { + pub trait IntoIterator { + type Item; + } + } + } + + pub use self::sources::*; + pub(crate) mod sources { + use super::Iterator; + use crate::option::Option::{self, *}; + pub struct Repeat { + element: A, + } + + pub fn repeat(elt: T) -> Repeat { + Repeat { element: elt } + } + + impl Iterator for Repeat { + type Item = A; + + fn next(&mut self) -> Option { + None + } + } + } + + pub use self::adapters::*; + pub(crate) mod adapters { + use super::Iterator; + use crate::option::Option::{self, *}; + pub struct Take { + pub(crate) inner: I, + } + impl Iterator for Take + where + I: Iterator, + { + type Item = ::Item; + fn next(&mut self) -> Option<::Item> { + None + } + } + } +} + +pub mod ops { + #[lang = "fn"] + pub trait Fn: FnMut { + extern "rust-call" fn call(&self, args: Args) -> Self::Output; + } + + #[lang = "fn_mut"] + pub trait FnMut: FnOnce { + extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; + } + #[lang = "fn_once"] + pub trait FnOnce { + #[lang = "fn_once_output"] + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; + } +} + +pub mod option { + pub enum Option { + None, + Some(T), + } +} + +pub mod prelude { + pub use crate::{ + convert::From, + default::Default, + iter::{IntoIterator, Iterator}, + ops::{Fn, FnMut, FnOnce}, + option::Option::{self, *}, + }; +} +#[prelude_import] +pub use prelude::*; -- cgit v1.2.3 From 3d6480bc3103f7238b1b0e020518e8aa72af3156 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 12 Jan 2021 20:19:13 +0100 Subject: Render Fn* trait objects and impl types as rust does --- crates/ide_db/src/helpers/famous_defs_fixture.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'crates/ide_db/src/helpers/famous_defs_fixture.rs') diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs index f3d355861..5e88de64d 100644 --- a/crates/ide_db/src/helpers/famous_defs_fixture.rs +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs @@ -1,4 +1,5 @@ //- /libcore.rs crate:core +//! Signatures of traits, types and functions from the core lib for use in tests. pub mod convert { pub trait From { fn from(t: T) -> Self; -- cgit v1.2.3