1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! Announced copies of std/core traits, so they can be passed to proc macros.
//!
//! `announce_std::iter::Iterator! { [announce_std::iter::Iterator!, cb!] }` passes
//! a copy of `Iterator` to `cb!`. META holds `mock(::core::iter::Iterator)`:
//! implement that real trait, not the copy. In the type namespace,
//! `announce_std::iter::Iterator` is the real trait, so it works in bounds too.
//!
//! ```
//! macro_rules! show {
//! ([$($l:tt)*] $($p:ident)? $(:: $s:ident)* ! => [mock($($m:tt)*)] { $($item:tt)* }) => {
//! const MOCKED: &str = stringify!($($m)*);
//! };
//! }
//! announce_std::iter::Iterator! { [announce_std::iter::Iterator!, show!] }
//! assert_eq!(MOCKED, ":: core :: iter :: Iterator");
//! // The type namespace holds the real trait:
//! fn _f(_: &dyn announce_std::iter::Iterator<Item = u8>) {}
//! ```
//!
//! **Old compilers.** `Debug`, `Hash`, `PartialEq`, `Eq`, `PartialOrd`, `Ord`,
//! `Clone`, `Copy` and `Default` are also derive macro names. Before rustc 1.94,
//! their type-namespace item is a blanket subtrait instead of the real trait. It
//! works in bounds, but `impl announce_std::fmt::Debug for X` does not implement
//! the real `Debug`. Write impls against the real path from `mock(..)`.
//!
//! **Not mocked.** `BuildHasher::hash_one` is stable only since Rust 1.71, and
//! announce-std supports older compilers (MSRV 1.57), so a consumer that forwards
//! it would break there. The `BuildHasher` mock has `build_hasher` only. To hash a
//! value, use `Hash::hash`: `x.hash(&mut b.build_hasher())`, then `finish()` on
//! the hasher.
//!
//! **Version gates.** Mocks of traits newer than the MSRV (1.57), or changed after
//! it, are gated with `#[cfg(announce_std_rust_1_N)]`. `build.rs` sets that cfg on
//! rustc 1.N and later, using `rustversion` attributes (`Termination` 1.61,
//! `IntoFuture` 1.64, and the 1.80, 1.81 and 1.94 variants).