chore: add vendor dependencies for kauma build
This commit is contained in:
parent
7c94e5d8fb
commit
067ef6141c
1758 changed files with 398473 additions and 0 deletions
1
vendor/proc-macro2/.cargo-checksum.json
vendored
Normal file
1
vendor/proc-macro2/.cargo-checksum.json
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"files":{"Cargo.toml":"634793a6fc0a4fb424d2b8c5f4d84c814494380ad9f5c81ad0730dd1c9a20db1","LICENSE-APACHE":"62c7a1e35f56406896d7aa7ca52d0cc0d272ac022b5d2796e7d6905db8a3636a","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"c609b6865476d6c35879784e9155367a97a0da496aa5c3c61488440a20f59883","build.rs":"cf78c0005f11d54ca42dbaee77cb76a440e6fa2e0b64798d3f74c04770a0ad2b","build/probe.rs":"df0d73191f20c207bb1051a4944fb6962e1f632d1e0535aba4b995aa7feba8d1","rust-toolchain.toml":"6bbb61302978c736b2da03e4fb40e3beab908f85d533ab46fd541e637b5f3e0f","src/detection.rs":"ed9a5f9a979ab01247d7a68eeb1afa3c13209334c5bfff0f9289cb07e5bb4e8b","src/extra.rs":"29f094473279a29b71c3cc9f5fa27c2e2c30c670390cf7e4b7cf451486cc857e","src/fallback.rs":"be1ce5e32c88c29d41d2ab663375951817d52decce3dc9e335ec22378be8fa65","src/lib.rs":"b073933783beae6a8f43635eace6250dbfa2bdf4ebed0049f112d034af7c2183","src/location.rs":"9225c5a55f03b56cce42bc55ceb509e8216a5e0b24c94aa1cd071b04e3d6c15f","src/marker.rs":"c11c5a1be8bdf18be3fcd224393f350a9aae7ce282e19ce583c84910c6903a8f","src/parse.rs":"4b77cddbc2752bc4d38a65acd8b96b6786c5220d19b1e1b37810257b5d24132d","src/rcvec.rs":"1c3c48c4f819927cc445ae15ca3bb06775feff2fd1cb21901ae4c40c7e6b4e82","src/wrapper.rs":"d4afc41f00ca40088b50e35c0b622fb8b72ca7c091385c528d0290e44dfd07a5","tests/comments.rs":"31115b3a56c83d93eef2fb4c9566bf4543e302560732986161b98aef504785ed","tests/features.rs":"a86deb8644992a4eb64d9fd493eff16f9cf9c5cb6ade3a634ce0c990cf87d559","tests/marker.rs":"473e962ee1aa0633dd5cf9a973b3bbd0ef43b740d4b7f6d008ff455a6b89d386","tests/test.rs":"2e7106f582367d168638be7364d4e9aadbe0affca8b51dd80f0b3977cc2fcf83","tests/test_fmt.rs":"b7743b612af65f2c88cbe109d50a093db7aa7e87f9e37bf45b7bbaeb240aa020","tests/test_size.rs":"62d8373ea46b669b87bc90a9c49b6d02f90ff4c21f9a25acebf60c9926e01fb7"},"package":"7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9"}
|
||||
105
vendor/proc-macro2/Cargo.toml
vendored
Normal file
105
vendor/proc-macro2/Cargo.toml
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g., crates.io) dependencies.
|
||||
#
|
||||
# If you are reading this file be aware that the original Cargo.toml
|
||||
# will likely look very different (and much more reasonable).
|
||||
# See Cargo.toml.orig for the original contents.
|
||||
|
||||
[package]
|
||||
edition = "2021"
|
||||
rust-version = "1.56"
|
||||
name = "proc-macro2"
|
||||
version = "1.0.88"
|
||||
authors = [
|
||||
"David Tolnay <dtolnay@gmail.com>",
|
||||
"Alex Crichton <alex@alexcrichton.com>",
|
||||
]
|
||||
build = "build.rs"
|
||||
autolib = false
|
||||
autobins = false
|
||||
autoexamples = false
|
||||
autotests = false
|
||||
autobenches = false
|
||||
description = "A substitute implementation of the compiler's `proc_macro` API to decouple token-based libraries from the procedural macro use case."
|
||||
documentation = "https://docs.rs/proc-macro2"
|
||||
readme = "README.md"
|
||||
keywords = [
|
||||
"macros",
|
||||
"syn",
|
||||
]
|
||||
categories = ["development-tools::procedural-macro-helpers"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/dtolnay/proc-macro2"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
rustc-args = [
|
||||
"--cfg",
|
||||
"procmacro2_semver_exempt",
|
||||
]
|
||||
rustdoc-args = [
|
||||
"--cfg",
|
||||
"procmacro2_semver_exempt",
|
||||
"--generate-link-to-definition",
|
||||
]
|
||||
targets = ["x86_64-unknown-linux-gnu"]
|
||||
|
||||
[package.metadata.playground]
|
||||
features = ["span-locations"]
|
||||
|
||||
[lib]
|
||||
name = "proc_macro2"
|
||||
path = "src/lib.rs"
|
||||
doc-scrape-examples = false
|
||||
|
||||
[[test]]
|
||||
name = "comments"
|
||||
path = "tests/comments.rs"
|
||||
|
||||
[[test]]
|
||||
name = "features"
|
||||
path = "tests/features.rs"
|
||||
|
||||
[[test]]
|
||||
name = "marker"
|
||||
path = "tests/marker.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test"
|
||||
path = "tests/test.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_fmt"
|
||||
path = "tests/test_fmt.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_size"
|
||||
path = "tests/test_size.rs"
|
||||
|
||||
[dependencies.unicode-ident]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.flate2]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.quote]
|
||||
version = "1.0"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies.rayon]
|
||||
version = "1.0"
|
||||
|
||||
[dev-dependencies.rustversion]
|
||||
version = "1"
|
||||
|
||||
[dev-dependencies.tar]
|
||||
version = "0.4"
|
||||
|
||||
[features]
|
||||
default = ["proc-macro"]
|
||||
nightly = []
|
||||
proc-macro = []
|
||||
span-locations = []
|
||||
176
vendor/proc-macro2/LICENSE-APACHE
vendored
Normal file
176
vendor/proc-macro2/LICENSE-APACHE
vendored
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
23
vendor/proc-macro2/LICENSE-MIT
vendored
Normal file
23
vendor/proc-macro2/LICENSE-MIT
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
94
vendor/proc-macro2/README.md
vendored
Normal file
94
vendor/proc-macro2/README.md
vendored
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# proc-macro2
|
||||
|
||||
[<img alt="github" src="https://img.shields.io/badge/github-dtolnay/proc--macro2-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/proc-macro2)
|
||||
[<img alt="crates.io" src="https://img.shields.io/crates/v/proc-macro2.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/proc-macro2)
|
||||
[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-proc--macro2-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/proc-macro2)
|
||||
[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/proc-macro2/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/proc-macro2/actions?query=branch%3Amaster)
|
||||
|
||||
A wrapper around the procedural macro API of the compiler's `proc_macro` crate.
|
||||
This library serves two purposes:
|
||||
|
||||
- **Bring proc-macro-like functionality to other contexts like build.rs and
|
||||
main.rs.** Types from `proc_macro` are entirely specific to procedural macros
|
||||
and cannot ever exist in code outside of a procedural macro. Meanwhile
|
||||
`proc_macro2` types may exist anywhere including non-macro code. By developing
|
||||
foundational libraries like [syn] and [quote] against `proc_macro2` rather
|
||||
than `proc_macro`, the procedural macro ecosystem becomes easily applicable to
|
||||
many other use cases and we avoid reimplementing non-macro equivalents of
|
||||
those libraries.
|
||||
|
||||
- **Make procedural macros unit testable.** As a consequence of being specific
|
||||
to procedural macros, nothing that uses `proc_macro` can be executed from a
|
||||
unit test. In order for helper libraries or components of a macro to be
|
||||
testable in isolation, they must be implemented using `proc_macro2`.
|
||||
|
||||
[syn]: https://github.com/dtolnay/syn
|
||||
[quote]: https://github.com/dtolnay/quote
|
||||
|
||||
## Usage
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
```
|
||||
|
||||
The skeleton of a typical procedural macro typically looks like this:
|
||||
|
||||
```rust
|
||||
extern crate proc_macro;
|
||||
|
||||
#[proc_macro_derive(MyDerive)]
|
||||
pub fn my_derive(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let input = proc_macro2::TokenStream::from(input);
|
||||
|
||||
let output: proc_macro2::TokenStream = {
|
||||
/* transform input */
|
||||
};
|
||||
|
||||
proc_macro::TokenStream::from(output)
|
||||
}
|
||||
```
|
||||
|
||||
If parsing with [Syn], you'll use [`parse_macro_input!`] instead to propagate
|
||||
parse errors correctly back to the compiler when parsing fails.
|
||||
|
||||
[`parse_macro_input!`]: https://docs.rs/syn/2.0/syn/macro.parse_macro_input.html
|
||||
|
||||
## Unstable features
|
||||
|
||||
The default feature set of proc-macro2 tracks the most recent stable compiler
|
||||
API. Functionality in `proc_macro` that is not yet stable is not exposed by
|
||||
proc-macro2 by default.
|
||||
|
||||
To opt into the additional APIs available in the most recent nightly compiler,
|
||||
the `procmacro2_semver_exempt` config flag must be passed to rustc. We will
|
||||
polyfill those nightly-only APIs back to Rust 1.56.0. As these are unstable APIs
|
||||
that track the nightly compiler, minor versions of proc-macro2 may make breaking
|
||||
changes to them at any time.
|
||||
|
||||
```
|
||||
RUSTFLAGS='--cfg procmacro2_semver_exempt' cargo build
|
||||
```
|
||||
|
||||
Note that this must not only be done for your crate, but for any crate that
|
||||
depends on your crate. This infectious nature is intentional, as it serves as a
|
||||
reminder that you are outside of the normal semver guarantees.
|
||||
|
||||
Semver exempt methods are marked as such in the proc-macro2 documentation.
|
||||
|
||||
<br>
|
||||
|
||||
#### License
|
||||
|
||||
<sup>
|
||||
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
|
||||
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
|
||||
</sup>
|
||||
|
||||
<br>
|
||||
|
||||
<sub>
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
|
||||
be dual licensed as above, without any additional terms or conditions.
|
||||
</sub>
|
||||
213
vendor/proc-macro2/build.rs
vendored
Normal file
213
vendor/proc-macro2/build.rs
vendored
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
#![allow(unknown_lints)]
|
||||
#![allow(unexpected_cfgs)]
|
||||
|
||||
use std::env;
|
||||
use std::ffi::OsString;
|
||||
use std::iter;
|
||||
use std::path::Path;
|
||||
use std::process::{self, Command, Stdio};
|
||||
use std::str;
|
||||
|
||||
fn main() {
|
||||
let rustc = rustc_minor_version().unwrap_or(u32::MAX);
|
||||
|
||||
if rustc >= 80 {
|
||||
println!("cargo:rustc-check-cfg=cfg(fuzzing)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_is_available)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_literal_byte_character)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_literal_c_string)");
|
||||
println!("cargo:rustc-check-cfg=cfg(no_source_text)");
|
||||
println!("cargo:rustc-check-cfg=cfg(proc_macro_span)");
|
||||
println!("cargo:rustc-check-cfg=cfg(procmacro2_backtrace)");
|
||||
println!("cargo:rustc-check-cfg=cfg(procmacro2_nightly_testing)");
|
||||
println!("cargo:rustc-check-cfg=cfg(procmacro2_semver_exempt)");
|
||||
println!("cargo:rustc-check-cfg=cfg(randomize_layout)");
|
||||
println!("cargo:rustc-check-cfg=cfg(span_locations)");
|
||||
println!("cargo:rustc-check-cfg=cfg(super_unstable)");
|
||||
println!("cargo:rustc-check-cfg=cfg(wrap_proc_macro)");
|
||||
}
|
||||
|
||||
let docs_rs = env::var_os("DOCS_RS").is_some();
|
||||
let semver_exempt = cfg!(procmacro2_semver_exempt) || docs_rs;
|
||||
if semver_exempt {
|
||||
// https://github.com/dtolnay/proc-macro2/issues/147
|
||||
println!("cargo:rustc-cfg=procmacro2_semver_exempt");
|
||||
}
|
||||
|
||||
if semver_exempt || cfg!(feature = "span-locations") {
|
||||
// Provide methods Span::start and Span::end which give the line/column
|
||||
// location of a token. This is behind a cfg because tracking location
|
||||
// inside spans is a performance hit.
|
||||
println!("cargo:rustc-cfg=span_locations");
|
||||
}
|
||||
|
||||
if rustc < 57 {
|
||||
// Do not use proc_macro::is_available() to detect whether the proc
|
||||
// macro API is available vs needs to be polyfilled. Instead, use the
|
||||
// proc macro API unconditionally and catch the panic that occurs if it
|
||||
// isn't available.
|
||||
println!("cargo:rustc-cfg=no_is_available");
|
||||
}
|
||||
|
||||
if rustc < 66 {
|
||||
// Do not call libproc_macro's Span::source_text. Always return None.
|
||||
println!("cargo:rustc-cfg=no_source_text");
|
||||
}
|
||||
|
||||
if rustc < 79 {
|
||||
// Do not call Literal::byte_character nor Literal::c_string. They can
|
||||
// be emulated by way of Literal::from_str.
|
||||
println!("cargo:rustc-cfg=no_literal_byte_character");
|
||||
println!("cargo:rustc-cfg=no_literal_c_string");
|
||||
}
|
||||
|
||||
if !cfg!(feature = "proc-macro") {
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
return;
|
||||
}
|
||||
|
||||
println!("cargo:rerun-if-changed=build/probe.rs");
|
||||
|
||||
let proc_macro_span;
|
||||
let consider_rustc_bootstrap;
|
||||
if compile_probe(false) {
|
||||
// This is a nightly or dev compiler, so it supports unstable features
|
||||
// regardless of RUSTC_BOOTSTRAP. No need to rerun build script if
|
||||
// RUSTC_BOOTSTRAP is changed.
|
||||
proc_macro_span = true;
|
||||
consider_rustc_bootstrap = false;
|
||||
} else if let Some(rustc_bootstrap) = env::var_os("RUSTC_BOOTSTRAP") {
|
||||
if compile_probe(true) {
|
||||
// This is a stable or beta compiler for which the user has set
|
||||
// RUSTC_BOOTSTRAP to turn on unstable features. Rerun build script
|
||||
// if they change it.
|
||||
proc_macro_span = true;
|
||||
consider_rustc_bootstrap = true;
|
||||
} else if rustc_bootstrap == "1" {
|
||||
// This compiler does not support the proc macro Span API in the
|
||||
// form that proc-macro2 expects. No need to pay attention to
|
||||
// RUSTC_BOOTSTRAP.
|
||||
proc_macro_span = false;
|
||||
consider_rustc_bootstrap = false;
|
||||
} else {
|
||||
// This is a stable or beta compiler for which RUSTC_BOOTSTRAP is
|
||||
// set to restrict the use of unstable features by this crate.
|
||||
proc_macro_span = false;
|
||||
consider_rustc_bootstrap = true;
|
||||
}
|
||||
} else {
|
||||
// Without RUSTC_BOOTSTRAP, this compiler does not support the proc
|
||||
// macro Span API in the form that proc-macro2 expects, but try again if
|
||||
// the user turns on unstable features.
|
||||
proc_macro_span = false;
|
||||
consider_rustc_bootstrap = true;
|
||||
}
|
||||
|
||||
if proc_macro_span || !semver_exempt {
|
||||
// Wrap types from libproc_macro rather than polyfilling the whole API.
|
||||
// Enabled as long as procmacro2_semver_exempt is not set, because we
|
||||
// can't emulate the unstable API without emulating everything else.
|
||||
// Also enabled unconditionally on nightly, in which case the
|
||||
// procmacro2_semver_exempt surface area is implemented by using the
|
||||
// nightly-only proc_macro API.
|
||||
println!("cargo:rustc-cfg=wrap_proc_macro");
|
||||
}
|
||||
|
||||
if proc_macro_span {
|
||||
// Enable non-dummy behavior of Span::start and Span::end methods which
|
||||
// requires an unstable compiler feature. Enabled when building with
|
||||
// nightly, unless `-Z allow-feature` in RUSTFLAGS disallows unstable
|
||||
// features.
|
||||
println!("cargo:rustc-cfg=proc_macro_span");
|
||||
}
|
||||
|
||||
if semver_exempt && proc_macro_span {
|
||||
// Implement the semver exempt API in terms of the nightly-only
|
||||
// proc_macro API.
|
||||
println!("cargo:rustc-cfg=super_unstable");
|
||||
}
|
||||
|
||||
if consider_rustc_bootstrap {
|
||||
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
|
||||
}
|
||||
}
|
||||
|
||||
fn compile_probe(rustc_bootstrap: bool) -> bool {
|
||||
if env::var_os("RUSTC_STAGE").is_some() {
|
||||
// We are running inside rustc bootstrap. This is a highly non-standard
|
||||
// environment with issues such as:
|
||||
//
|
||||
// https://github.com/rust-lang/cargo/issues/11138
|
||||
// https://github.com/rust-lang/rust/issues/114839
|
||||
//
|
||||
// Let's just not use nightly features here.
|
||||
return false;
|
||||
}
|
||||
|
||||
let rustc = cargo_env_var("RUSTC");
|
||||
let out_dir = cargo_env_var("OUT_DIR");
|
||||
let probefile = Path::new("build").join("probe.rs");
|
||||
|
||||
let rustc_wrapper = env::var_os("RUSTC_WRAPPER").filter(|wrapper| !wrapper.is_empty());
|
||||
let rustc_workspace_wrapper =
|
||||
env::var_os("RUSTC_WORKSPACE_WRAPPER").filter(|wrapper| !wrapper.is_empty());
|
||||
let mut rustc = rustc_wrapper
|
||||
.into_iter()
|
||||
.chain(rustc_workspace_wrapper)
|
||||
.chain(iter::once(rustc));
|
||||
let mut cmd = Command::new(rustc.next().unwrap());
|
||||
cmd.args(rustc);
|
||||
|
||||
if !rustc_bootstrap {
|
||||
cmd.env_remove("RUSTC_BOOTSTRAP");
|
||||
}
|
||||
|
||||
cmd.stderr(Stdio::null())
|
||||
.arg("--edition=2021")
|
||||
.arg("--crate-name=proc_macro2")
|
||||
.arg("--crate-type=lib")
|
||||
.arg("--cap-lints=allow")
|
||||
.arg("--emit=dep-info,metadata")
|
||||
.arg("--out-dir")
|
||||
.arg(out_dir)
|
||||
.arg(probefile);
|
||||
|
||||
if let Some(target) = env::var_os("TARGET") {
|
||||
cmd.arg("--target").arg(target);
|
||||
}
|
||||
|
||||
// If Cargo wants to set RUSTFLAGS, use that.
|
||||
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
|
||||
if !rustflags.is_empty() {
|
||||
for arg in rustflags.split('\x1f') {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match cmd.status() {
|
||||
Ok(status) => status.success(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn rustc_minor_version() -> Option<u32> {
|
||||
let rustc = cargo_env_var("RUSTC");
|
||||
let output = Command::new(rustc).arg("--version").output().ok()?;
|
||||
let version = str::from_utf8(&output.stdout).ok()?;
|
||||
let mut pieces = version.split('.');
|
||||
if pieces.next() != Some("rustc 1") {
|
||||
return None;
|
||||
}
|
||||
pieces.next()?.parse().ok()
|
||||
}
|
||||
|
||||
fn cargo_env_var(key: &str) -> OsString {
|
||||
env::var_os(key).unwrap_or_else(|| {
|
||||
eprintln!(
|
||||
"Environment variable ${} is not set during execution of build script",
|
||||
key,
|
||||
);
|
||||
process::exit(1);
|
||||
})
|
||||
}
|
||||
41
vendor/proc-macro2/build/probe.rs
vendored
Normal file
41
vendor/proc-macro2/build/probe.rs
vendored
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
// This code exercises the surface area that we expect of Span's unstable API.
|
||||
// If the current toolchain is able to compile it, then proc-macro2 is able to
|
||||
// offer these APIs too.
|
||||
|
||||
#![feature(proc_macro_span)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use core::ops::{Range, RangeBounds};
|
||||
use proc_macro::{Literal, Span};
|
||||
|
||||
pub fn byte_range(this: &Span) -> Range<usize> {
|
||||
this.byte_range()
|
||||
}
|
||||
|
||||
pub fn start(this: &Span) -> Span {
|
||||
this.start()
|
||||
}
|
||||
|
||||
pub fn end(this: &Span) -> Span {
|
||||
this.end()
|
||||
}
|
||||
|
||||
pub fn line(this: &Span) -> usize {
|
||||
this.line()
|
||||
}
|
||||
|
||||
pub fn column(this: &Span) -> usize {
|
||||
this.column()
|
||||
}
|
||||
|
||||
pub fn join(this: &Span, other: Span) -> Option<Span> {
|
||||
this.join(other)
|
||||
}
|
||||
|
||||
pub fn subspan<R: RangeBounds<usize>>(this: &Literal, range: R) -> Option<Span> {
|
||||
this.subspan(range)
|
||||
}
|
||||
|
||||
// Include in sccache cache key.
|
||||
const _: Option<&str> = option_env!("RUSTC_BOOTSTRAP");
|
||||
2
vendor/proc-macro2/rust-toolchain.toml
vendored
Normal file
2
vendor/proc-macro2/rust-toolchain.toml
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[toolchain]
|
||||
components = ["rust-src"]
|
||||
75
vendor/proc-macro2/src/detection.rs
vendored
Normal file
75
vendor/proc-macro2/src/detection.rs
vendored
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::Once;
|
||||
|
||||
static WORKS: AtomicUsize = AtomicUsize::new(0);
|
||||
static INIT: Once = Once::new();
|
||||
|
||||
pub(crate) fn inside_proc_macro() -> bool {
|
||||
match WORKS.load(Ordering::Relaxed) {
|
||||
1 => return false,
|
||||
2 => return true,
|
||||
_ => {}
|
||||
}
|
||||
|
||||
INIT.call_once(initialize);
|
||||
inside_proc_macro()
|
||||
}
|
||||
|
||||
pub(crate) fn force_fallback() {
|
||||
WORKS.store(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub(crate) fn unforce_fallback() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
#[cfg(not(no_is_available))]
|
||||
fn initialize() {
|
||||
let available = proc_macro::is_available();
|
||||
WORKS.store(available as usize + 1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
// Swap in a null panic hook to avoid printing "thread panicked" to stderr,
|
||||
// then use catch_unwind to determine whether the compiler's proc_macro is
|
||||
// working. When proc-macro2 is used from outside of a procedural macro all
|
||||
// of the proc_macro crate's APIs currently panic.
|
||||
//
|
||||
// The Once is to prevent the possibility of this ordering:
|
||||
//
|
||||
// thread 1 calls take_hook, gets the user's original hook
|
||||
// thread 1 calls set_hook with the null hook
|
||||
// thread 2 calls take_hook, thinks null hook is the original hook
|
||||
// thread 2 calls set_hook with the null hook
|
||||
// thread 1 calls set_hook with the actual original hook
|
||||
// thread 2 calls set_hook with what it thinks is the original hook
|
||||
//
|
||||
// in which the user's hook has been lost.
|
||||
//
|
||||
// There is still a race condition where a panic in a different thread can
|
||||
// happen during the interval that the user's original panic hook is
|
||||
// unregistered such that their hook is incorrectly not called. This is
|
||||
// sufficiently unlikely and less bad than printing panic messages to stderr
|
||||
// on correct use of this crate. Maybe there is a libstd feature request
|
||||
// here. For now, if a user needs to guarantee that this failure mode does
|
||||
// not occur, they need to call e.g. `proc_macro2::Span::call_site()` from
|
||||
// the main thread before launching any other threads.
|
||||
#[cfg(no_is_available)]
|
||||
fn initialize() {
|
||||
use std::panic::{self, PanicInfo};
|
||||
|
||||
type PanicHook = dyn Fn(&PanicInfo) + Sync + Send + 'static;
|
||||
|
||||
let null_hook: Box<PanicHook> = Box::new(|_panic_info| { /* ignore */ });
|
||||
let sanity_check = &*null_hook as *const PanicHook;
|
||||
let original_hook = panic::take_hook();
|
||||
panic::set_hook(null_hook);
|
||||
|
||||
let works = panic::catch_unwind(proc_macro::Span::call_site).is_ok();
|
||||
WORKS.store(works as usize + 1, Ordering::Relaxed);
|
||||
|
||||
let hopefully_null_hook = panic::take_hook();
|
||||
panic::set_hook(original_hook);
|
||||
if sanity_check != &*hopefully_null_hook {
|
||||
panic!("observed race condition in proc_macro2::inside_proc_macro");
|
||||
}
|
||||
}
|
||||
151
vendor/proc-macro2/src/extra.rs
vendored
Normal file
151
vendor/proc-macro2/src/extra.rs
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
//! Items which do not have a correspondence to any API in the proc_macro crate,
|
||||
//! but are necessary to include in proc-macro2.
|
||||
|
||||
use crate::fallback;
|
||||
use crate::imp;
|
||||
use crate::marker::{ProcMacroAutoTraits, MARKER};
|
||||
use crate::Span;
|
||||
use core::fmt::{self, Debug};
|
||||
|
||||
/// Invalidate any `proc_macro2::Span` that exist on the current thread.
|
||||
///
|
||||
/// The implementation of `Span` uses thread-local data structures and this
|
||||
/// function clears them. Calling any method on a `Span` on the current thread
|
||||
/// created prior to the invalidation will return incorrect values or crash.
|
||||
///
|
||||
/// This function is useful for programs that process more than 2<sup>32</sup>
|
||||
/// bytes of Rust source code on the same thread. Just like rustc, proc-macro2
|
||||
/// uses 32-bit source locations, and these wrap around when the total source
|
||||
/// code processed by the same thread exceeds 2<sup>32</sup> bytes (4
|
||||
/// gigabytes). After a wraparound, `Span` methods such as `source_text()` can
|
||||
/// return wrong data.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// As of late 2023, there is 200 GB of Rust code published on crates.io.
|
||||
/// Looking at just the newest version of every crate, it is 16 GB of code. So a
|
||||
/// workload that involves parsing it all would overflow a 32-bit source
|
||||
/// location unless spans are being invalidated.
|
||||
///
|
||||
/// ```
|
||||
/// use flate2::read::GzDecoder;
|
||||
/// use std::ffi::OsStr;
|
||||
/// use std::io::{BufReader, Read};
|
||||
/// use std::str::FromStr;
|
||||
/// use tar::Archive;
|
||||
///
|
||||
/// rayon::scope(|s| {
|
||||
/// for krate in every_version_of_every_crate() {
|
||||
/// s.spawn(move |_| {
|
||||
/// proc_macro2::extra::invalidate_current_thread_spans();
|
||||
///
|
||||
/// let reader = BufReader::new(krate);
|
||||
/// let tar = GzDecoder::new(reader);
|
||||
/// let mut archive = Archive::new(tar);
|
||||
/// for entry in archive.entries().unwrap() {
|
||||
/// let mut entry = entry.unwrap();
|
||||
/// let path = entry.path().unwrap();
|
||||
/// if path.extension() != Some(OsStr::new("rs")) {
|
||||
/// continue;
|
||||
/// }
|
||||
/// let mut content = String::new();
|
||||
/// entry.read_to_string(&mut content).unwrap();
|
||||
/// match proc_macro2::TokenStream::from_str(&content) {
|
||||
/// Ok(tokens) => {/* ... */},
|
||||
/// Err(_) => continue,
|
||||
/// }
|
||||
/// }
|
||||
/// });
|
||||
/// }
|
||||
/// });
|
||||
/// #
|
||||
/// # fn every_version_of_every_crate() -> Vec<std::fs::File> {
|
||||
/// # Vec::new()
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This function is not applicable to and will panic if called from a
|
||||
/// procedural macro.
|
||||
#[cfg(span_locations)]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))]
|
||||
pub fn invalidate_current_thread_spans() {
|
||||
crate::imp::invalidate_current_thread_spans();
|
||||
}
|
||||
|
||||
/// An object that holds a [`Group`]'s `span_open()` and `span_close()` together
|
||||
/// in a more compact representation than holding those 2 spans individually.
|
||||
///
|
||||
/// [`Group`]: crate::Group
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct DelimSpan {
|
||||
inner: DelimSpanEnum,
|
||||
_marker: ProcMacroAutoTraits,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum DelimSpanEnum {
|
||||
#[cfg(wrap_proc_macro)]
|
||||
Compiler {
|
||||
join: proc_macro::Span,
|
||||
open: proc_macro::Span,
|
||||
close: proc_macro::Span,
|
||||
},
|
||||
Fallback(fallback::Span),
|
||||
}
|
||||
|
||||
impl DelimSpan {
|
||||
pub(crate) fn new(group: &imp::Group) -> Self {
|
||||
#[cfg(wrap_proc_macro)]
|
||||
let inner = match group {
|
||||
imp::Group::Compiler(group) => DelimSpanEnum::Compiler {
|
||||
join: group.span(),
|
||||
open: group.span_open(),
|
||||
close: group.span_close(),
|
||||
},
|
||||
imp::Group::Fallback(group) => DelimSpanEnum::Fallback(group.span()),
|
||||
};
|
||||
|
||||
#[cfg(not(wrap_proc_macro))]
|
||||
let inner = DelimSpanEnum::Fallback(group.span());
|
||||
|
||||
DelimSpan {
|
||||
inner,
|
||||
_marker: MARKER,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a span covering the entire delimited group.
|
||||
pub fn join(&self) -> Span {
|
||||
match &self.inner {
|
||||
#[cfg(wrap_proc_macro)]
|
||||
DelimSpanEnum::Compiler { join, .. } => Span::_new(imp::Span::Compiler(*join)),
|
||||
DelimSpanEnum::Fallback(span) => Span::_new_fallback(*span),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a span for the opening punctuation of the group only.
|
||||
pub fn open(&self) -> Span {
|
||||
match &self.inner {
|
||||
#[cfg(wrap_proc_macro)]
|
||||
DelimSpanEnum::Compiler { open, .. } => Span::_new(imp::Span::Compiler(*open)),
|
||||
DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.first_byte()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a span for the closing punctuation of the group only.
|
||||
pub fn close(&self) -> Span {
|
||||
match &self.inner {
|
||||
#[cfg(wrap_proc_macro)]
|
||||
DelimSpanEnum::Compiler { close, .. } => Span::_new(imp::Span::Compiler(*close)),
|
||||
DelimSpanEnum::Fallback(span) => Span::_new_fallback(span.last_byte()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for DelimSpan {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
Debug::fmt(&self.join(), f)
|
||||
}
|
||||
}
|
||||
1226
vendor/proc-macro2/src/fallback.rs
vendored
Normal file
1226
vendor/proc-macro2/src/fallback.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
1377
vendor/proc-macro2/src/lib.rs
vendored
Normal file
1377
vendor/proc-macro2/src/lib.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
29
vendor/proc-macro2/src/location.rs
vendored
Normal file
29
vendor/proc-macro2/src/location.rs
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use core::cmp::Ordering;
|
||||
|
||||
/// A line-column pair representing the start or end of a `Span`.
|
||||
///
|
||||
/// This type is semver exempt and not exposed by default.
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "span-locations")))]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct LineColumn {
|
||||
/// The 1-indexed line in the source file on which the span starts or ends
|
||||
/// (inclusive).
|
||||
pub line: usize,
|
||||
/// The 0-indexed column (in UTF-8 characters) in the source file on which
|
||||
/// the span starts or ends (inclusive).
|
||||
pub column: usize,
|
||||
}
|
||||
|
||||
impl Ord for LineColumn {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.line
|
||||
.cmp(&other.line)
|
||||
.then(self.column.cmp(&other.column))
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for LineColumn {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
17
vendor/proc-macro2/src/marker.rs
vendored
Normal file
17
vendor/proc-macro2/src/marker.rs
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use alloc::rc::Rc;
|
||||
use core::marker::PhantomData;
|
||||
use core::panic::{RefUnwindSafe, UnwindSafe};
|
||||
|
||||
// Zero sized marker with the correct set of autotrait impls we want all proc
|
||||
// macro types to have.
|
||||
#[derive(Copy, Clone)]
|
||||
#[cfg_attr(
|
||||
all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)),
|
||||
derive(PartialEq, Eq)
|
||||
)]
|
||||
pub(crate) struct ProcMacroAutoTraits(PhantomData<Rc<()>>);
|
||||
|
||||
pub(crate) const MARKER: ProcMacroAutoTraits = ProcMacroAutoTraits(PhantomData);
|
||||
|
||||
impl UnwindSafe for ProcMacroAutoTraits {}
|
||||
impl RefUnwindSafe for ProcMacroAutoTraits {}
|
||||
996
vendor/proc-macro2/src/parse.rs
vendored
Normal file
996
vendor/proc-macro2/src/parse.rs
vendored
Normal file
|
|
@ -0,0 +1,996 @@
|
|||
use crate::fallback::{
|
||||
self, is_ident_continue, is_ident_start, Group, LexError, Literal, Span, TokenStream,
|
||||
TokenStreamBuilder,
|
||||
};
|
||||
use crate::{Delimiter, Punct, Spacing, TokenTree};
|
||||
use core::char;
|
||||
use core::str::{Bytes, CharIndices, Chars};
|
||||
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub(crate) struct Cursor<'a> {
|
||||
pub rest: &'a str,
|
||||
#[cfg(span_locations)]
|
||||
pub off: u32,
|
||||
}
|
||||
|
||||
impl<'a> Cursor<'a> {
|
||||
pub fn advance(&self, bytes: usize) -> Cursor<'a> {
|
||||
let (_front, rest) = self.rest.split_at(bytes);
|
||||
Cursor {
|
||||
rest,
|
||||
#[cfg(span_locations)]
|
||||
off: self.off + _front.chars().count() as u32,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn starts_with(&self, s: &str) -> bool {
|
||||
self.rest.starts_with(s)
|
||||
}
|
||||
|
||||
pub fn starts_with_char(&self, ch: char) -> bool {
|
||||
self.rest.starts_with(ch)
|
||||
}
|
||||
|
||||
pub fn starts_with_fn<Pattern>(&self, f: Pattern) -> bool
|
||||
where
|
||||
Pattern: FnMut(char) -> bool,
|
||||
{
|
||||
self.rest.starts_with(f)
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.rest.is_empty()
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.rest.len()
|
||||
}
|
||||
|
||||
fn as_bytes(&self) -> &'a [u8] {
|
||||
self.rest.as_bytes()
|
||||
}
|
||||
|
||||
fn bytes(&self) -> Bytes<'a> {
|
||||
self.rest.bytes()
|
||||
}
|
||||
|
||||
fn chars(&self) -> Chars<'a> {
|
||||
self.rest.chars()
|
||||
}
|
||||
|
||||
fn char_indices(&self) -> CharIndices<'a> {
|
||||
self.rest.char_indices()
|
||||
}
|
||||
|
||||
fn parse(&self, tag: &str) -> Result<Cursor<'a>, Reject> {
|
||||
if self.starts_with(tag) {
|
||||
Ok(self.advance(tag.len()))
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct Reject;
|
||||
type PResult<'a, O> = Result<(Cursor<'a>, O), Reject>;
|
||||
|
||||
fn skip_whitespace(input: Cursor) -> Cursor {
|
||||
let mut s = input;
|
||||
|
||||
while !s.is_empty() {
|
||||
let byte = s.as_bytes()[0];
|
||||
if byte == b'/' {
|
||||
if s.starts_with("//")
|
||||
&& (!s.starts_with("///") || s.starts_with("////"))
|
||||
&& !s.starts_with("//!")
|
||||
{
|
||||
let (cursor, _) = take_until_newline_or_eof(s);
|
||||
s = cursor;
|
||||
continue;
|
||||
} else if s.starts_with("/**/") {
|
||||
s = s.advance(4);
|
||||
continue;
|
||||
} else if s.starts_with("/*")
|
||||
&& (!s.starts_with("/**") || s.starts_with("/***"))
|
||||
&& !s.starts_with("/*!")
|
||||
{
|
||||
match block_comment(s) {
|
||||
Ok((rest, _)) => {
|
||||
s = rest;
|
||||
continue;
|
||||
}
|
||||
Err(Reject) => return s,
|
||||
}
|
||||
}
|
||||
}
|
||||
match byte {
|
||||
b' ' | 0x09..=0x0d => {
|
||||
s = s.advance(1);
|
||||
continue;
|
||||
}
|
||||
b if b.is_ascii() => {}
|
||||
_ => {
|
||||
let ch = s.chars().next().unwrap();
|
||||
if is_whitespace(ch) {
|
||||
s = s.advance(ch.len_utf8());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
s
|
||||
}
|
||||
|
||||
fn block_comment(input: Cursor) -> PResult<&str> {
|
||||
if !input.starts_with("/*") {
|
||||
return Err(Reject);
|
||||
}
|
||||
|
||||
let mut depth = 0usize;
|
||||
let bytes = input.as_bytes();
|
||||
let mut i = 0usize;
|
||||
let upper = bytes.len() - 1;
|
||||
|
||||
while i < upper {
|
||||
if bytes[i] == b'/' && bytes[i + 1] == b'*' {
|
||||
depth += 1;
|
||||
i += 1; // eat '*'
|
||||
} else if bytes[i] == b'*' && bytes[i + 1] == b'/' {
|
||||
depth -= 1;
|
||||
if depth == 0 {
|
||||
return Ok((input.advance(i + 2), &input.rest[..i + 2]));
|
||||
}
|
||||
i += 1; // eat '/'
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn is_whitespace(ch: char) -> bool {
|
||||
// Rust treats left-to-right mark and right-to-left mark as whitespace
|
||||
ch.is_whitespace() || ch == '\u{200e}' || ch == '\u{200f}'
|
||||
}
|
||||
|
||||
fn word_break(input: Cursor) -> Result<Cursor, Reject> {
|
||||
match input.chars().next() {
|
||||
Some(ch) if is_ident_continue(ch) => Err(Reject),
|
||||
Some(_) | None => Ok(input),
|
||||
}
|
||||
}
|
||||
|
||||
// Rustc's representation of a macro expansion error in expression position or
|
||||
// type position.
|
||||
const ERROR: &str = "(/*ERROR*/)";
|
||||
|
||||
pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> {
|
||||
let mut trees = TokenStreamBuilder::new();
|
||||
let mut stack = Vec::new();
|
||||
|
||||
loop {
|
||||
input = skip_whitespace(input);
|
||||
|
||||
if let Ok((rest, ())) = doc_comment(input, &mut trees) {
|
||||
input = rest;
|
||||
continue;
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
let lo = input.off;
|
||||
|
||||
let first = match input.bytes().next() {
|
||||
Some(first) => first,
|
||||
None => match stack.last() {
|
||||
None => return Ok(trees.build()),
|
||||
#[cfg(span_locations)]
|
||||
Some((lo, _frame)) => {
|
||||
return Err(LexError {
|
||||
span: Span { lo: *lo, hi: *lo },
|
||||
})
|
||||
}
|
||||
#[cfg(not(span_locations))]
|
||||
Some(_frame) => return Err(LexError { span: Span {} }),
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(open_delimiter) = match first {
|
||||
b'(' if !input.starts_with(ERROR) => Some(Delimiter::Parenthesis),
|
||||
b'[' => Some(Delimiter::Bracket),
|
||||
b'{' => Some(Delimiter::Brace),
|
||||
_ => None,
|
||||
} {
|
||||
input = input.advance(1);
|
||||
let frame = (open_delimiter, trees);
|
||||
#[cfg(span_locations)]
|
||||
let frame = (lo, frame);
|
||||
stack.push(frame);
|
||||
trees = TokenStreamBuilder::new();
|
||||
} else if let Some(close_delimiter) = match first {
|
||||
b')' => Some(Delimiter::Parenthesis),
|
||||
b']' => Some(Delimiter::Bracket),
|
||||
b'}' => Some(Delimiter::Brace),
|
||||
_ => None,
|
||||
} {
|
||||
let frame = match stack.pop() {
|
||||
Some(frame) => frame,
|
||||
None => return Err(lex_error(input)),
|
||||
};
|
||||
#[cfg(span_locations)]
|
||||
let (lo, frame) = frame;
|
||||
let (open_delimiter, outer) = frame;
|
||||
if open_delimiter != close_delimiter {
|
||||
return Err(lex_error(input));
|
||||
}
|
||||
input = input.advance(1);
|
||||
let mut g = Group::new(open_delimiter, trees.build());
|
||||
g.set_span(Span {
|
||||
#[cfg(span_locations)]
|
||||
lo,
|
||||
#[cfg(span_locations)]
|
||||
hi: input.off,
|
||||
});
|
||||
trees = outer;
|
||||
trees.push_token_from_parser(TokenTree::Group(crate::Group::_new_fallback(g)));
|
||||
} else {
|
||||
let (rest, mut tt) = match leaf_token(input) {
|
||||
Ok((rest, tt)) => (rest, tt),
|
||||
Err(Reject) => return Err(lex_error(input)),
|
||||
};
|
||||
tt.set_span(crate::Span::_new_fallback(Span {
|
||||
#[cfg(span_locations)]
|
||||
lo,
|
||||
#[cfg(span_locations)]
|
||||
hi: rest.off,
|
||||
}));
|
||||
trees.push_token_from_parser(tt);
|
||||
input = rest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn lex_error(cursor: Cursor) -> LexError {
|
||||
#[cfg(not(span_locations))]
|
||||
let _ = cursor;
|
||||
LexError {
|
||||
span: Span {
|
||||
#[cfg(span_locations)]
|
||||
lo: cursor.off,
|
||||
#[cfg(span_locations)]
|
||||
hi: cursor.off,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn leaf_token(input: Cursor) -> PResult<TokenTree> {
|
||||
if let Ok((input, l)) = literal(input) {
|
||||
// must be parsed before ident
|
||||
Ok((input, TokenTree::Literal(crate::Literal::_new_fallback(l))))
|
||||
} else if let Ok((input, p)) = punct(input) {
|
||||
Ok((input, TokenTree::Punct(p)))
|
||||
} else if let Ok((input, i)) = ident(input) {
|
||||
Ok((input, TokenTree::Ident(i)))
|
||||
} else if input.starts_with(ERROR) {
|
||||
let rest = input.advance(ERROR.len());
|
||||
let repr = crate::Literal::_new_fallback(Literal::_new(ERROR.to_owned()));
|
||||
Ok((rest, TokenTree::Literal(repr)))
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn ident(input: Cursor) -> PResult<crate::Ident> {
|
||||
if [
|
||||
"r\"", "r#\"", "r##", "b\"", "b\'", "br\"", "br#", "c\"", "cr\"", "cr#",
|
||||
]
|
||||
.iter()
|
||||
.any(|prefix| input.starts_with(prefix))
|
||||
{
|
||||
Err(Reject)
|
||||
} else {
|
||||
ident_any(input)
|
||||
}
|
||||
}
|
||||
|
||||
fn ident_any(input: Cursor) -> PResult<crate::Ident> {
|
||||
let raw = input.starts_with("r#");
|
||||
let rest = input.advance((raw as usize) << 1);
|
||||
|
||||
let (rest, sym) = ident_not_raw(rest)?;
|
||||
|
||||
if !raw {
|
||||
let ident = crate::Ident::_new(crate::imp::Ident::new_unchecked(
|
||||
sym,
|
||||
fallback::Span::call_site(),
|
||||
));
|
||||
return Ok((rest, ident));
|
||||
}
|
||||
|
||||
match sym {
|
||||
"_" | "super" | "self" | "Self" | "crate" => return Err(Reject),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let ident = crate::Ident::_new(crate::imp::Ident::new_raw_unchecked(
|
||||
sym,
|
||||
fallback::Span::call_site(),
|
||||
));
|
||||
Ok((rest, ident))
|
||||
}
|
||||
|
||||
fn ident_not_raw(input: Cursor) -> PResult<&str> {
|
||||
let mut chars = input.char_indices();
|
||||
|
||||
match chars.next() {
|
||||
Some((_, ch)) if is_ident_start(ch) => {}
|
||||
_ => return Err(Reject),
|
||||
}
|
||||
|
||||
let mut end = input.len();
|
||||
for (i, ch) in chars {
|
||||
if !is_ident_continue(ch) {
|
||||
end = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Ok((input.advance(end), &input.rest[..end]))
|
||||
}
|
||||
|
||||
pub(crate) fn literal(input: Cursor) -> PResult<Literal> {
|
||||
let rest = literal_nocapture(input)?;
|
||||
let end = input.len() - rest.len();
|
||||
Ok((rest, Literal::_new(input.rest[..end].to_string())))
|
||||
}
|
||||
|
||||
fn literal_nocapture(input: Cursor) -> Result<Cursor, Reject> {
|
||||
if let Ok(ok) = string(input) {
|
||||
Ok(ok)
|
||||
} else if let Ok(ok) = byte_string(input) {
|
||||
Ok(ok)
|
||||
} else if let Ok(ok) = c_string(input) {
|
||||
Ok(ok)
|
||||
} else if let Ok(ok) = byte(input) {
|
||||
Ok(ok)
|
||||
} else if let Ok(ok) = character(input) {
|
||||
Ok(ok)
|
||||
} else if let Ok(ok) = float(input) {
|
||||
Ok(ok)
|
||||
} else if let Ok(ok) = int(input) {
|
||||
Ok(ok)
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn literal_suffix(input: Cursor) -> Cursor {
|
||||
match ident_not_raw(input) {
|
||||
Ok((input, _)) => input,
|
||||
Err(Reject) => input,
|
||||
}
|
||||
}
|
||||
|
||||
fn string(input: Cursor) -> Result<Cursor, Reject> {
|
||||
if let Ok(input) = input.parse("\"") {
|
||||
cooked_string(input)
|
||||
} else if let Ok(input) = input.parse("r") {
|
||||
raw_string(input)
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn cooked_string(mut input: Cursor) -> Result<Cursor, Reject> {
|
||||
let mut chars = input.char_indices();
|
||||
|
||||
while let Some((i, ch)) = chars.next() {
|
||||
match ch {
|
||||
'"' => {
|
||||
let input = input.advance(i + 1);
|
||||
return Ok(literal_suffix(input));
|
||||
}
|
||||
'\r' => match chars.next() {
|
||||
Some((_, '\n')) => {}
|
||||
_ => break,
|
||||
},
|
||||
'\\' => match chars.next() {
|
||||
Some((_, 'x')) => {
|
||||
backslash_x_char(&mut chars)?;
|
||||
}
|
||||
Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"' | '0')) => {}
|
||||
Some((_, 'u')) => {
|
||||
backslash_u(&mut chars)?;
|
||||
}
|
||||
Some((newline, ch @ ('\n' | '\r'))) => {
|
||||
input = input.advance(newline + 1);
|
||||
trailing_backslash(&mut input, ch as u8)?;
|
||||
chars = input.char_indices();
|
||||
}
|
||||
_ => break,
|
||||
},
|
||||
_ch => {}
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let (input, delimiter) = delimiter_of_raw_string(input)?;
|
||||
let mut bytes = input.bytes().enumerate();
|
||||
while let Some((i, byte)) = bytes.next() {
|
||||
match byte {
|
||||
b'"' if input.rest[i + 1..].starts_with(delimiter) => {
|
||||
let rest = input.advance(i + 1 + delimiter.len());
|
||||
return Ok(literal_suffix(rest));
|
||||
}
|
||||
b'\r' => match bytes.next() {
|
||||
Some((_, b'\n')) => {}
|
||||
_ => break,
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn byte_string(input: Cursor) -> Result<Cursor, Reject> {
|
||||
if let Ok(input) = input.parse("b\"") {
|
||||
cooked_byte_string(input)
|
||||
} else if let Ok(input) = input.parse("br") {
|
||||
raw_byte_string(input)
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> {
|
||||
let mut bytes = input.bytes().enumerate();
|
||||
while let Some((offset, b)) = bytes.next() {
|
||||
match b {
|
||||
b'"' => {
|
||||
let input = input.advance(offset + 1);
|
||||
return Ok(literal_suffix(input));
|
||||
}
|
||||
b'\r' => match bytes.next() {
|
||||
Some((_, b'\n')) => {}
|
||||
_ => break,
|
||||
},
|
||||
b'\\' => match bytes.next() {
|
||||
Some((_, b'x')) => {
|
||||
backslash_x_byte(&mut bytes)?;
|
||||
}
|
||||
Some((_, b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"')) => {}
|
||||
Some((newline, b @ (b'\n' | b'\r'))) => {
|
||||
input = input.advance(newline + 1);
|
||||
trailing_backslash(&mut input, b)?;
|
||||
bytes = input.bytes().enumerate();
|
||||
}
|
||||
_ => break,
|
||||
},
|
||||
b if b.is_ascii() => {}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn delimiter_of_raw_string(input: Cursor) -> PResult<&str> {
|
||||
for (i, byte) in input.bytes().enumerate() {
|
||||
match byte {
|
||||
b'"' => {
|
||||
if i > 255 {
|
||||
// https://github.com/rust-lang/rust/pull/95251
|
||||
return Err(Reject);
|
||||
}
|
||||
return Ok((input.advance(i + 1), &input.rest[..i]));
|
||||
}
|
||||
b'#' => {}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn raw_byte_string(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let (input, delimiter) = delimiter_of_raw_string(input)?;
|
||||
let mut bytes = input.bytes().enumerate();
|
||||
while let Some((i, byte)) = bytes.next() {
|
||||
match byte {
|
||||
b'"' if input.rest[i + 1..].starts_with(delimiter) => {
|
||||
let rest = input.advance(i + 1 + delimiter.len());
|
||||
return Ok(literal_suffix(rest));
|
||||
}
|
||||
b'\r' => match bytes.next() {
|
||||
Some((_, b'\n')) => {}
|
||||
_ => break,
|
||||
},
|
||||
other => {
|
||||
if !other.is_ascii() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn c_string(input: Cursor) -> Result<Cursor, Reject> {
|
||||
if let Ok(input) = input.parse("c\"") {
|
||||
cooked_c_string(input)
|
||||
} else if let Ok(input) = input.parse("cr") {
|
||||
raw_c_string(input)
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn raw_c_string(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let (input, delimiter) = delimiter_of_raw_string(input)?;
|
||||
let mut bytes = input.bytes().enumerate();
|
||||
while let Some((i, byte)) = bytes.next() {
|
||||
match byte {
|
||||
b'"' if input.rest[i + 1..].starts_with(delimiter) => {
|
||||
let rest = input.advance(i + 1 + delimiter.len());
|
||||
return Ok(literal_suffix(rest));
|
||||
}
|
||||
b'\r' => match bytes.next() {
|
||||
Some((_, b'\n')) => {}
|
||||
_ => break,
|
||||
},
|
||||
b'\0' => break,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn cooked_c_string(mut input: Cursor) -> Result<Cursor, Reject> {
|
||||
let mut chars = input.char_indices();
|
||||
|
||||
while let Some((i, ch)) = chars.next() {
|
||||
match ch {
|
||||
'"' => {
|
||||
let input = input.advance(i + 1);
|
||||
return Ok(literal_suffix(input));
|
||||
}
|
||||
'\r' => match chars.next() {
|
||||
Some((_, '\n')) => {}
|
||||
_ => break,
|
||||
},
|
||||
'\\' => match chars.next() {
|
||||
Some((_, 'x')) => {
|
||||
backslash_x_nonzero(&mut chars)?;
|
||||
}
|
||||
Some((_, 'n' | 'r' | 't' | '\\' | '\'' | '"')) => {}
|
||||
Some((_, 'u')) => {
|
||||
if backslash_u(&mut chars)? == '\0' {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Some((newline, ch @ ('\n' | '\r'))) => {
|
||||
input = input.advance(newline + 1);
|
||||
trailing_backslash(&mut input, ch as u8)?;
|
||||
chars = input.char_indices();
|
||||
}
|
||||
_ => break,
|
||||
},
|
||||
'\0' => break,
|
||||
_ch => {}
|
||||
}
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn byte(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let input = input.parse("b'")?;
|
||||
let mut bytes = input.bytes().enumerate();
|
||||
let ok = match bytes.next().map(|(_, b)| b) {
|
||||
Some(b'\\') => match bytes.next().map(|(_, b)| b) {
|
||||
Some(b'x') => backslash_x_byte(&mut bytes).is_ok(),
|
||||
Some(b'n' | b'r' | b't' | b'\\' | b'0' | b'\'' | b'"') => true,
|
||||
_ => false,
|
||||
},
|
||||
b => b.is_some(),
|
||||
};
|
||||
if !ok {
|
||||
return Err(Reject);
|
||||
}
|
||||
let (offset, _) = bytes.next().ok_or(Reject)?;
|
||||
if !input.chars().as_str().is_char_boundary(offset) {
|
||||
return Err(Reject);
|
||||
}
|
||||
let input = input.advance(offset).parse("'")?;
|
||||
Ok(literal_suffix(input))
|
||||
}
|
||||
|
||||
fn character(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let input = input.parse("'")?;
|
||||
let mut chars = input.char_indices();
|
||||
let ok = match chars.next().map(|(_, ch)| ch) {
|
||||
Some('\\') => match chars.next().map(|(_, ch)| ch) {
|
||||
Some('x') => backslash_x_char(&mut chars).is_ok(),
|
||||
Some('u') => backslash_u(&mut chars).is_ok(),
|
||||
Some('n' | 'r' | 't' | '\\' | '0' | '\'' | '"') => true,
|
||||
_ => false,
|
||||
},
|
||||
ch => ch.is_some(),
|
||||
};
|
||||
if !ok {
|
||||
return Err(Reject);
|
||||
}
|
||||
let (idx, _) = chars.next().ok_or(Reject)?;
|
||||
let input = input.advance(idx).parse("'")?;
|
||||
Ok(literal_suffix(input))
|
||||
}
|
||||
|
||||
macro_rules! next_ch {
|
||||
($chars:ident @ $pat:pat) => {
|
||||
match $chars.next() {
|
||||
Some((_, ch)) => match ch {
|
||||
$pat => ch,
|
||||
_ => return Err(Reject),
|
||||
},
|
||||
None => return Err(Reject),
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn backslash_x_char<I>(chars: &mut I) -> Result<(), Reject>
|
||||
where
|
||||
I: Iterator<Item = (usize, char)>,
|
||||
{
|
||||
next_ch!(chars @ '0'..='7');
|
||||
next_ch!(chars @ '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn backslash_x_byte<I>(chars: &mut I) -> Result<(), Reject>
|
||||
where
|
||||
I: Iterator<Item = (usize, u8)>,
|
||||
{
|
||||
next_ch!(chars @ b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F');
|
||||
next_ch!(chars @ b'0'..=b'9' | b'a'..=b'f' | b'A'..=b'F');
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn backslash_x_nonzero<I>(chars: &mut I) -> Result<(), Reject>
|
||||
where
|
||||
I: Iterator<Item = (usize, char)>,
|
||||
{
|
||||
let first = next_ch!(chars @ '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
let second = next_ch!(chars @ '0'..='9' | 'a'..='f' | 'A'..='F');
|
||||
if first == '0' && second == '0' {
|
||||
Err(Reject)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn backslash_u<I>(chars: &mut I) -> Result<char, Reject>
|
||||
where
|
||||
I: Iterator<Item = (usize, char)>,
|
||||
{
|
||||
next_ch!(chars @ '{');
|
||||
let mut value = 0;
|
||||
let mut len = 0;
|
||||
for (_, ch) in chars {
|
||||
let digit = match ch {
|
||||
'0'..='9' => ch as u8 - b'0',
|
||||
'a'..='f' => 10 + ch as u8 - b'a',
|
||||
'A'..='F' => 10 + ch as u8 - b'A',
|
||||
'_' if len > 0 => continue,
|
||||
'}' if len > 0 => return char::from_u32(value).ok_or(Reject),
|
||||
_ => break,
|
||||
};
|
||||
if len == 6 {
|
||||
break;
|
||||
}
|
||||
value *= 0x10;
|
||||
value += u32::from(digit);
|
||||
len += 1;
|
||||
}
|
||||
Err(Reject)
|
||||
}
|
||||
|
||||
fn trailing_backslash(input: &mut Cursor, mut last: u8) -> Result<(), Reject> {
|
||||
let mut whitespace = input.bytes().enumerate();
|
||||
loop {
|
||||
if last == b'\r' && whitespace.next().map_or(true, |(_, b)| b != b'\n') {
|
||||
return Err(Reject);
|
||||
}
|
||||
match whitespace.next() {
|
||||
Some((_, b @ (b' ' | b'\t' | b'\n' | b'\r'))) => {
|
||||
last = b;
|
||||
}
|
||||
Some((offset, _)) => {
|
||||
*input = input.advance(offset);
|
||||
return Ok(());
|
||||
}
|
||||
None => return Err(Reject),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn float(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let mut rest = float_digits(input)?;
|
||||
if let Some(ch) = rest.chars().next() {
|
||||
if is_ident_start(ch) {
|
||||
rest = ident_not_raw(rest)?.0;
|
||||
}
|
||||
}
|
||||
word_break(rest)
|
||||
}
|
||||
|
||||
fn float_digits(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let mut chars = input.chars().peekable();
|
||||
match chars.next() {
|
||||
Some(ch) if '0' <= ch && ch <= '9' => {}
|
||||
_ => return Err(Reject),
|
||||
}
|
||||
|
||||
let mut len = 1;
|
||||
let mut has_dot = false;
|
||||
let mut has_exp = false;
|
||||
while let Some(&ch) = chars.peek() {
|
||||
match ch {
|
||||
'0'..='9' | '_' => {
|
||||
chars.next();
|
||||
len += 1;
|
||||
}
|
||||
'.' => {
|
||||
if has_dot {
|
||||
break;
|
||||
}
|
||||
chars.next();
|
||||
if chars
|
||||
.peek()
|
||||
.map_or(false, |&ch| ch == '.' || is_ident_start(ch))
|
||||
{
|
||||
return Err(Reject);
|
||||
}
|
||||
len += 1;
|
||||
has_dot = true;
|
||||
}
|
||||
'e' | 'E' => {
|
||||
chars.next();
|
||||
len += 1;
|
||||
has_exp = true;
|
||||
break;
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
|
||||
if !(has_dot || has_exp) {
|
||||
return Err(Reject);
|
||||
}
|
||||
|
||||
if has_exp {
|
||||
let token_before_exp = if has_dot {
|
||||
Ok(input.advance(len - 1))
|
||||
} else {
|
||||
Err(Reject)
|
||||
};
|
||||
let mut has_sign = false;
|
||||
let mut has_exp_value = false;
|
||||
while let Some(&ch) = chars.peek() {
|
||||
match ch {
|
||||
'+' | '-' => {
|
||||
if has_exp_value {
|
||||
break;
|
||||
}
|
||||
if has_sign {
|
||||
return token_before_exp;
|
||||
}
|
||||
chars.next();
|
||||
len += 1;
|
||||
has_sign = true;
|
||||
}
|
||||
'0'..='9' => {
|
||||
chars.next();
|
||||
len += 1;
|
||||
has_exp_value = true;
|
||||
}
|
||||
'_' => {
|
||||
chars.next();
|
||||
len += 1;
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
if !has_exp_value {
|
||||
return token_before_exp;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(input.advance(len))
|
||||
}
|
||||
|
||||
fn int(input: Cursor) -> Result<Cursor, Reject> {
|
||||
let mut rest = digits(input)?;
|
||||
if let Some(ch) = rest.chars().next() {
|
||||
if is_ident_start(ch) {
|
||||
rest = ident_not_raw(rest)?.0;
|
||||
}
|
||||
}
|
||||
word_break(rest)
|
||||
}
|
||||
|
||||
fn digits(mut input: Cursor) -> Result<Cursor, Reject> {
|
||||
let base = if input.starts_with("0x") {
|
||||
input = input.advance(2);
|
||||
16
|
||||
} else if input.starts_with("0o") {
|
||||
input = input.advance(2);
|
||||
8
|
||||
} else if input.starts_with("0b") {
|
||||
input = input.advance(2);
|
||||
2
|
||||
} else {
|
||||
10
|
||||
};
|
||||
|
||||
let mut len = 0;
|
||||
let mut empty = true;
|
||||
for b in input.bytes() {
|
||||
match b {
|
||||
b'0'..=b'9' => {
|
||||
let digit = (b - b'0') as u64;
|
||||
if digit >= base {
|
||||
return Err(Reject);
|
||||
}
|
||||
}
|
||||
b'a'..=b'f' => {
|
||||
let digit = 10 + (b - b'a') as u64;
|
||||
if digit >= base {
|
||||
break;
|
||||
}
|
||||
}
|
||||
b'A'..=b'F' => {
|
||||
let digit = 10 + (b - b'A') as u64;
|
||||
if digit >= base {
|
||||
break;
|
||||
}
|
||||
}
|
||||
b'_' => {
|
||||
if empty && base == 10 {
|
||||
return Err(Reject);
|
||||
}
|
||||
len += 1;
|
||||
continue;
|
||||
}
|
||||
_ => break,
|
||||
};
|
||||
len += 1;
|
||||
empty = false;
|
||||
}
|
||||
if empty {
|
||||
Err(Reject)
|
||||
} else {
|
||||
Ok(input.advance(len))
|
||||
}
|
||||
}
|
||||
|
||||
fn punct(input: Cursor) -> PResult<Punct> {
|
||||
let (rest, ch) = punct_char(input)?;
|
||||
if ch == '\'' {
|
||||
if ident_any(rest)?.0.starts_with_char('\'') {
|
||||
Err(Reject)
|
||||
} else {
|
||||
Ok((rest, Punct::new('\'', Spacing::Joint)))
|
||||
}
|
||||
} else {
|
||||
let kind = match punct_char(rest) {
|
||||
Ok(_) => Spacing::Joint,
|
||||
Err(Reject) => Spacing::Alone,
|
||||
};
|
||||
Ok((rest, Punct::new(ch, kind)))
|
||||
}
|
||||
}
|
||||
|
||||
fn punct_char(input: Cursor) -> PResult<char> {
|
||||
if input.starts_with("//") || input.starts_with("/*") {
|
||||
// Do not accept `/` of a comment as a punct.
|
||||
return Err(Reject);
|
||||
}
|
||||
|
||||
let mut chars = input.chars();
|
||||
let first = match chars.next() {
|
||||
Some(ch) => ch,
|
||||
None => {
|
||||
return Err(Reject);
|
||||
}
|
||||
};
|
||||
let recognized = "~!@#$%^&*-=+|;:,<.>/?'";
|
||||
if recognized.contains(first) {
|
||||
Ok((input.advance(first.len_utf8()), first))
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn doc_comment<'a>(input: Cursor<'a>, trees: &mut TokenStreamBuilder) -> PResult<'a, ()> {
|
||||
#[cfg(span_locations)]
|
||||
let lo = input.off;
|
||||
let (rest, (comment, inner)) = doc_comment_contents(input)?;
|
||||
let fallback_span = Span {
|
||||
#[cfg(span_locations)]
|
||||
lo,
|
||||
#[cfg(span_locations)]
|
||||
hi: rest.off,
|
||||
};
|
||||
let span = crate::Span::_new_fallback(fallback_span);
|
||||
|
||||
let mut scan_for_bare_cr = comment;
|
||||
while let Some(cr) = scan_for_bare_cr.find('\r') {
|
||||
let rest = &scan_for_bare_cr[cr + 1..];
|
||||
if !rest.starts_with('\n') {
|
||||
return Err(Reject);
|
||||
}
|
||||
scan_for_bare_cr = rest;
|
||||
}
|
||||
|
||||
let mut pound = Punct::new('#', Spacing::Alone);
|
||||
pound.set_span(span);
|
||||
trees.push_token_from_parser(TokenTree::Punct(pound));
|
||||
|
||||
if inner {
|
||||
let mut bang = Punct::new('!', Spacing::Alone);
|
||||
bang.set_span(span);
|
||||
trees.push_token_from_parser(TokenTree::Punct(bang));
|
||||
}
|
||||
|
||||
let doc_ident = crate::Ident::_new(crate::imp::Ident::new_unchecked("doc", fallback_span));
|
||||
let mut equal = Punct::new('=', Spacing::Alone);
|
||||
equal.set_span(span);
|
||||
let mut literal = crate::Literal::string(comment);
|
||||
literal.set_span(span);
|
||||
let mut bracketed = TokenStreamBuilder::with_capacity(3);
|
||||
bracketed.push_token_from_parser(TokenTree::Ident(doc_ident));
|
||||
bracketed.push_token_from_parser(TokenTree::Punct(equal));
|
||||
bracketed.push_token_from_parser(TokenTree::Literal(literal));
|
||||
let group = Group::new(Delimiter::Bracket, bracketed.build());
|
||||
let mut group = crate::Group::_new_fallback(group);
|
||||
group.set_span(span);
|
||||
trees.push_token_from_parser(TokenTree::Group(group));
|
||||
|
||||
Ok((rest, ()))
|
||||
}
|
||||
|
||||
fn doc_comment_contents(input: Cursor) -> PResult<(&str, bool)> {
|
||||
if input.starts_with("//!") {
|
||||
let input = input.advance(3);
|
||||
let (input, s) = take_until_newline_or_eof(input);
|
||||
Ok((input, (s, true)))
|
||||
} else if input.starts_with("/*!") {
|
||||
let (input, s) = block_comment(input)?;
|
||||
Ok((input, (&s[3..s.len() - 2], true)))
|
||||
} else if input.starts_with("///") {
|
||||
let input = input.advance(3);
|
||||
if input.starts_with_char('/') {
|
||||
return Err(Reject);
|
||||
}
|
||||
let (input, s) = take_until_newline_or_eof(input);
|
||||
Ok((input, (s, false)))
|
||||
} else if input.starts_with("/**") && !input.rest[3..].starts_with('*') {
|
||||
let (input, s) = block_comment(input)?;
|
||||
Ok((input, (&s[3..s.len() - 2], false)))
|
||||
} else {
|
||||
Err(Reject)
|
||||
}
|
||||
}
|
||||
|
||||
fn take_until_newline_or_eof(input: Cursor) -> (Cursor, &str) {
|
||||
let chars = input.char_indices();
|
||||
|
||||
for (i, ch) in chars {
|
||||
if ch == '\n' {
|
||||
return (input.advance(i), &input.rest[..i]);
|
||||
} else if ch == '\r' && input.rest[i + 1..].starts_with('\n') {
|
||||
return (input.advance(i + 1), &input.rest[..i]);
|
||||
}
|
||||
}
|
||||
|
||||
(input.advance(input.len()), input.rest)
|
||||
}
|
||||
145
vendor/proc-macro2/src/rcvec.rs
vendored
Normal file
145
vendor/proc-macro2/src/rcvec.rs
vendored
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
use alloc::rc::Rc;
|
||||
use alloc::vec;
|
||||
use core::mem;
|
||||
use core::panic::RefUnwindSafe;
|
||||
use core::slice;
|
||||
|
||||
pub(crate) struct RcVec<T> {
|
||||
inner: Rc<Vec<T>>,
|
||||
}
|
||||
|
||||
pub(crate) struct RcVecBuilder<T> {
|
||||
inner: Vec<T>,
|
||||
}
|
||||
|
||||
pub(crate) struct RcVecMut<'a, T> {
|
||||
inner: &'a mut Vec<T>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct RcVecIntoIter<T> {
|
||||
inner: vec::IntoIter<T>,
|
||||
}
|
||||
|
||||
impl<T> RcVec<T> {
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.inner.is_empty()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.inner.len()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> slice::Iter<T> {
|
||||
self.inner.iter()
|
||||
}
|
||||
|
||||
pub fn make_mut(&mut self) -> RcVecMut<T>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
RcVecMut {
|
||||
inner: Rc::make_mut(&mut self.inner),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> Option<RcVecMut<T>> {
|
||||
let inner = Rc::get_mut(&mut self.inner)?;
|
||||
Some(RcVecMut { inner })
|
||||
}
|
||||
|
||||
pub fn make_owned(mut self) -> RcVecBuilder<T>
|
||||
where
|
||||
T: Clone,
|
||||
{
|
||||
let vec = if let Some(owned) = Rc::get_mut(&mut self.inner) {
|
||||
mem::take(owned)
|
||||
} else {
|
||||
Vec::clone(&self.inner)
|
||||
};
|
||||
RcVecBuilder { inner: vec }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> RcVecBuilder<T> {
|
||||
pub fn new() -> Self {
|
||||
RcVecBuilder { inner: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn with_capacity(cap: usize) -> Self {
|
||||
RcVecBuilder {
|
||||
inner: Vec::with_capacity(cap),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, element: T) {
|
||||
self.inner.push(element);
|
||||
}
|
||||
|
||||
pub fn extend(&mut self, iter: impl IntoIterator<Item = T>) {
|
||||
self.inner.extend(iter);
|
||||
}
|
||||
|
||||
pub fn as_mut(&mut self) -> RcVecMut<T> {
|
||||
RcVecMut {
|
||||
inner: &mut self.inner,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(self) -> RcVec<T> {
|
||||
RcVec {
|
||||
inner: Rc::new(self.inner),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T> RcVecMut<'a, T> {
|
||||
pub fn push(&mut self, element: T) {
|
||||
self.inner.push(element);
|
||||
}
|
||||
|
||||
pub fn extend(&mut self, iter: impl IntoIterator<Item = T>) {
|
||||
self.inner.extend(iter);
|
||||
}
|
||||
|
||||
pub fn pop(&mut self) -> Option<T> {
|
||||
self.inner.pop()
|
||||
}
|
||||
|
||||
pub fn as_mut(&mut self) -> RcVecMut<T> {
|
||||
RcVecMut { inner: self.inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Clone for RcVec<T> {
|
||||
fn clone(&self) -> Self {
|
||||
RcVec {
|
||||
inner: Rc::clone(&self.inner),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> IntoIterator for RcVecBuilder<T> {
|
||||
type Item = T;
|
||||
type IntoIter = RcVecIntoIter<T>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
RcVecIntoIter {
|
||||
inner: self.inner.into_iter(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Iterator for RcVecIntoIter<T> {
|
||||
type Item = T;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.inner.next()
|
||||
}
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
self.inner.size_hint()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> RefUnwindSafe for RcVec<T> where T: RefUnwindSafe {}
|
||||
1008
vendor/proc-macro2/src/wrapper.rs
vendored
Normal file
1008
vendor/proc-macro2/src/wrapper.rs
vendored
Normal file
File diff suppressed because it is too large
Load diff
105
vendor/proc-macro2/tests/comments.rs
vendored
Normal file
105
vendor/proc-macro2/tests/comments.rs
vendored
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#![allow(clippy::assertions_on_result_states)]
|
||||
|
||||
use proc_macro2::{Delimiter, Literal, Spacing, TokenStream, TokenTree};
|
||||
|
||||
// #[doc = "..."] -> "..."
|
||||
fn lit_of_outer_doc_comment(tokens: &TokenStream) -> Literal {
|
||||
lit_of_doc_comment(tokens, false)
|
||||
}
|
||||
|
||||
// #![doc = "..."] -> "..."
|
||||
fn lit_of_inner_doc_comment(tokens: &TokenStream) -> Literal {
|
||||
lit_of_doc_comment(tokens, true)
|
||||
}
|
||||
|
||||
fn lit_of_doc_comment(tokens: &TokenStream, inner: bool) -> Literal {
|
||||
let mut iter = tokens.clone().into_iter();
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Punct(punct) => {
|
||||
assert_eq!(punct.as_char(), '#');
|
||||
assert_eq!(punct.spacing(), Spacing::Alone);
|
||||
}
|
||||
_ => panic!("wrong token {:?}", tokens),
|
||||
}
|
||||
if inner {
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Punct(punct) => {
|
||||
assert_eq!(punct.as_char(), '!');
|
||||
assert_eq!(punct.spacing(), Spacing::Alone);
|
||||
}
|
||||
_ => panic!("wrong token {:?}", tokens),
|
||||
}
|
||||
}
|
||||
iter = match iter.next().unwrap() {
|
||||
TokenTree::Group(group) => {
|
||||
assert_eq!(group.delimiter(), Delimiter::Bracket);
|
||||
assert!(iter.next().is_none(), "unexpected token {:?}", tokens);
|
||||
group.stream().into_iter()
|
||||
}
|
||||
_ => panic!("wrong token {:?}", tokens),
|
||||
};
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Ident(ident) => assert_eq!(ident.to_string(), "doc"),
|
||||
_ => panic!("wrong token {:?}", tokens),
|
||||
}
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Punct(punct) => {
|
||||
assert_eq!(punct.as_char(), '=');
|
||||
assert_eq!(punct.spacing(), Spacing::Alone);
|
||||
}
|
||||
_ => panic!("wrong token {:?}", tokens),
|
||||
}
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Literal(literal) => {
|
||||
assert!(iter.next().is_none(), "unexpected token {:?}", tokens);
|
||||
literal
|
||||
}
|
||||
_ => panic!("wrong token {:?}", tokens),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closed_immediately() {
|
||||
let stream = "/**/".parse::<TokenStream>().unwrap();
|
||||
let tokens = stream.into_iter().collect::<Vec<_>>();
|
||||
assert!(tokens.is_empty(), "not empty -- {:?}", tokens);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn incomplete() {
|
||||
assert!("/*/".parse::<TokenStream>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lit() {
|
||||
let stream = "/// doc".parse::<TokenStream>().unwrap();
|
||||
let lit = lit_of_outer_doc_comment(&stream);
|
||||
assert_eq!(lit.to_string(), "\" doc\"");
|
||||
|
||||
let stream = "//! doc".parse::<TokenStream>().unwrap();
|
||||
let lit = lit_of_inner_doc_comment(&stream);
|
||||
assert_eq!(lit.to_string(), "\" doc\"");
|
||||
|
||||
let stream = "/** doc */".parse::<TokenStream>().unwrap();
|
||||
let lit = lit_of_outer_doc_comment(&stream);
|
||||
assert_eq!(lit.to_string(), "\" doc \"");
|
||||
|
||||
let stream = "/*! doc */".parse::<TokenStream>().unwrap();
|
||||
let lit = lit_of_inner_doc_comment(&stream);
|
||||
assert_eq!(lit.to_string(), "\" doc \"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn carriage_return() {
|
||||
let stream = "///\r\n".parse::<TokenStream>().unwrap();
|
||||
let lit = lit_of_outer_doc_comment(&stream);
|
||||
assert_eq!(lit.to_string(), "\"\"");
|
||||
|
||||
let stream = "/**\r\n*/".parse::<TokenStream>().unwrap();
|
||||
let lit = lit_of_outer_doc_comment(&stream);
|
||||
assert_eq!(lit.to_string(), "\"\\r\\n\"");
|
||||
|
||||
"///\r".parse::<TokenStream>().unwrap_err();
|
||||
"///\r \n".parse::<TokenStream>().unwrap_err();
|
||||
"/**\r \n*/".parse::<TokenStream>().unwrap_err();
|
||||
}
|
||||
8
vendor/proc-macro2/tests/features.rs
vendored
Normal file
8
vendor/proc-macro2/tests/features.rs
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#[test]
|
||||
#[ignore]
|
||||
fn make_sure_no_proc_macro() {
|
||||
assert!(
|
||||
!cfg!(feature = "proc-macro"),
|
||||
"still compiled with proc_macro?"
|
||||
);
|
||||
}
|
||||
100
vendor/proc-macro2/tests/marker.rs
vendored
Normal file
100
vendor/proc-macro2/tests/marker.rs
vendored
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
#![allow(clippy::extra_unused_type_parameters)]
|
||||
|
||||
use proc_macro2::{
|
||||
Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
|
||||
};
|
||||
|
||||
macro_rules! assert_impl {
|
||||
($ty:ident is $($marker:ident) and +) => {
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $ty() {
|
||||
fn assert_implemented<T: $($marker +)+>() {}
|
||||
assert_implemented::<$ty>();
|
||||
}
|
||||
};
|
||||
|
||||
($ty:ident is not $($marker:ident) or +) => {
|
||||
#[test]
|
||||
#[allow(non_snake_case)]
|
||||
fn $ty() {
|
||||
$(
|
||||
{
|
||||
// Implemented for types that implement $marker.
|
||||
#[allow(dead_code)]
|
||||
trait IsNotImplemented {
|
||||
fn assert_not_implemented() {}
|
||||
}
|
||||
impl<T: $marker> IsNotImplemented for T {}
|
||||
|
||||
// Implemented for the type being tested.
|
||||
trait IsImplemented {
|
||||
fn assert_not_implemented() {}
|
||||
}
|
||||
impl IsImplemented for $ty {}
|
||||
|
||||
// If $ty does not implement $marker, there is no ambiguity
|
||||
// in the following trait method call.
|
||||
<$ty>::assert_not_implemented();
|
||||
}
|
||||
)+
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
assert_impl!(Delimiter is Send and Sync);
|
||||
assert_impl!(Spacing is Send and Sync);
|
||||
|
||||
assert_impl!(Group is not Send or Sync);
|
||||
assert_impl!(Ident is not Send or Sync);
|
||||
assert_impl!(LexError is not Send or Sync);
|
||||
assert_impl!(Literal is not Send or Sync);
|
||||
assert_impl!(Punct is not Send or Sync);
|
||||
assert_impl!(Span is not Send or Sync);
|
||||
assert_impl!(TokenStream is not Send or Sync);
|
||||
assert_impl!(TokenTree is not Send or Sync);
|
||||
|
||||
#[cfg(procmacro2_semver_exempt)]
|
||||
mod semver_exempt {
|
||||
use proc_macro2::{LineColumn, SourceFile};
|
||||
|
||||
assert_impl!(LineColumn is Send and Sync);
|
||||
|
||||
assert_impl!(SourceFile is not Send or Sync);
|
||||
}
|
||||
|
||||
mod unwind_safe {
|
||||
use proc_macro2::{
|
||||
Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
|
||||
};
|
||||
#[cfg(procmacro2_semver_exempt)]
|
||||
use proc_macro2::{LineColumn, SourceFile};
|
||||
use std::panic::{RefUnwindSafe, UnwindSafe};
|
||||
|
||||
macro_rules! assert_unwind_safe {
|
||||
($($types:ident)*) => {
|
||||
$(
|
||||
assert_impl!($types is UnwindSafe and RefUnwindSafe);
|
||||
)*
|
||||
};
|
||||
}
|
||||
|
||||
assert_unwind_safe! {
|
||||
Delimiter
|
||||
Group
|
||||
Ident
|
||||
LexError
|
||||
Literal
|
||||
Punct
|
||||
Spacing
|
||||
Span
|
||||
TokenStream
|
||||
TokenTree
|
||||
}
|
||||
|
||||
#[cfg(procmacro2_semver_exempt)]
|
||||
assert_unwind_safe! {
|
||||
LineColumn
|
||||
SourceFile
|
||||
}
|
||||
}
|
||||
905
vendor/proc-macro2/tests/test.rs
vendored
Normal file
905
vendor/proc-macro2/tests/test.rs
vendored
Normal file
|
|
@ -0,0 +1,905 @@
|
|||
#![allow(
|
||||
clippy::assertions_on_result_states,
|
||||
clippy::items_after_statements,
|
||||
clippy::needless_pass_by_value,
|
||||
clippy::needless_raw_string_hashes,
|
||||
clippy::non_ascii_literal,
|
||||
clippy::octal_escapes
|
||||
)]
|
||||
|
||||
use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
|
||||
use std::ffi::CStr;
|
||||
use std::iter;
|
||||
use std::str::{self, FromStr};
|
||||
|
||||
#[test]
|
||||
fn idents() {
|
||||
assert_eq!(
|
||||
Ident::new("String", Span::call_site()).to_string(),
|
||||
"String"
|
||||
);
|
||||
assert_eq!(Ident::new("fn", Span::call_site()).to_string(), "fn");
|
||||
assert_eq!(Ident::new("_", Span::call_site()).to_string(), "_");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_idents() {
|
||||
assert_eq!(
|
||||
Ident::new_raw("String", Span::call_site()).to_string(),
|
||||
"r#String"
|
||||
);
|
||||
assert_eq!(Ident::new_raw("fn", Span::call_site()).to_string(), "r#fn");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "`r#_` cannot be a raw identifier")]
|
||||
fn ident_raw_underscore() {
|
||||
Ident::new_raw("_", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "`r#super` cannot be a raw identifier")]
|
||||
fn ident_raw_reserved() {
|
||||
Ident::new_raw("super", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Ident is not allowed to be empty; use Option<Ident>")]
|
||||
fn ident_empty() {
|
||||
Ident::new("", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Ident cannot be a number; use Literal instead")]
|
||||
fn ident_number() {
|
||||
Ident::new("255", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "\"a#\" is not a valid Ident")]
|
||||
fn ident_invalid() {
|
||||
Ident::new("a#", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "not a valid Ident")]
|
||||
fn raw_ident_empty() {
|
||||
Ident::new("r#", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "not a valid Ident")]
|
||||
fn raw_ident_number() {
|
||||
Ident::new("r#255", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "\"r#a#\" is not a valid Ident")]
|
||||
fn raw_ident_invalid() {
|
||||
Ident::new("r#a#", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "not a valid Ident")]
|
||||
fn lifetime_empty() {
|
||||
Ident::new("'", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "not a valid Ident")]
|
||||
fn lifetime_number() {
|
||||
Ident::new("'255", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = r#""'a#" is not a valid Ident"#)]
|
||||
fn lifetime_invalid() {
|
||||
Ident::new("'a#", Span::call_site());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_string() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected.trim());
|
||||
}
|
||||
|
||||
assert(Literal::string(""), r#" "" "#);
|
||||
assert(Literal::string("aA"), r#" "aA" "#);
|
||||
assert(Literal::string("\t"), r#" "\t" "#);
|
||||
assert(Literal::string("❤"), r#" "❤" "#);
|
||||
assert(Literal::string("'"), r#" "'" "#);
|
||||
assert(Literal::string("\""), r#" "\"" "#);
|
||||
assert(Literal::string("\0"), r#" "\0" "#);
|
||||
assert(Literal::string("\u{1}"), r#" "\u{1}" "#);
|
||||
assert(
|
||||
Literal::string("a\00b\07c\08d\0e\0"),
|
||||
r#" "a\x000b\x007c\08d\0e\0" "#,
|
||||
);
|
||||
|
||||
"\"\\\r\n x\"".parse::<TokenStream>().unwrap();
|
||||
"\"\\\r\n \rx\"".parse::<TokenStream>().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_raw_string() {
|
||||
"r\"\r\n\"".parse::<TokenStream>().unwrap();
|
||||
|
||||
fn raw_string_literal_with_hashes(n: usize) -> String {
|
||||
let mut literal = String::new();
|
||||
literal.push('r');
|
||||
literal.extend(iter::repeat('#').take(n));
|
||||
literal.push('"');
|
||||
literal.push('"');
|
||||
literal.extend(iter::repeat('#').take(n));
|
||||
literal
|
||||
}
|
||||
|
||||
raw_string_literal_with_hashes(255)
|
||||
.parse::<TokenStream>()
|
||||
.unwrap();
|
||||
|
||||
// https://github.com/rust-lang/rust/pull/95251
|
||||
raw_string_literal_with_hashes(256)
|
||||
.parse::<TokenStream>()
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_byte_character() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected.trim());
|
||||
}
|
||||
|
||||
assert(Literal::byte_character(b'a'), r#" b'a' "#);
|
||||
assert(Literal::byte_character(b'\0'), r#" b'\0' "#);
|
||||
assert(Literal::byte_character(b'\t'), r#" b'\t' "#);
|
||||
assert(Literal::byte_character(b'\n'), r#" b'\n' "#);
|
||||
assert(Literal::byte_character(b'\r'), r#" b'\r' "#);
|
||||
assert(Literal::byte_character(b'\''), r#" b'\'' "#);
|
||||
assert(Literal::byte_character(b'\\'), r#" b'\\' "#);
|
||||
assert(Literal::byte_character(b'\x1f'), r#" b'\x1F' "#);
|
||||
assert(Literal::byte_character(b'"'), r#" b'"' "#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_byte_string() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected.trim());
|
||||
}
|
||||
|
||||
assert(Literal::byte_string(b""), r#" b"" "#);
|
||||
assert(Literal::byte_string(b"\0"), r#" b"\0" "#);
|
||||
assert(Literal::byte_string(b"\t"), r#" b"\t" "#);
|
||||
assert(Literal::byte_string(b"\n"), r#" b"\n" "#);
|
||||
assert(Literal::byte_string(b"\r"), r#" b"\r" "#);
|
||||
assert(Literal::byte_string(b"\""), r#" b"\"" "#);
|
||||
assert(Literal::byte_string(b"\\"), r#" b"\\" "#);
|
||||
assert(Literal::byte_string(b"\x1f"), r#" b"\x1F" "#);
|
||||
assert(Literal::byte_string(b"'"), r#" b"'" "#);
|
||||
assert(
|
||||
Literal::byte_string(b"a\00b\07c\08d\0e\0"),
|
||||
r#" b"a\x000b\x007c\08d\0e\0" "#,
|
||||
);
|
||||
|
||||
"b\"\\\r\n x\"".parse::<TokenStream>().unwrap();
|
||||
"b\"\\\r\n \rx\"".parse::<TokenStream>().unwrap_err();
|
||||
"b\"\\\r\n \u{a0}x\"".parse::<TokenStream>().unwrap_err();
|
||||
"br\"\u{a0}\"".parse::<TokenStream>().unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_c_string() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected.trim());
|
||||
}
|
||||
|
||||
assert(Literal::c_string(<&CStr>::default()), r#" c"" "#);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"aA\0").unwrap()),
|
||||
r#" c"aA" "#,
|
||||
);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"aA\0").unwrap()),
|
||||
r#" c"aA" "#,
|
||||
);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"\t\0").unwrap()),
|
||||
r#" c"\t" "#,
|
||||
);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"\xE2\x9D\xA4\0").unwrap()),
|
||||
r#" c"❤" "#,
|
||||
);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"'\0").unwrap()),
|
||||
r#" c"'" "#,
|
||||
);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"\"\0").unwrap()),
|
||||
r#" c"\"" "#,
|
||||
);
|
||||
assert(
|
||||
Literal::c_string(CStr::from_bytes_with_nul(b"\x7F\xFF\xFE\xCC\xB3\0").unwrap()),
|
||||
r#" c"\u{7f}\xFF\xFE\u{333}" "#,
|
||||
);
|
||||
|
||||
let strings = r###"
|
||||
c"hello\x80我叫\u{1F980}" // from the RFC
|
||||
cr"\"
|
||||
cr##"Hello "world"!"##
|
||||
c"\t\n\r\"\\"
|
||||
"###;
|
||||
|
||||
let mut tokens = strings.parse::<TokenStream>().unwrap().into_iter();
|
||||
|
||||
for expected in &[
|
||||
r#"c"hello\x80我叫\u{1F980}""#,
|
||||
r#"cr"\""#,
|
||||
r###"cr##"Hello "world"!"##"###,
|
||||
r#"c"\t\n\r\"\\""#,
|
||||
] {
|
||||
match tokens.next().unwrap() {
|
||||
TokenTree::Literal(literal) => {
|
||||
assert_eq!(literal.to_string(), *expected);
|
||||
}
|
||||
unexpected => panic!("unexpected token: {:?}", unexpected),
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(unexpected) = tokens.next() {
|
||||
panic!("unexpected token: {:?}", unexpected);
|
||||
}
|
||||
|
||||
for invalid in &[r#"c"\0""#, r#"c"\x00""#, r#"c"\u{0}""#, "c\"\0\""] {
|
||||
if let Ok(unexpected) = invalid.parse::<TokenStream>() {
|
||||
panic!("unexpected token: {:?}", unexpected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_character() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected.trim());
|
||||
}
|
||||
|
||||
assert(Literal::character('a'), r#" 'a' "#);
|
||||
assert(Literal::character('\t'), r#" '\t' "#);
|
||||
assert(Literal::character('❤'), r#" '❤' "#);
|
||||
assert(Literal::character('\''), r#" '\'' "#);
|
||||
assert(Literal::character('"'), r#" '"' "#);
|
||||
assert(Literal::character('\0'), r#" '\0' "#);
|
||||
assert(Literal::character('\u{1}'), r#" '\u{1}' "#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_integer() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected);
|
||||
}
|
||||
|
||||
assert(Literal::u8_suffixed(10), "10u8");
|
||||
assert(Literal::u16_suffixed(10), "10u16");
|
||||
assert(Literal::u32_suffixed(10), "10u32");
|
||||
assert(Literal::u64_suffixed(10), "10u64");
|
||||
assert(Literal::u128_suffixed(10), "10u128");
|
||||
assert(Literal::usize_suffixed(10), "10usize");
|
||||
|
||||
assert(Literal::i8_suffixed(10), "10i8");
|
||||
assert(Literal::i16_suffixed(10), "10i16");
|
||||
assert(Literal::i32_suffixed(10), "10i32");
|
||||
assert(Literal::i64_suffixed(10), "10i64");
|
||||
assert(Literal::i128_suffixed(10), "10i128");
|
||||
assert(Literal::isize_suffixed(10), "10isize");
|
||||
|
||||
assert(Literal::u8_unsuffixed(10), "10");
|
||||
assert(Literal::u16_unsuffixed(10), "10");
|
||||
assert(Literal::u32_unsuffixed(10), "10");
|
||||
assert(Literal::u64_unsuffixed(10), "10");
|
||||
assert(Literal::u128_unsuffixed(10), "10");
|
||||
assert(Literal::usize_unsuffixed(10), "10");
|
||||
|
||||
assert(Literal::i8_unsuffixed(10), "10");
|
||||
assert(Literal::i16_unsuffixed(10), "10");
|
||||
assert(Literal::i32_unsuffixed(10), "10");
|
||||
assert(Literal::i64_unsuffixed(10), "10");
|
||||
assert(Literal::i128_unsuffixed(10), "10");
|
||||
assert(Literal::isize_unsuffixed(10), "10");
|
||||
|
||||
assert(Literal::i32_suffixed(-10), "-10i32");
|
||||
assert(Literal::i32_unsuffixed(-10), "-10");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_float() {
|
||||
#[track_caller]
|
||||
fn assert(literal: Literal, expected: &str) {
|
||||
assert_eq!(literal.to_string(), expected);
|
||||
}
|
||||
|
||||
assert(Literal::f32_suffixed(10.0), "10f32");
|
||||
assert(Literal::f32_suffixed(-10.0), "-10f32");
|
||||
assert(Literal::f64_suffixed(10.0), "10f64");
|
||||
assert(Literal::f64_suffixed(-10.0), "-10f64");
|
||||
|
||||
assert(Literal::f32_unsuffixed(10.0), "10.0");
|
||||
assert(Literal::f32_unsuffixed(-10.0), "-10.0");
|
||||
assert(Literal::f64_unsuffixed(10.0), "10.0");
|
||||
assert(Literal::f64_unsuffixed(-10.0), "-10.0");
|
||||
|
||||
assert(
|
||||
Literal::f64_unsuffixed(1e100),
|
||||
"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_suffix() {
|
||||
fn token_count(p: &str) -> usize {
|
||||
p.parse::<TokenStream>().unwrap().into_iter().count()
|
||||
}
|
||||
|
||||
assert_eq!(token_count("999u256"), 1);
|
||||
assert_eq!(token_count("999r#u256"), 3);
|
||||
assert_eq!(token_count("1."), 1);
|
||||
assert_eq!(token_count("1.f32"), 3);
|
||||
assert_eq!(token_count("1.0_0"), 1);
|
||||
assert_eq!(token_count("1._0"), 3);
|
||||
assert_eq!(token_count("1._m"), 3);
|
||||
assert_eq!(token_count("\"\"s"), 1);
|
||||
assert_eq!(token_count("r\"\"r"), 1);
|
||||
assert_eq!(token_count("r#\"\"#r"), 1);
|
||||
assert_eq!(token_count("b\"\"b"), 1);
|
||||
assert_eq!(token_count("br\"\"br"), 1);
|
||||
assert_eq!(token_count("br#\"\"#br"), 1);
|
||||
assert_eq!(token_count("c\"\"c"), 1);
|
||||
assert_eq!(token_count("cr\"\"cr"), 1);
|
||||
assert_eq!(token_count("cr#\"\"#cr"), 1);
|
||||
assert_eq!(token_count("'c'c"), 1);
|
||||
assert_eq!(token_count("b'b'b"), 1);
|
||||
assert_eq!(token_count("0E"), 1);
|
||||
assert_eq!(token_count("0o0A"), 1);
|
||||
assert_eq!(token_count("0E--0"), 4);
|
||||
assert_eq!(token_count("0.0ECMA"), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_iter_negative() {
|
||||
let negative_literal = Literal::i32_suffixed(-3);
|
||||
let tokens = TokenStream::from(TokenTree::Literal(negative_literal));
|
||||
let mut iter = tokens.into_iter();
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Punct(punct) => {
|
||||
assert_eq!(punct.as_char(), '-');
|
||||
assert_eq!(punct.spacing(), Spacing::Alone);
|
||||
}
|
||||
unexpected => panic!("unexpected token {:?}", unexpected),
|
||||
}
|
||||
match iter.next().unwrap() {
|
||||
TokenTree::Literal(literal) => {
|
||||
assert_eq!(literal.to_string(), "3i32");
|
||||
}
|
||||
unexpected => panic!("unexpected token {:?}", unexpected),
|
||||
}
|
||||
assert!(iter.next().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_parse() {
|
||||
assert!("1".parse::<Literal>().is_ok());
|
||||
assert!("-1".parse::<Literal>().is_ok());
|
||||
assert!("-1u12".parse::<Literal>().is_ok());
|
||||
assert!("1.0".parse::<Literal>().is_ok());
|
||||
assert!("-1.0".parse::<Literal>().is_ok());
|
||||
assert!("-1.0f12".parse::<Literal>().is_ok());
|
||||
assert!("'a'".parse::<Literal>().is_ok());
|
||||
assert!("\"\n\"".parse::<Literal>().is_ok());
|
||||
assert!("0 1".parse::<Literal>().is_err());
|
||||
assert!(" 0".parse::<Literal>().is_err());
|
||||
assert!("0 ".parse::<Literal>().is_err());
|
||||
assert!("/* comment */0".parse::<Literal>().is_err());
|
||||
assert!("0/* comment */".parse::<Literal>().is_err());
|
||||
assert!("0// comment".parse::<Literal>().is_err());
|
||||
assert!("- 1".parse::<Literal>().is_err());
|
||||
assert!("- 1.0".parse::<Literal>().is_err());
|
||||
assert!("-\"\"".parse::<Literal>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn literal_span() {
|
||||
let positive = "0.1".parse::<Literal>().unwrap();
|
||||
let negative = "-0.1".parse::<Literal>().unwrap();
|
||||
let subspan = positive.subspan(1..2);
|
||||
|
||||
#[cfg(not(span_locations))]
|
||||
{
|
||||
let _ = negative;
|
||||
assert!(subspan.is_none());
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
{
|
||||
assert_eq!(positive.span().start().column, 0);
|
||||
assert_eq!(positive.span().end().column, 3);
|
||||
assert_eq!(negative.span().start().column, 0);
|
||||
assert_eq!(negative.span().end().column, 4);
|
||||
assert_eq!(subspan.unwrap().source_text().unwrap(), ".");
|
||||
}
|
||||
|
||||
assert!(positive.subspan(1..4).is_none());
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
#[test]
|
||||
fn source_text() {
|
||||
let input = " 𓀕 a z ";
|
||||
let mut tokens = input
|
||||
.parse::<proc_macro2::TokenStream>()
|
||||
.unwrap()
|
||||
.into_iter();
|
||||
|
||||
let first = tokens.next().unwrap();
|
||||
assert_eq!("𓀕", first.span().source_text().unwrap());
|
||||
|
||||
let second = tokens.next().unwrap();
|
||||
let third = tokens.next().unwrap();
|
||||
assert_eq!("z", third.span().source_text().unwrap());
|
||||
assert_eq!("a", second.span().source_text().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrip() {
|
||||
fn roundtrip(p: &str) {
|
||||
println!("parse: {}", p);
|
||||
let s = p.parse::<TokenStream>().unwrap().to_string();
|
||||
println!("first: {}", s);
|
||||
let s2 = s.parse::<TokenStream>().unwrap().to_string();
|
||||
assert_eq!(s, s2);
|
||||
}
|
||||
roundtrip("a");
|
||||
roundtrip("<<");
|
||||
roundtrip("<<=");
|
||||
roundtrip(
|
||||
"
|
||||
1
|
||||
1.0
|
||||
1f32
|
||||
2f64
|
||||
1usize
|
||||
4isize
|
||||
4e10
|
||||
1_000
|
||||
1_0i32
|
||||
8u8
|
||||
9
|
||||
0
|
||||
0xffffffffffffffffffffffffffffffff
|
||||
1x
|
||||
1u80
|
||||
1f320
|
||||
",
|
||||
);
|
||||
roundtrip("'a");
|
||||
roundtrip("'_");
|
||||
roundtrip("'static");
|
||||
roundtrip(r"'\u{10__FFFF}'");
|
||||
roundtrip("\"\\u{10_F0FF__}foo\\u{1_0_0_0__}\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fail() {
|
||||
fn fail(p: &str) {
|
||||
if let Ok(s) = p.parse::<TokenStream>() {
|
||||
panic!("should have failed to parse: {}\n{:#?}", p, s);
|
||||
}
|
||||
}
|
||||
fail("' static");
|
||||
fail("r#1");
|
||||
fail("r#_");
|
||||
fail("\"\\u{0000000}\""); // overlong unicode escape (rust allows at most 6 hex digits)
|
||||
fail("\"\\u{999999}\""); // outside of valid range of char
|
||||
fail("\"\\u{_0}\""); // leading underscore
|
||||
fail("\"\\u{}\""); // empty
|
||||
fail("b\"\r\""); // bare carriage return in byte string
|
||||
fail("r\"\r\""); // bare carriage return in raw string
|
||||
fail("\"\\\r \""); // backslash carriage return
|
||||
fail("'aa'aa");
|
||||
fail("br##\"\"#");
|
||||
fail("cr##\"\"#");
|
||||
fail("\"\\\n\u{85}\r\"");
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
#[test]
|
||||
fn span_test() {
|
||||
check_spans(
|
||||
"\
|
||||
/// This is a document comment
|
||||
testing 123
|
||||
{
|
||||
testing 234
|
||||
}",
|
||||
&[
|
||||
(1, 0, 1, 30), // #
|
||||
(1, 0, 1, 30), // [ ... ]
|
||||
(1, 0, 1, 30), // doc
|
||||
(1, 0, 1, 30), // =
|
||||
(1, 0, 1, 30), // "This is..."
|
||||
(2, 0, 2, 7), // testing
|
||||
(2, 8, 2, 11), // 123
|
||||
(3, 0, 5, 1), // { ... }
|
||||
(4, 2, 4, 9), // testing
|
||||
(4, 10, 4, 13), // 234
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(procmacro2_semver_exempt)]
|
||||
#[test]
|
||||
fn default_span() {
|
||||
let start = Span::call_site().start();
|
||||
assert_eq!(start.line, 1);
|
||||
assert_eq!(start.column, 0);
|
||||
let end = Span::call_site().end();
|
||||
assert_eq!(end.line, 1);
|
||||
assert_eq!(end.column, 0);
|
||||
let source_file = Span::call_site().source_file();
|
||||
assert_eq!(source_file.path().to_string_lossy(), "<unspecified>");
|
||||
assert!(!source_file.is_real());
|
||||
}
|
||||
|
||||
#[cfg(procmacro2_semver_exempt)]
|
||||
#[test]
|
||||
fn span_join() {
|
||||
let source1 = "aaa\nbbb"
|
||||
.parse::<TokenStream>()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
let source2 = "ccc\nddd"
|
||||
.parse::<TokenStream>()
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
assert!(source1[0].span().source_file() != source2[0].span().source_file());
|
||||
assert_eq!(
|
||||
source1[0].span().source_file(),
|
||||
source1[1].span().source_file()
|
||||
);
|
||||
|
||||
let joined1 = source1[0].span().join(source1[1].span());
|
||||
let joined2 = source1[0].span().join(source2[0].span());
|
||||
assert!(joined1.is_some());
|
||||
assert!(joined2.is_none());
|
||||
|
||||
let start = joined1.unwrap().start();
|
||||
let end = joined1.unwrap().end();
|
||||
assert_eq!(start.line, 1);
|
||||
assert_eq!(start.column, 0);
|
||||
assert_eq!(end.line, 2);
|
||||
assert_eq!(end.column, 3);
|
||||
|
||||
assert_eq!(
|
||||
joined1.unwrap().source_file(),
|
||||
source1[0].span().source_file()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_panic() {
|
||||
let s = str::from_utf8(b"b\'\xc2\x86 \x00\x00\x00^\"").unwrap();
|
||||
assert!(s.parse::<TokenStream>().is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn punct_before_comment() {
|
||||
let mut tts = TokenStream::from_str("~// comment").unwrap().into_iter();
|
||||
match tts.next().unwrap() {
|
||||
TokenTree::Punct(tt) => {
|
||||
assert_eq!(tt.as_char(), '~');
|
||||
assert_eq!(tt.spacing(), Spacing::Alone);
|
||||
}
|
||||
wrong => panic!("wrong token {:?}", wrong),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn joint_last_token() {
|
||||
// This test verifies that we match the behavior of libproc_macro *not* in
|
||||
// the range nightly-2020-09-06 through nightly-2020-09-10, in which this
|
||||
// behavior was temporarily broken.
|
||||
// See https://github.com/rust-lang/rust/issues/76399
|
||||
|
||||
let joint_punct = Punct::new(':', Spacing::Joint);
|
||||
let stream = TokenStream::from(TokenTree::Punct(joint_punct));
|
||||
let punct = match stream.into_iter().next().unwrap() {
|
||||
TokenTree::Punct(punct) => punct,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
assert_eq!(punct.spacing(), Spacing::Joint);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raw_identifier() {
|
||||
let mut tts = TokenStream::from_str("r#dyn").unwrap().into_iter();
|
||||
match tts.next().unwrap() {
|
||||
TokenTree::Ident(raw) => assert_eq!("r#dyn", raw.to_string()),
|
||||
wrong => panic!("wrong token {:?}", wrong),
|
||||
}
|
||||
assert!(tts.next().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_ident() {
|
||||
let ident = Ident::new("proc_macro", Span::call_site());
|
||||
|
||||
#[cfg(not(span_locations))]
|
||||
let expected = "Ident(proc_macro)";
|
||||
|
||||
#[cfg(span_locations)]
|
||||
let expected = "Ident { sym: proc_macro }";
|
||||
|
||||
assert_eq!(expected, format!("{:?}", ident));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_debug_tokenstream() {
|
||||
let tts = TokenStream::from_str("[a + 1]").unwrap();
|
||||
|
||||
#[cfg(not(span_locations))]
|
||||
let expected = "\
|
||||
TokenStream [
|
||||
Group {
|
||||
delimiter: Bracket,
|
||||
stream: TokenStream [
|
||||
Ident {
|
||||
sym: a,
|
||||
},
|
||||
Punct {
|
||||
char: '+',
|
||||
spacing: Alone,
|
||||
},
|
||||
Literal {
|
||||
lit: 1,
|
||||
},
|
||||
],
|
||||
},
|
||||
]\
|
||||
";
|
||||
|
||||
#[cfg(not(span_locations))]
|
||||
let expected_before_trailing_commas = "\
|
||||
TokenStream [
|
||||
Group {
|
||||
delimiter: Bracket,
|
||||
stream: TokenStream [
|
||||
Ident {
|
||||
sym: a
|
||||
},
|
||||
Punct {
|
||||
char: '+',
|
||||
spacing: Alone
|
||||
},
|
||||
Literal {
|
||||
lit: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
]\
|
||||
";
|
||||
|
||||
#[cfg(span_locations)]
|
||||
let expected = "\
|
||||
TokenStream [
|
||||
Group {
|
||||
delimiter: Bracket,
|
||||
stream: TokenStream [
|
||||
Ident {
|
||||
sym: a,
|
||||
span: bytes(2..3),
|
||||
},
|
||||
Punct {
|
||||
char: '+',
|
||||
spacing: Alone,
|
||||
span: bytes(4..5),
|
||||
},
|
||||
Literal {
|
||||
lit: 1,
|
||||
span: bytes(6..7),
|
||||
},
|
||||
],
|
||||
span: bytes(1..8),
|
||||
},
|
||||
]\
|
||||
";
|
||||
|
||||
#[cfg(span_locations)]
|
||||
let expected_before_trailing_commas = "\
|
||||
TokenStream [
|
||||
Group {
|
||||
delimiter: Bracket,
|
||||
stream: TokenStream [
|
||||
Ident {
|
||||
sym: a,
|
||||
span: bytes(2..3)
|
||||
},
|
||||
Punct {
|
||||
char: '+',
|
||||
spacing: Alone,
|
||||
span: bytes(4..5)
|
||||
},
|
||||
Literal {
|
||||
lit: 1,
|
||||
span: bytes(6..7)
|
||||
}
|
||||
],
|
||||
span: bytes(1..8)
|
||||
}
|
||||
]\
|
||||
";
|
||||
|
||||
let actual = format!("{:#?}", tts);
|
||||
if actual.ends_with(",\n]") {
|
||||
assert_eq!(expected, actual);
|
||||
} else {
|
||||
assert_eq!(expected_before_trailing_commas, actual);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_tokenstream_is_empty() {
|
||||
let default_token_stream = <TokenStream as Default>::default();
|
||||
|
||||
assert!(default_token_stream.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tokenstream_size_hint() {
|
||||
let tokens = "a b (c d) e".parse::<TokenStream>().unwrap();
|
||||
|
||||
assert_eq!(tokens.into_iter().size_hint(), (4, Some(4)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tuple_indexing() {
|
||||
// This behavior may change depending on https://github.com/rust-lang/rust/pull/71322
|
||||
let mut tokens = "tuple.0.0".parse::<TokenStream>().unwrap().into_iter();
|
||||
assert_eq!("tuple", tokens.next().unwrap().to_string());
|
||||
assert_eq!(".", tokens.next().unwrap().to_string());
|
||||
assert_eq!("0.0", tokens.next().unwrap().to_string());
|
||||
assert!(tokens.next().is_none());
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
#[test]
|
||||
fn non_ascii_tokens() {
|
||||
check_spans("// abc", &[]);
|
||||
check_spans("// ábc", &[]);
|
||||
check_spans("// abc x", &[]);
|
||||
check_spans("// ábc x", &[]);
|
||||
check_spans("/* abc */ x", &[(1, 10, 1, 11)]);
|
||||
check_spans("/* ábc */ x", &[(1, 10, 1, 11)]);
|
||||
check_spans("/* ab\nc */ x", &[(2, 5, 2, 6)]);
|
||||
check_spans("/* áb\nc */ x", &[(2, 5, 2, 6)]);
|
||||
check_spans("/*** abc */ x", &[(1, 12, 1, 13)]);
|
||||
check_spans("/*** ábc */ x", &[(1, 12, 1, 13)]);
|
||||
check_spans(r#""abc""#, &[(1, 0, 1, 5)]);
|
||||
check_spans(r#""ábc""#, &[(1, 0, 1, 5)]);
|
||||
check_spans(r##"r#"abc"#"##, &[(1, 0, 1, 8)]);
|
||||
check_spans(r##"r#"ábc"#"##, &[(1, 0, 1, 8)]);
|
||||
check_spans("r#\"a\nc\"#", &[(1, 0, 2, 3)]);
|
||||
check_spans("r#\"á\nc\"#", &[(1, 0, 2, 3)]);
|
||||
check_spans("'a'", &[(1, 0, 1, 3)]);
|
||||
check_spans("'á'", &[(1, 0, 1, 3)]);
|
||||
check_spans("//! abc", &[(1, 0, 1, 7), (1, 0, 1, 7), (1, 0, 1, 7)]);
|
||||
check_spans("//! ábc", &[(1, 0, 1, 7), (1, 0, 1, 7), (1, 0, 1, 7)]);
|
||||
check_spans("//! abc\n", &[(1, 0, 1, 7), (1, 0, 1, 7), (1, 0, 1, 7)]);
|
||||
check_spans("//! ábc\n", &[(1, 0, 1, 7), (1, 0, 1, 7), (1, 0, 1, 7)]);
|
||||
check_spans("/*! abc */", &[(1, 0, 1, 10), (1, 0, 1, 10), (1, 0, 1, 10)]);
|
||||
check_spans("/*! ábc */", &[(1, 0, 1, 10), (1, 0, 1, 10), (1, 0, 1, 10)]);
|
||||
check_spans("/*! a\nc */", &[(1, 0, 2, 4), (1, 0, 2, 4), (1, 0, 2, 4)]);
|
||||
check_spans("/*! á\nc */", &[(1, 0, 2, 4), (1, 0, 2, 4), (1, 0, 2, 4)]);
|
||||
check_spans("abc", &[(1, 0, 1, 3)]);
|
||||
check_spans("ábc", &[(1, 0, 1, 3)]);
|
||||
check_spans("ábć", &[(1, 0, 1, 3)]);
|
||||
check_spans("abc// foo", &[(1, 0, 1, 3)]);
|
||||
check_spans("ábc// foo", &[(1, 0, 1, 3)]);
|
||||
check_spans("ábć// foo", &[(1, 0, 1, 3)]);
|
||||
check_spans("b\"a\\\n c\"", &[(1, 0, 2, 3)]);
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
fn check_spans(p: &str, mut lines: &[(usize, usize, usize, usize)]) {
|
||||
let ts = p.parse::<TokenStream>().unwrap();
|
||||
check_spans_internal(ts, &mut lines);
|
||||
assert!(lines.is_empty(), "leftover ranges: {:?}", lines);
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
fn check_spans_internal(ts: TokenStream, lines: &mut &[(usize, usize, usize, usize)]) {
|
||||
for i in ts {
|
||||
if let Some((&(sline, scol, eline, ecol), rest)) = lines.split_first() {
|
||||
*lines = rest;
|
||||
|
||||
let start = i.span().start();
|
||||
assert_eq!(start.line, sline, "sline did not match for {}", i);
|
||||
assert_eq!(start.column, scol, "scol did not match for {}", i);
|
||||
|
||||
let end = i.span().end();
|
||||
assert_eq!(end.line, eline, "eline did not match for {}", i);
|
||||
assert_eq!(end.column, ecol, "ecol did not match for {}", i);
|
||||
|
||||
if let TokenTree::Group(g) = i {
|
||||
check_spans_internal(g.stream().clone(), lines);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whitespace() {
|
||||
// space, horizontal tab, vertical tab, form feed, carriage return, line
|
||||
// feed, non-breaking space, left-to-right mark, right-to-left mark
|
||||
let various_spaces = " \t\u{b}\u{c}\r\n\u{a0}\u{200e}\u{200f}";
|
||||
let tokens = various_spaces.parse::<TokenStream>().unwrap();
|
||||
assert_eq!(tokens.into_iter().count(), 0);
|
||||
|
||||
let lone_carriage_returns = " \r \r\r\n ";
|
||||
lone_carriage_returns.parse::<TokenStream>().unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn byte_order_mark() {
|
||||
let string = "\u{feff}foo";
|
||||
let tokens = string.parse::<TokenStream>().unwrap();
|
||||
match tokens.into_iter().next().unwrap() {
|
||||
TokenTree::Ident(ident) => assert_eq!(ident, "foo"),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let string = "foo\u{feff}";
|
||||
string.parse::<TokenStream>().unwrap_err();
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
fn create_span() -> proc_macro2::Span {
|
||||
let tts: TokenStream = "1".parse().unwrap();
|
||||
match tts.into_iter().next().unwrap() {
|
||||
TokenTree::Literal(literal) => literal.span(),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
#[test]
|
||||
fn test_invalidate_current_thread_spans() {
|
||||
let actual = format!("{:#?}", create_span());
|
||||
assert_eq!(actual, "bytes(1..2)");
|
||||
let actual = format!("{:#?}", create_span());
|
||||
assert_eq!(actual, "bytes(3..4)");
|
||||
|
||||
proc_macro2::extra::invalidate_current_thread_spans();
|
||||
|
||||
let actual = format!("{:#?}", create_span());
|
||||
// Test that span offsets have been reset after the call
|
||||
// to invalidate_current_thread_spans()
|
||||
assert_eq!(actual, "bytes(1..2)");
|
||||
}
|
||||
|
||||
#[cfg(span_locations)]
|
||||
#[test]
|
||||
#[should_panic(expected = "Invalid span with no related FileInfo!")]
|
||||
fn test_use_span_after_invalidation() {
|
||||
let span = create_span();
|
||||
|
||||
proc_macro2::extra::invalidate_current_thread_spans();
|
||||
|
||||
span.source_text();
|
||||
}
|
||||
28
vendor/proc-macro2/tests/test_fmt.rs
vendored
Normal file
28
vendor/proc-macro2/tests/test_fmt.rs
vendored
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#![allow(clippy::from_iter_instead_of_collect)]
|
||||
|
||||
use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
|
||||
use std::iter;
|
||||
|
||||
#[test]
|
||||
fn test_fmt_group() {
|
||||
let ident = Ident::new("x", Span::call_site());
|
||||
let inner = TokenStream::from_iter(iter::once(TokenTree::Ident(ident)));
|
||||
let parens_empty = Group::new(Delimiter::Parenthesis, TokenStream::new());
|
||||
let parens_nonempty = Group::new(Delimiter::Parenthesis, inner.clone());
|
||||
let brackets_empty = Group::new(Delimiter::Bracket, TokenStream::new());
|
||||
let brackets_nonempty = Group::new(Delimiter::Bracket, inner.clone());
|
||||
let braces_empty = Group::new(Delimiter::Brace, TokenStream::new());
|
||||
let braces_nonempty = Group::new(Delimiter::Brace, inner.clone());
|
||||
let none_empty = Group::new(Delimiter::None, TokenStream::new());
|
||||
let none_nonempty = Group::new(Delimiter::None, inner);
|
||||
|
||||
// Matches libproc_macro.
|
||||
assert_eq!("()", parens_empty.to_string());
|
||||
assert_eq!("(x)", parens_nonempty.to_string());
|
||||
assert_eq!("[]", brackets_empty.to_string());
|
||||
assert_eq!("[x]", brackets_nonempty.to_string());
|
||||
assert_eq!("{ }", braces_empty.to_string());
|
||||
assert_eq!("{ x }", braces_nonempty.to_string());
|
||||
assert_eq!("", none_empty.to_string());
|
||||
assert_eq!("x", none_nonempty.to_string());
|
||||
}
|
||||
81
vendor/proc-macro2/tests/test_size.rs
vendored
Normal file
81
vendor/proc-macro2/tests/test_size.rs
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
#![allow(unused_attributes)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use std::mem;
|
||||
|
||||
#[rustversion::attr(before(1.64), ignore = "requires Rust 1.64+")]
|
||||
#[cfg_attr(not(target_pointer_width = "64"), ignore = "only applicable to 64-bit")]
|
||||
#[cfg_attr(randomize_layout, ignore = "disabled due to randomized layout")]
|
||||
#[test]
|
||||
fn test_proc_macro_size() {
|
||||
assert_eq!(mem::size_of::<proc_macro::Span>(), 4);
|
||||
assert_eq!(mem::size_of::<Option<proc_macro::Span>>(), 4);
|
||||
assert_eq!(mem::size_of::<proc_macro::Group>(), 20);
|
||||
assert_eq!(mem::size_of::<proc_macro::Ident>(), 12);
|
||||
assert_eq!(mem::size_of::<proc_macro::Punct>(), 8);
|
||||
assert_eq!(mem::size_of::<proc_macro::Literal>(), 16);
|
||||
assert_eq!(mem::size_of::<proc_macro::TokenStream>(), 4);
|
||||
}
|
||||
|
||||
#[cfg_attr(not(target_pointer_width = "64"), ignore = "only applicable to 64-bit")]
|
||||
#[cfg_attr(randomize_layout, ignore = "disabled due to randomized layout")]
|
||||
#[cfg_attr(wrap_proc_macro, ignore = "wrapper mode")]
|
||||
#[cfg_attr(span_locations, ignore = "span locations are on")]
|
||||
#[test]
|
||||
fn test_proc_macro2_fallback_size_without_locations() {
|
||||
assert_eq!(mem::size_of::<proc_macro2::Span>(), 0);
|
||||
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 1);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Group>(), 16);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 24);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 8);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 24);
|
||||
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 8);
|
||||
}
|
||||
|
||||
#[cfg_attr(not(target_pointer_width = "64"), ignore = "only applicable to 64-bit")]
|
||||
#[cfg_attr(randomize_layout, ignore = "disabled due to randomized layout")]
|
||||
#[cfg_attr(wrap_proc_macro, ignore = "wrapper mode")]
|
||||
#[cfg_attr(not(span_locations), ignore = "span locations are off")]
|
||||
#[test]
|
||||
fn test_proc_macro2_fallback_size_with_locations() {
|
||||
assert_eq!(mem::size_of::<proc_macro2::Span>(), 8);
|
||||
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 12);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Group>(), 24);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 32);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 16);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 32);
|
||||
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 8);
|
||||
}
|
||||
|
||||
#[rustversion::attr(before(1.71), ignore = "requires Rust 1.71+")]
|
||||
#[cfg_attr(not(target_pointer_width = "64"), ignore = "only applicable to 64-bit")]
|
||||
#[cfg_attr(randomize_layout, ignore = "disabled due to randomized layout")]
|
||||
#[cfg_attr(not(wrap_proc_macro), ignore = "fallback mode")]
|
||||
#[cfg_attr(span_locations, ignore = "span locations are on")]
|
||||
#[test]
|
||||
fn test_proc_macro2_wrapper_size_without_locations() {
|
||||
assert_eq!(mem::size_of::<proc_macro2::Span>(), 4);
|
||||
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 8);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Group>(), 24);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 24);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 12);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 24);
|
||||
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 32);
|
||||
}
|
||||
|
||||
#[rustversion::attr(before(1.65), ignore = "requires Rust 1.65+")]
|
||||
#[cfg_attr(not(target_pointer_width = "64"), ignore = "only applicable to 64-bit")]
|
||||
#[cfg_attr(randomize_layout, ignore = "disabled due to randomized layout")]
|
||||
#[cfg_attr(not(wrap_proc_macro), ignore = "fallback mode")]
|
||||
#[cfg_attr(not(span_locations), ignore = "span locations are off")]
|
||||
#[test]
|
||||
fn test_proc_macro2_wrapper_size_with_locations() {
|
||||
assert_eq!(mem::size_of::<proc_macro2::Span>(), 12);
|
||||
assert_eq!(mem::size_of::<Option<proc_macro2::Span>>(), 12);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Group>(), 32);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Ident>(), 32);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Punct>(), 20);
|
||||
assert_eq!(mem::size_of::<proc_macro2::Literal>(), 32);
|
||||
assert_eq!(mem::size_of::<proc_macro2::TokenStream>(), 32);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue