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
111
112
/*
* Copyright 2022 taylor.fish <contact@taylor.fish>
*
* This file is part of add-syntax.
*
* add-syntax is licensed under the Apache License, Version 2.0
* (the "License"); you may not use add-syntax except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//! Attribute macros that prepend or append arbitrary syntax. Useful with
//! [`cfg_attr`].
//!
//! This crate provides two attribute macros, [`prepend`] and [`append`], that
//! add the tokens passed to them to the start or end of the item to which the
//! attribute is applied, respectively. This is particularly useful with
//! [`cfg_attr`].
//!
//! Example
//! -------
//!
//! Conditionally applying `unsafe` when [`#[may_dangle]`][may_dangle] is used:
//!
//! [may_dangle]: https://github.com/rust-lang/rust/issues/34761
//!
//! ```rust
//! # #![cfg_attr(feature = "dropck_eyepatch", feature(dropck_eyepatch))]
//! # struct Foo<T>(T);
//! #[cfg_attr(feature = "dropck_eyepatch", add_syntax::prepend(unsafe))]
//! impl<#[cfg_attr(feature = "dropck_eyepatch", may_dangle)] T> Drop
//! for Foo<T>
//! {
//! fn drop(&mut self) { /* ... */ }
//! }
//! ```
//!
//! If the hypothetical feature `dropck_eyepatch` is enabled, the code above
//! is equivalent to:
//!
//! ```rust
//! # #![cfg_attr(feature = "dropck_eyepatch", feature(dropck_eyepatch))]
//! # struct Foo<T>(T);
//! # #[cfg(feature = "dropck_eyepatch")]
//! unsafe impl<#[may_dangle] T> Drop for Foo<T> {
//! fn drop(&mut self) { /* ... */ }
//! }
//! ```
//!
//! Otherwise, if the feature is not enabled, the code is equivalent to:
//!
//! ```rust
//! # struct Foo<T>(T);
//! impl<T> Drop for Foo<T> {
//! fn drop(&mut self) { /* ... */ }
//! }
//! ```
//!
//! [`cfg_attr`]:
//! [`prepend`]: macro@prepend
//! [`append`]: macro@append
use ;
/// Adds the tokens provided to this attribute to the start of the item to
/// which this attribute is applied.
/// Adds the tokens provided to this attribute to the end of the item to
/// which this attribute is applied.