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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Switch between Rust editions anywhere in your code.
//!
//! See [the Rust Edition Guide](https://doc.rust-lang.org/edition-guide)
//! for details on all the editions.
//!
//! ## Example
//!
//! ```
//! use edition::*;
//!
//! rust_2015! {
//! // `async` isn't a keyword yet.
//! fn async() {}
//! }
//!
//! rust_2018! {
//! // `async` is a keyword now.
//! async fn abc() {}
//! }
//!
//! rust_2021! {
//! // Arrays now implement IntoIter.
//! let _: i32 = [1, 2, 3].into_iter().next().unwrap();
//! }
//!
//! rust_2024! {
//! // Box<[T]> now implements IntoIter.
//! let _: i32 = vec![1, 2, 3].into_boxed_slice().into_iter().next().unwrap();
//! }
//! ```
//!
//! The macros are usable in any context where a macro call is allowed.
//! That is, not only can they wrap items or statements, they can also wrap a type or a (sub)expression:
//!
//! ```rust
//! # use edition::*;
//! use std::string::ToString;
//!
//! # fn main() {
//! let _: rust_2015!(&::ToString) = &rust_2021!([1, 2, 3].into_iter()).next().unwrap();
//! # }
//! ```
//!
//! ## Limitations
//!
//! These macros only work for edition changes that are token based, which are most of them.
//! They do not affect which prelude is imported, what resolver Cargo uses, or how the source code is tokenized.
//!
//! These macros change the context of the token spans to that of a token from the requested edition.
//! This breaks hygiene, meaning that you cannot refer to locals outside the macro invocation:
//!
//! ```compile_fail,E0425
//! # use edition::*;
//! let a = 123;
//!
//! rust_2015! {
//! let _ = a; // Error: cannot find value `a` in this scope
//! }
//! ```
/// Switch to Rust 2015.
///
/// ```
/// # use edition::*;
/// rust_2015! {
/// fn async() {} // `async` isn't a keyword yet.
/// }
/// ```
pub use rust_2015;
/// Switch to Rust 2018.
///
/// ```
/// # use edition::*;
/// rust_2018! {
/// async fn abc() {} // `async` is a keyword now.
/// }
///
/// let _: rust_2018!(&ToString) = &123; // `dyn` isn't required yet.
/// ```
pub use rust_2018;
/// Switch to Rust 2021.
///
/// ```
/// # use edition::*;
/// rust_2021! {
/// // Arrays now implement IntoIter.
/// let _: i32 = [1, 2, 3].into_iter().next().unwrap();
///
/// // But Box<[T]> doesn't yet. (Note the &i32 instead of i32.)
/// let _: &i32 = vec![1, 2, 3].into_boxed_slice().into_iter().next().unwrap();
/// }
/// ```
pub use rust_2021;
/// Switch to Rust 2024.
///
/// ```
/// # use edition::*;
/// rust_2024! {
/// // Box<[T]> now implements IntoIter.
/// let _: i32 = vec![1, 2, 3].into_boxed_slice().into_iter().next().unwrap();
/// }
/// ```
pub use rust_2024;