|
1 | | -// rustc-cfg emitted by the build script: |
2 | | -// |
3 | | -// "wrap_proc_macro" |
4 | | -// Wrap types from libproc_macro rather than polyfilling the whole API. |
5 | | -// Enabled on rustc 1.29+ as long as procmacro2_semver_exempt is not set, |
6 | | -// because we can't emulate the unstable API without emulating everything |
7 | | -// else. Also enabled unconditionally on nightly, in which case the |
8 | | -// procmacro2_semver_exempt surface area is implemented by using the |
9 | | -// nightly-only proc_macro API. |
10 | | -// |
11 | | -// "hygiene" |
12 | | -// Enable Span::mixed_site() and non-dummy behavior of Span::resolved_at |
13 | | -// and Span::located_at. Enabled on Rust 1.45+. |
14 | | -// |
15 | | -// "proc_macro_span" |
16 | | -// Enable non-dummy behavior of Span::start and Span::end methods which |
17 | | -// requires an unstable compiler feature. Enabled when building with |
18 | | -// nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable |
19 | | -// features. |
20 | | -// |
21 | | -// "super_unstable" |
22 | | -// Implement the semver exempt API in terms of the nightly-only proc_macro |
23 | | -// API. Enabled when using procmacro2_semver_exempt on a nightly compiler. |
24 | | -// |
25 | | -// "span_locations" |
26 | | -// Provide methods Span::start and Span::end which give the line/column |
27 | | -// location of a token. Enabled by procmacro2_semver_exempt or the |
28 | | -// "span-locations" Cargo cfg. This is behind a cfg because tracking |
29 | | -// location inside spans is a performance hit. |
30 | | -// |
31 | | -// "is_available" |
32 | | -// Use proc_macro::is_available() to detect if the proc macro API is |
33 | | -// available or needs to be polyfilled instead of trying to use the proc |
34 | | -// macro API and catching a panic if it isn't available. Enabled on Rust |
35 | | -// 1.57+. |
36 | | - |
37 | 1 | #![allow(unknown_lints)] |
38 | 2 | #![allow(unexpected_cfgs)] |
39 | 3 |
|
@@ -71,18 +35,28 @@ fn main() { |
71 | 35 | } |
72 | 36 |
|
73 | 37 | if semver_exempt || cfg!(feature = "span-locations") { |
| 38 | + // Provide methods Span::start and Span::end which give the line/column |
| 39 | + // location of a token. This is behind a cfg because tracking location |
| 40 | + // inside spans is a performance hit. |
74 | 41 | println!("cargo:rustc-cfg=span_locations"); |
75 | 42 | } |
76 | 43 |
|
77 | 44 | if rustc < 57 { |
| 45 | + // Do not use proc_macro::is_available() to detect whether the proc |
| 46 | + // macro API is available vs needs to be polyfilled. Instead, use the |
| 47 | + // proc macro API unconditionally and catch the panic that occurs if it |
| 48 | + // isn't available. |
78 | 49 | println!("cargo:rustc-cfg=no_is_available"); |
79 | 50 | } |
80 | 51 |
|
81 | 52 | if rustc < 66 { |
| 53 | + // Do not call libproc_macro's Span::source_text. Always return None. |
82 | 54 | println!("cargo:rustc-cfg=no_source_text"); |
83 | 55 | } |
84 | 56 |
|
85 | 57 | if rustc < 79 { |
| 58 | + // Do not call Literal::byte_character nor Literal::c_string. They can |
| 59 | + // be emulated by way of Literal::from_str. |
86 | 60 | println!("cargo:rustc-cfg=no_literal_byte_character"); |
87 | 61 | println!("cargo:rustc-cfg=no_literal_c_string"); |
88 | 62 | } |
@@ -130,14 +104,26 @@ fn main() { |
130 | 104 | } |
131 | 105 |
|
132 | 106 | if proc_macro_span || !semver_exempt { |
| 107 | + // Wrap types from libproc_macro rather than polyfilling the whole API. |
| 108 | + // Enabled as long as procmacro2_semver_exempt is not set, because we |
| 109 | + // can't emulate the unstable API without emulating everything else. |
| 110 | + // Also enabled unconditionally on nightly, in which case the |
| 111 | + // procmacro2_semver_exempt surface area is implemented by using the |
| 112 | + // nightly-only proc_macro API. |
133 | 113 | println!("cargo:rustc-cfg=wrap_proc_macro"); |
134 | 114 | } |
135 | 115 |
|
136 | 116 | if proc_macro_span { |
| 117 | + // Enable non-dummy behavior of Span::start and Span::end methods which |
| 118 | + // requires an unstable compiler feature. Enabled when building with |
| 119 | + // nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable |
| 120 | + // features. |
137 | 121 | println!("cargo:rustc-cfg=proc_macro_span"); |
138 | 122 | } |
139 | 123 |
|
140 | 124 | if semver_exempt && proc_macro_span { |
| 125 | + // Implement the semver exempt API in terms of the nightly-only |
| 126 | + // proc_macro API. |
141 | 127 | println!("cargo:rustc-cfg=super_unstable"); |
142 | 128 | } |
143 | 129 |
|
|
0 commit comments