diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:45:06 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-06-15 21:45:06 +0000 |
commit | cfcf3125222fe2e932ca5dd70044c123d90bf311 (patch) | |
tree | 44cebb73ced35debf89bc3554d7388321cd1a37b | |
parent | dda352945eb859600ef28722db3b64e4b134441d (diff) | |
parent | cfc7d1dc1fc3c6a5269340e2169efee176549f4d (diff) | |
download | proc-macro2-aml_tz3_314012010.tar.gz |
Snap for 8730993 from cfc7d1dc1fc3c6a5269340e2169efee176549f4d to mainline-tzdata3-releaseaml_tz3_314012070aml_tz3_314012050aml_tz3_314012010aml_tz3_313110000aml_tz3_312511020aml_tz3_312511010aml_tz3_312410020aml_tz3_312410010android12-mainline-tzdata3-releaseaml_tz3_314012010
Change-Id: I8eb3d9e1846d1e98e252c5b58fbc30921b66ff0d
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 39 | ||||
-rw-r--r-- | Android.bp | 84 | ||||
-rw-r--r-- | Cargo.toml | 17 | ||||
-rw-r--r-- | Cargo.toml.orig | 8 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | TEST_MAPPING | 157 | ||||
-rw-r--r-- | build.rs | 68 | ||||
-rw-r--r-- | cargo2android.json | 6 | ||||
-rw-r--r-- | src/detection.rs | 18 | ||||
-rw-r--r-- | src/fallback.rs | 108 | ||||
-rw-r--r-- | src/lib.rs | 107 | ||||
-rw-r--r-- | src/parse.rs | 19 | ||||
-rw-r--r-- | src/wrapper.rs | 89 | ||||
-rw-r--r-- | tests/comments.rs | 18 | ||||
-rw-r--r-- | tests/marker.rs | 12 | ||||
-rw-r--r-- | tests/test.rs | 27 | ||||
-rw-r--r-- | tests/test_fmt.rs | 4 |
19 files changed, 307 insertions, 496 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 59bd97e..1eb63e4 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,5 @@ { "git": { - "sha1": "7ecea3b88fe72672ca4270631b5d4585c0f7c715" - }, - "path_in_vcs": "" -}
\ No newline at end of file + "sha1": "56043a1715cf9c458e5203bdf792668e3b271651" + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2063a5c..e469b08 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: jobs: test: - name: Rust ${{matrix.rust}} + name: Rust ${{ matrix.rust }} runs-on: ubuntu-latest strategy: fail-fast: false @@ -15,9 +15,11 @@ jobs: rust: [1.31.0, stable, beta] steps: - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@master + - uses: actions-rs/toolchain@v1 with: - toolchain: ${{matrix.rust}} + toolchain: ${{ matrix.rust }} + profile: minimal + override: true - run: cargo test - run: cargo test --no-default-features - run: cargo test --features span-locations @@ -29,7 +31,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@nightly + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + override: true - run: cargo test - run: cargo test --no-default-features - run: cargo test --no-default-features -- --ignored # run the ignored test to make sure the `proc-macro` feature is disabled @@ -45,26 +51,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@nightly + - uses: actions-rs/toolchain@v1 with: + toolchain: nightly target: wasm32-unknown-unknown + profile: minimal + override: true - run: cargo test --target wasm32-unknown-unknown --no-run clippy: name: Clippy runs-on: ubuntu-latest - if: github.event_name != 'pull_request' - steps: - - uses: actions/checkout@v2 - - uses: dtolnay/rust-toolchain@clippy - - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic - - run: cargo clippy --tests --all-features -- -Dclippy::all -Dclippy::pedantic - - outdated: - name: Outdated - runs-on: ubuntu-latest - if: github.event_name != 'pull_request' steps: - uses: actions/checkout@v2 - - uses: dtolnay/install@cargo-outdated - - run: cargo outdated --exit-code 1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: nightly + profile: minimal + override: true + components: clippy + - run: cargo clippy -- -Dclippy::all @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --config cargo2android.json. +// This file is generated by cargo2android.py --run --dependencies --tests --host-first-multilib --features=default,span-locations. // Do not modify this file as changes will be overridden on upgrade. package { @@ -40,8 +40,6 @@ license { rust_library_host { name: "libproc_macro2", crate_name: "proc_macro2", - cargo_env_compat: true, - cargo_pkg_version: "1.0.36", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -49,10 +47,13 @@ rust_library_host { "proc-macro", "span-locations", ], - cfgs: [ - "span_locations", - "use_proc_macro", - "wrap_proc_macro", + flags: [ + "--cfg hygiene", + "--cfg lexerror_display", + "--cfg proc_macro_span", + "--cfg span_locations", + "--cfg use_proc_macro", + "--cfg wrap_proc_macro", ], rustlibs: [ "libunicode_xid", @@ -60,11 +61,38 @@ rust_library_host { compile_multilib: "first", } +rust_test_host { + name: "proc-macro2_host_test_src_lib", + crate_name: "proc_macro2", + srcs: ["src/lib.rs"], + test_suites: ["general-tests"], + auto_gen_config: true, + test_options: { + unit_test: true, + }, + edition: "2018", + features: [ + "default", + "proc-macro", + "span-locations", + ], + flags: [ + "--cfg hygiene", + "--cfg lexerror_display", + "--cfg proc_macro_span", + "--cfg span_locations", + "--cfg use_proc_macro", + "--cfg wrap_proc_macro", + ], + rustlibs: [ + "libquote", + "libunicode_xid", + ], +} + rust_defaults { - name: "proc-macro2_test_defaults", + name: "proc-macro2_defaults", crate_name: "proc_macro2", - cargo_env_compat: true, - cargo_pkg_version: "1.0.36", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", @@ -73,10 +101,13 @@ rust_defaults { "proc-macro", "span-locations", ], - cfgs: [ - "span_locations", - "use_proc_macro", - "wrap_proc_macro", + flags: [ + "--cfg hygiene", + "--cfg lexerror_display", + "--cfg proc_macro_span", + "--cfg span_locations", + "--cfg use_proc_macro", + "--cfg wrap_proc_macro", ], rustlibs: [ "libproc_macro2", @@ -86,8 +117,8 @@ rust_defaults { } rust_test_host { - name: "proc-macro2_test_tests_comments", - defaults: ["proc-macro2_test_defaults"], + name: "proc-macro2_host_test_tests_comments", + defaults: ["proc-macro2_defaults"], srcs: ["tests/comments.rs"], test_options: { unit_test: true, @@ -95,8 +126,8 @@ rust_test_host { } rust_test_host { - name: "proc-macro2_test_tests_features", - defaults: ["proc-macro2_test_defaults"], + name: "proc-macro2_host_test_tests_features", + defaults: ["proc-macro2_defaults"], srcs: ["tests/features.rs"], test_options: { unit_test: true, @@ -104,8 +135,8 @@ rust_test_host { } rust_test_host { - name: "proc-macro2_test_tests_marker", - defaults: ["proc-macro2_test_defaults"], + name: "proc-macro2_host_test_tests_marker", + defaults: ["proc-macro2_defaults"], srcs: ["tests/marker.rs"], test_options: { unit_test: true, @@ -113,8 +144,8 @@ rust_test_host { } rust_test_host { - name: "proc-macro2_test_tests_test", - defaults: ["proc-macro2_test_defaults"], + name: "proc-macro2_host_test_tests_test", + defaults: ["proc-macro2_defaults"], srcs: ["tests/test.rs"], test_options: { unit_test: true, @@ -122,10 +153,15 @@ rust_test_host { } rust_test_host { - name: "proc-macro2_test_tests_test_fmt", - defaults: ["proc-macro2_test_defaults"], + name: "proc-macro2_host_test_tests_test_fmt", + defaults: ["proc-macro2_defaults"], srcs: ["tests/test_fmt.rs"], test_options: { unit_test: true, }, } + +// dependent_library ["feature_list"] +// proc-macro2-1.0.26 +// quote-1.0.9 +// unicode-xid-0.2.1 "default" @@ -3,26 +3,25 @@ # 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. +# 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. +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) [package] edition = "2018" -rust-version = "1.31" name = "proc-macro2" -version = "1.0.36" -authors = ["David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>"] -autobenches = false +version = "1.0.26" +authors = ["Alex Crichton <alex@alexcrichton.com>", "David Tolnay <dtolnay@gmail.com>"] description = "A substitute implementation of the compiler's `proc_macro` API to decouple\ntoken-based libraries from the procedural macro use case.\n" documentation = "https://docs.rs/proc-macro2" readme = "README.md" keywords = ["macros"] categories = ["development-tools::procedural-macro-helpers"] license = "MIT OR Apache-2.0" -repository = "https://github.com/dtolnay/proc-macro2" +repository = "https://github.com/alexcrichton/proc-macro2" [package.metadata.docs.rs] rustc-args = ["--cfg", "procmacro2_semver_exempt"] rustdoc-args = ["--cfg", "procmacro2_semver_exempt", "--cfg", "doc_cfg"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 401bfaf..f229dbe 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,16 +1,14 @@ [package] name = "proc-macro2" -version = "1.0.36" # remember to update html_root_url -authors = ["David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>"] +version = "1.0.26" # remember to update html_root_url +authors = ["Alex Crichton <alex@alexcrichton.com>", "David Tolnay <dtolnay@gmail.com>"] license = "MIT OR Apache-2.0" readme = "README.md" keywords = ["macros"] -repository = "https://github.com/dtolnay/proc-macro2" +repository = "https://github.com/alexcrichton/proc-macro2" documentation = "https://docs.rs/proc-macro2" categories = ["development-tools::procedural-macro-helpers"] edition = "2018" -autobenches = false -rust-version = "1.31" description = """ A substitute implementation of the compiler's `proc_macro` API to decouple token-based libraries from the procedural macro use case. @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.36.crate" + value: "https://static.crates.io/crates/proc-macro2/proc-macro2-1.0.26.crate" } - version: "1.0.36" + version: "1.0.26" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 3 + year: 2021 + month: 4 day: 1 } } @@ -1,9 +1,8 @@ # 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&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/proc-macro2) -[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/proc-macro2/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/proc-macro2/actions?query=branch%3Amaster) +[![Build Status](https://img.shields.io/github/workflow/status/alexcrichton/proc-macro2/build%20and%20test)](https://github.com/alexcrichton/proc-macro2/actions) +[![Latest Version](https://img.shields.io/crates/v/proc-macro2.svg)](https://crates.io/crates/proc-macro2) +[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/proc-macro2) A wrapper around the procedural macro API of the compiler's `proc_macro` crate. This library serves two purposes: diff --git a/TEST_MAPPING b/TEST_MAPPING index 76a8253..2e3c81b 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,231 +1,224 @@ // Generated by update_crate_tests.py for tests that depend on this crate. { - "imports": [ + "presubmit": [ { - "path": "external/rust/crates/anyhow" + "name": "ZipFuseTest" }, { - "path": "external/rust/crates/arbitrary" + "name": "anyhow_device_test_src_lib" }, { - "path": "external/rust/crates/argh" + "name": "anyhow_device_test_tests_test_autotrait" }, { - "path": "external/rust/crates/base64" + "name": "anyhow_device_test_tests_test_boxed" }, { - "path": "external/rust/crates/bitflags" + "name": "anyhow_device_test_tests_test_chain" }, { - "path": "external/rust/crates/bytes" + "name": "anyhow_device_test_tests_test_context" }, { - "path": "external/rust/crates/either" + "name": "anyhow_device_test_tests_test_convert" }, { - "path": "external/rust/crates/futures-util" + "name": "anyhow_device_test_tests_test_downcast" }, { - "path": "external/rust/crates/jni" + "name": "anyhow_device_test_tests_test_ffi" }, { - "path": "external/rust/crates/libm" + "name": "anyhow_device_test_tests_test_fmt" }, { - "path": "external/rust/crates/libsqlite3-sys" + "name": "anyhow_device_test_tests_test_macros" }, { - "path": "external/rust/crates/oid-registry" + "name": "anyhow_device_test_tests_test_repr" }, { - "path": "external/rust/crates/rand_chacha" + "name": "anyhow_device_test_tests_test_source" }, { - "path": "external/rust/crates/serde" + "name": "authfs_device_test_src_lib" }, { - "path": "external/rust/crates/serde-xml-rs" + "name": "doh_unit_test" }, { - "path": "external/rust/crates/serde_cbor" + "name": "either_device_test_src_lib" }, { - "path": "external/rust/crates/slab" + "name": "futures-util_device_test_src_lib" }, { - "path": "external/rust/crates/tinytemplate" + "name": "keystore2_crypto_test_rust" }, { - "path": "external/rust/crates/tinyvec" + "name": "keystore2_selinux_test" }, { - "path": "external/rust/crates/tokio" + "name": "keystore2_test" }, { - "path": "external/rust/crates/tokio-test" + "name": "libm_device_test_src_lib" }, { - "path": "external/rust/crates/unicode-bidi" + "name": "libsqlite3-sys_device_test_src_lib" }, { - "path": "external/rust/crates/unicode-xid" + "name": "serde_cbor_device_test_src_lib" }, { - "path": "external/rust/crates/url" - } - ], - "presubmit": [ - { - "name": "ZipFuseTest" + "name": "serde_cbor_device_test_tests_bennofs" }, { - "name": "apkdmverity.test" + "name": "serde_cbor_device_test_tests_canonical" }, { - "name": "authfs_device_test_src_lib" + "name": "serde_cbor_device_test_tests_de" }, { - "name": "diced_open_dice_cbor_test" + "name": "serde_cbor_device_test_tests_enum" }, { - "name": "diced_sample_inputs_test" + "name": "serde_cbor_device_test_tests_ser" }, { - "name": "diced_test" + "name": "serde_cbor_device_test_tests_std_types" }, { - "name": "diced_utils_test" + "name": "serde_cbor_device_test_tests_tags" }, { - "name": "diced_vendor_test" + "name": "serde_cbor_device_test_tests_value" }, { - "name": "doh_unit_test" + "name": "serde_test_device_test_src_lib" }, { - "name": "keystore2_crypto_test_rust" + "name": "tokio-test_device_test_src_lib" }, { - "name": "keystore2_km_compat_test" + "name": "tokio-test_device_test_tests_block_on" }, { - "name": "keystore2_selinux_concurrency_test" + "name": "tokio-test_device_test_tests_io" }, { - "name": "keystore2_selinux_test" + "name": "tokio-test_device_test_tests_macros" }, { - "name": "keystore2_test" + "name": "tokio_device_test_tests_buffered" }, { - "name": "keystore2_test_utils_test" + "name": "tokio_device_test_tests_io_async_read" }, { - "name": "keystore2_vintf_test" + "name": "tokio_device_test_tests_io_copy_bidirectional" }, { - "name": "legacykeystore_test" + "name": "tokio_device_test_tests_io_lines" }, { - "name": "libapkverify.integration_test" + "name": "tokio_device_test_tests_io_mem_stream" }, { - "name": "libapkverify.test" + "name": "tokio_device_test_tests_io_read" }, { - "name": "libcert_request_validator_tests" + "name": "tokio_device_test_tests_io_read_buf" }, { - "name": "libidsig.test" + "name": "tokio_device_test_tests_io_read_to_end" }, { - "name": "librustutils_test" + "name": "tokio_device_test_tests_io_take" }, { - "name": "microdroid_manager_test" + "name": "tokio_device_test_tests_io_write" }, { - "name": "rustBinderTest" + "name": "tokio_device_test_tests_io_write_all" }, { - "name": "virtualizationservice_device_test" - } - ], - "presubmit-rust": [ + "name": "tokio_device_test_tests_io_write_buf" + }, { - "name": "ZipFuseTest" + "name": "tokio_device_test_tests_io_write_int" }, { - "name": "apkdmverity.test" + "name": "tokio_device_test_tests_macros_join" }, { - "name": "authfs_device_test_src_lib" + "name": "tokio_device_test_tests_no_rt" }, { - "name": "diced_open_dice_cbor_test" + "name": "tokio_device_test_tests_rt_basic" }, { - "name": "diced_sample_inputs_test" + "name": "tokio_device_test_tests_rt_threaded" }, { - "name": "diced_test" + "name": "tokio_device_test_tests_sync_barrier" }, { - "name": "diced_utils_test" + "name": "tokio_device_test_tests_sync_broadcast" }, { - "name": "diced_vendor_test" + "name": "tokio_device_test_tests_sync_errors" }, { - "name": "doh_unit_test" + "name": "tokio_device_test_tests_sync_mpsc" }, { - "name": "keystore2_crypto_test_rust" + "name": "tokio_device_test_tests_sync_mutex_owned" }, { - "name": "keystore2_km_compat_test" + "name": "tokio_device_test_tests_sync_rwlock" }, { - "name": "keystore2_selinux_concurrency_test" + "name": "tokio_device_test_tests_sync_watch" }, { - "name": "keystore2_selinux_test" + "name": "tokio_device_test_tests_task_local" }, { - "name": "keystore2_test" + "name": "tokio_device_test_tests_task_local_set" }, { - "name": "keystore2_test_utils_test" + "name": "tokio_device_test_tests_tcp_accept" }, { - "name": "keystore2_vintf_test" + "name": "tokio_device_test_tests_tcp_echo" }, { - "name": "legacykeystore_test" + "name": "tokio_device_test_tests_tcp_into_std" }, { - "name": "libapkverify.integration_test" + "name": "tokio_device_test_tests_tcp_shutdown" }, { - "name": "libapkverify.test" + "name": "tokio_device_test_tests_time_rt" }, { - "name": "libcert_request_validator_tests" + "name": "tokio_device_test_tests_uds_split" }, { - "name": "libidsig.test" + "name": "unicode-bidi_device_test_src_lib" }, { - "name": "librustutils_test" + "name": "url_device_test_src_lib" }, { - "name": "microdroid_manager_test" + "name": "url_device_test_tests_data" }, { - "name": "rustBinderTest" + "name": "url_device_test_tests_unit" }, { - "name": "virtualizationservice_device_test" + "name": "vpnprofilestore_test" } ] } @@ -33,15 +33,8 @@ // location of a token. Enabled by procmacro2_semver_exempt or the // "span-locations" Cargo cfg. This is behind a cfg because tracking // location inside spans is a performance hit. -// -// "is_available" -// Use proc_macro::is_available() to detect if the proc macro API is -// available or needs to be polyfilled instead of trying to use the proc -// macro API and catching a panic if it isn't available. Enabled on Rust -// 1.57+. use std::env; -use std::iter; use std::process::{self, Command}; use std::str; @@ -58,10 +51,9 @@ fn main() { process::exit(1); } - let docs_rs = env::var_os("DOCS_RS").is_some(); - let semver_exempt = cfg!(procmacro2_semver_exempt) || docs_rs; + let semver_exempt = cfg!(procmacro2_semver_exempt); if semver_exempt { - // https://github.com/dtolnay/proc-macro2/issues/147 + // https://github.com/alexcrichton/proc-macro2/issues/147 println!("cargo:rustc-cfg=procmacro2_semver_exempt"); } @@ -77,24 +69,12 @@ fn main() { println!("cargo:rustc-cfg=no_bind_by_move_pattern_guard"); } - if version.minor < 44 { - println!("cargo:rustc-cfg=no_lexerror_display"); - } - - if version.minor < 45 { - println!("cargo:rustc-cfg=no_hygiene"); - } - - if version.minor < 54 { - println!("cargo:rustc-cfg=no_literal_from_str"); - } - - if version.minor < 55 { - println!("cargo:rustc-cfg=no_group_open_close"); + if version.minor >= 44 { + println!("cargo:rustc-cfg=lexerror_display"); } - if version.minor < 57 { - println!("cargo:rustc-cfg=no_is_available"); + if version.minor >= 45 { + println!("cargo:rustc-cfg=hygiene"); } let target = env::var("TARGET").unwrap(); @@ -152,33 +132,15 @@ fn feature_allowed(feature: &str) -> bool { // // -Zallow-features=feature1,feature2 - let flags_var; - let flags_var_string; - let mut flags_var_split; - let mut flags_none; - let flags: &mut dyn Iterator<Item = &str> = - if let Some(encoded_rustflags) = env::var_os("CARGO_ENCODED_RUSTFLAGS") { - flags_var = encoded_rustflags; - flags_var_string = flags_var.to_string_lossy(); - flags_var_split = flags_var_string.split('\x1f'); - &mut flags_var_split - } else if let Some(rustflags) = env::var_os("RUSTFLAGS") { - flags_var = rustflags; - flags_var_string = flags_var.to_string_lossy(); - flags_var_split = flags_var_string.split(' '); - &mut flags_var_split - } else { - flags_none = iter::empty(); - &mut flags_none - }; - - for mut flag in flags { - if flag.starts_with("-Z") { - flag = &flag["-Z".len()..]; - } - if flag.starts_with("allow-features=") { - flag = &flag["allow-features=".len()..]; - return flag.split(',').any(|allowed| allowed == feature); + if let Some(rustflags) = env::var_os("RUSTFLAGS") { + for mut flag in rustflags.to_string_lossy().split(' ') { + if flag.starts_with("-Z") { + flag = &flag["-Z".len()..]; + } + if flag.starts_with("allow-features=") { + flag = &flag["allow-features=".len()..]; + return flag.split(',').any(|allowed| allowed == feature); + } } } diff --git a/cargo2android.json b/cargo2android.json deleted file mode 100644 index 45a2954..0000000 --- a/cargo2android.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "features": "default,span-locations", - "host-first-multilib": true, - "run": true, - "tests": true -}
\ No newline at end of file diff --git a/src/detection.rs b/src/detection.rs index d139b73..c597bc9 100644 --- a/src/detection.rs +++ b/src/detection.rs @@ -1,11 +1,12 @@ -use std::sync::atomic::{AtomicUsize, Ordering}; +use std::panic::{self, PanicInfo}; +use std::sync::atomic::*; 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) { + match WORKS.load(Ordering::SeqCst) { 1 => return false, 2 => return true, _ => {} @@ -16,19 +17,13 @@ pub(crate) fn inside_proc_macro() -> bool { } pub(crate) fn force_fallback() { - WORKS.store(1, Ordering::Relaxed); + WORKS.store(1, Ordering::SeqCst); } 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 @@ -53,10 +48,7 @@ fn initialize() { // 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 */ }); @@ -65,7 +57,7 @@ fn initialize() { 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); + WORKS.store(works as usize + 1, Ordering::SeqCst); let hopefully_null_hook = panic::take_hook(); panic::set_hook(original_hook); diff --git a/src/fallback.rs b/src/fallback.rs index ac5437d..50d10db 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -31,7 +31,7 @@ pub fn unforce() { #[derive(Clone)] pub(crate) struct TokenStream { - inner: Vec<TokenTree>, + pub(crate) inner: Vec<TokenTree>, } #[derive(Debug)] @@ -43,16 +43,10 @@ impl LexError { pub(crate) fn span(&self) -> Span { self.span } - - fn call_site() -> Self { - LexError { - span: Span::call_site(), - } - } } impl TokenStream { - pub fn new() -> Self { + pub fn new() -> TokenStream { TokenStream { inner: Vec::new() } } @@ -65,7 +59,7 @@ impl TokenStream { } fn push_token(&mut self, token: TokenTree) { - // https://github.com/dtolnay/proc-macro2/issues/235 + // https://github.com/alexcrichton/proc-macro2/issues/235 match token { #[cfg(not(no_bind_by_move_pattern_guard))] TokenTree::Literal(crate::Literal { @@ -74,7 +68,7 @@ impl TokenStream { #[cfg(not(wrap_proc_macro))] inner: literal, .. - }) if literal.repr.starts_with('-') => { + }) if literal.text.starts_with('-') => { push_negative_literal(self, literal); } #[cfg(no_bind_by_move_pattern_guard)] @@ -85,7 +79,7 @@ impl TokenStream { inner: literal, .. }) => { - if literal.repr.starts_with('-') { + if literal.text.starts_with('-') { push_negative_literal(self, literal); } else { self.inner @@ -97,7 +91,7 @@ impl TokenStream { #[cold] fn push_negative_literal(stream: &mut TokenStream, mut literal: Literal) { - literal.repr.remove(0); + literal.text.remove(0); let mut punct = crate::Punct::new('-', Spacing::Alone); punct.set_span(crate::Span::_new_stable(literal.span)); stream.inner.push(TokenTree::Punct(punct)); @@ -108,12 +102,6 @@ impl TokenStream { } } -impl From<Vec<TokenTree>> for TokenStream { - fn from(inner: Vec<TokenTree>) -> Self { - TokenStream { inner } - } -} - // Nonrecursive to prevent stack overflow. impl Drop for TokenStream { fn drop(&mut self) { @@ -125,7 +113,7 @@ impl Drop for TokenStream { #[cfg(wrap_proc_macro)] let group = match group { crate::imp::Group::Fallback(group) => group, - crate::imp::Group::Compiler(_) => continue, + _ => continue, }; let mut group = group; self.inner.extend(group.stream.take_inner()); @@ -185,7 +173,7 @@ impl Display for TokenStream { Display::fmt(tt, f) } TokenTree::Literal(tt) => Display::fmt(tt, f), - }?; + }? } Ok(()) @@ -423,22 +411,22 @@ pub(crate) struct Span { impl Span { #[cfg(not(span_locations))] - pub fn call_site() -> Self { + pub fn call_site() -> Span { Span {} } #[cfg(span_locations)] - pub fn call_site() -> Self { + pub fn call_site() -> Span { Span { lo: 0, hi: 0 } } - #[cfg(not(no_hygiene))] - pub fn mixed_site() -> Self { + #[cfg(hygiene)] + pub fn mixed_site() -> Span { Span::call_site() } #[cfg(procmacro2_semver_exempt)] - pub fn def_site() -> Self { + pub fn def_site() -> Span { Span::call_site() } @@ -560,7 +548,7 @@ pub(crate) struct Group { } impl Group { - pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self { + pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group { Group { delimiter, stream, @@ -638,7 +626,7 @@ pub(crate) struct Ident { } impl Ident { - fn _new(string: &str, raw: bool, span: Span) -> Self { + fn _new(string: &str, raw: bool, span: Span) -> Ident { validate_ident(string); Ident { @@ -648,11 +636,11 @@ impl Ident { } } - pub fn new(string: &str, span: Span) -> Self { + pub fn new(string: &str, span: Span) -> Ident { Ident::_new(string, false, span) } - pub fn new_raw(string: &str, span: Span) -> Self { + pub fn new_raw(string: &str, span: Span) -> Ident { Ident::_new(string, true, span) } @@ -762,7 +750,7 @@ impl Debug for Ident { #[derive(Clone)] pub(crate) struct Literal { - repr: String, + text: String, span: Span, } @@ -783,17 +771,13 @@ macro_rules! unsuffixed_numbers { } impl Literal { - pub(crate) fn _new(repr: String) -> Self { + pub(crate) fn _new(text: String) -> Literal { Literal { - repr, + text, span: Span::call_site(), } } - pub(crate) unsafe fn from_str_unchecked(repr: &str) -> Self { - Literal::_new(repr.to_owned()) - } - suffixed_numbers! { u8_suffixed => u8, u16_suffixed => u16, @@ -844,31 +828,31 @@ impl Literal { } pub fn string(t: &str) -> Literal { - let mut repr = String::with_capacity(t.len() + 2); - repr.push('"'); + let mut text = String::with_capacity(t.len() + 2); + text.push('"'); for c in t.chars() { if c == '\'' { // escape_debug turns this into "\'" which is unnecessary. - repr.push(c); + text.push(c); } else { - repr.extend(c.escape_debug()); + text.extend(c.escape_debug()); } } - repr.push('"'); - Literal::_new(repr) + text.push('"'); + Literal::_new(text) } pub fn character(t: char) -> Literal { - let mut repr = String::new(); - repr.push('\''); + let mut text = String::new(); + text.push('\''); if t == '"' { // escape_debug turns this into '\"' which is unnecessary. - repr.push(t); + text.push(t); } else { - repr.extend(t.escape_debug()); + text.extend(t.escape_debug()); } - repr.push('\''); - Literal::_new(repr) + text.push('\''); + Literal::_new(text) } pub fn byte_string(bytes: &[u8]) -> Literal { @@ -903,40 +887,16 @@ impl Literal { } } -impl FromStr for Literal { - type Err = LexError; - - fn from_str(mut repr: &str) -> Result<Self, Self::Err> { - let negative = repr.starts_with('-'); - if negative { - repr = &repr[1..]; - if !repr.starts_with(|ch: char| ch.is_ascii_digit()) { - return Err(LexError::call_site()); - } - } - let cursor = get_cursor(repr); - if let Ok((_rest, mut literal)) = parse::literal(cursor) { - if literal.repr.len() == repr.len() { - if negative { - literal.repr.insert(0, '-'); - } - return Ok(literal); - } - } - Err(LexError::call_site()) - } -} - impl Display for Literal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.repr, f) + Display::fmt(&self.text, f) } } impl Debug for Literal { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { let mut debug = fmt.debug_struct("Literal"); - debug.field("lit", &format_args!("{}", self.repr)); + debug.field("lit", &format_args!("{}", self.text)); debug_span_field_if_nontrivial(&mut debug, self.span); debug.finish() } @@ -1,11 +1,3 @@ -//! [![github]](https://github.com/dtolnay/proc-macro2) [![crates-io]](https://crates.io/crates/proc-macro2) [![docs-rs]](crate) -//! -//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github -//! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust -//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K -//! -//! <br> -//! //! A wrapper around the procedural macro API of the compiler's [`proc_macro`] //! crate. This library serves two purposes: //! @@ -86,34 +78,11 @@ //! a different thread. // Proc-macro2 types in rustdoc of other crates get linked to here. -#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.36")] +#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.26")] #![cfg_attr(any(proc_macro_span, super_unstable), feature(proc_macro_span))] -#![cfg_attr(super_unstable, feature(proc_macro_def_site))] +#![cfg_attr(super_unstable, feature(proc_macro_raw_ident, proc_macro_def_site))] #![cfg_attr(doc_cfg, feature(doc_cfg))] -#![allow( - clippy::cast_lossless, - clippy::cast_possible_truncation, - clippy::doc_markdown, - clippy::items_after_statements, - clippy::manual_assert, - clippy::must_use_candidate, - clippy::needless_doctest_main, - clippy::return_self_not_must_use, - clippy::shadow_unrelated, - clippy::trivially_copy_pass_by_ref, - clippy::unnecessary_wraps, - clippy::unused_self, - clippy::used_underscore_binding, - clippy::vec_init_then_push -)] - -#[cfg(all(procmacro2_semver_exempt, wrap_proc_macro, not(super_unstable)))] -compile_error! {"\ - Something is not right. If you've tried to turn on \ - procmacro2_semver_exempt, you need to ensure that it \ - is turned on for the compilation of the proc-macro2 \ - build script as well. -"} +#![allow(clippy::needless_doctest_main, clippy::vec_init_then_push)] #[cfg(use_proc_macro)] extern crate proc_macro; @@ -166,14 +135,14 @@ pub struct LexError { } impl TokenStream { - fn _new(inner: imp::TokenStream) -> Self { + fn _new(inner: imp::TokenStream) -> TokenStream { TokenStream { inner, _marker: Marker, } } - fn _new_stable(inner: fallback::TokenStream) -> Self { + fn _new_stable(inner: fallback::TokenStream) -> TokenStream { TokenStream { inner: inner.into(), _marker: Marker, @@ -181,7 +150,7 @@ impl TokenStream { } /// Returns an empty `TokenStream` containing no token trees. - pub fn new() -> Self { + pub fn new() -> TokenStream { TokenStream::_new(imp::TokenStream::new()) } @@ -241,14 +210,14 @@ impl From<TokenTree> for TokenStream { impl Extend<TokenTree> for TokenStream { fn extend<I: IntoIterator<Item = TokenTree>>(&mut self, streams: I) { - self.inner.extend(streams); + self.inner.extend(streams) } } impl Extend<TokenStream> for TokenStream { fn extend<I: IntoIterator<Item = TokenStream>>(&mut self, streams: I) { self.inner - .extend(streams.into_iter().map(|stream| stream.inner)); + .extend(streams.into_iter().map(|stream| stream.inner)) } } @@ -304,7 +273,7 @@ impl Error for LexError {} /// The source file of a given `Span`. /// /// This type is semver exempt and not exposed by default. -#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))] +#[cfg(procmacro2_semver_exempt)] #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] #[derive(Clone, PartialEq, Eq)] pub struct SourceFile { @@ -312,7 +281,7 @@ pub struct SourceFile { _marker: Marker, } -#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))] +#[cfg(procmacro2_semver_exempt)] impl SourceFile { fn _new(inner: imp::SourceFile) -> Self { SourceFile { @@ -345,7 +314,7 @@ impl SourceFile { } } -#[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))] +#[cfg(procmacro2_semver_exempt)] impl Debug for SourceFile { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { Debug::fmt(&self.inner, f) @@ -391,14 +360,14 @@ pub struct Span { } impl Span { - fn _new(inner: imp::Span) -> Self { + fn _new(inner: imp::Span) -> Span { Span { inner, _marker: Marker, } } - fn _new_stable(inner: fallback::Span) -> Self { + fn _new_stable(inner: fallback::Span) -> Span { Span { inner: inner.into(), _marker: Marker, @@ -410,7 +379,7 @@ impl Span { /// Identifiers created with this span will be resolved as if they were /// written directly at the macro call location (call-site hygiene) and /// other code at the macro call site will be able to refer to them as well. - pub fn call_site() -> Self { + pub fn call_site() -> Span { Span::_new(imp::Span::call_site()) } @@ -419,8 +388,8 @@ impl Span { /// of the macro. This is the same hygiene behavior as `macro_rules`. /// /// This function requires Rust 1.45 or later. - #[cfg(not(no_hygiene))] - pub fn mixed_site() -> Self { + #[cfg(hygiene)] + pub fn mixed_site() -> Span { Span::_new(imp::Span::mixed_site()) } @@ -429,7 +398,7 @@ impl Span { /// This method is semver exempt and not exposed by default. #[cfg(procmacro2_semver_exempt)] #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] - pub fn def_site() -> Self { + pub fn def_site() -> Span { Span::_new(imp::Span::def_site()) } @@ -470,7 +439,7 @@ impl Span { /// The original source file into which this span points. /// /// This method is semver exempt and not exposed by default. - #[cfg(all(procmacro2_semver_exempt, any(not(wrap_proc_macro), super_unstable)))] + #[cfg(procmacro2_semver_exempt)] #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] pub fn source_file(&self) -> SourceFile { SourceFile::_new(self.inner.source_file()) @@ -680,7 +649,7 @@ impl Group { /// This constructor will set the span for this group to /// `Span::call_site()`. To change the span you can use the `set_span` /// method below. - pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self { + pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group { Group { inner: imp::Group::new(delimiter, stream.inner), } @@ -737,7 +706,7 @@ impl Group { /// by this group, but rather it will only set the span of the delimiter /// tokens at the level of the `Group`. pub fn set_span(&mut self, span: Span) { - self.inner.set_span(span.inner); + self.inner.set_span(span.inner) } } @@ -788,7 +757,7 @@ impl Punct { /// /// The returned `Punct` will have the default span of `Span::call_site()` /// which can be further configured with the `set_span` method below. - pub fn new(ch: char, spacing: Spacing) -> Self { + pub fn new(ch: char, spacing: Spacing) -> Punct { Punct { ch, spacing, @@ -910,7 +879,7 @@ pub struct Ident { } impl Ident { - fn _new(inner: imp::Ident) -> Self { + fn _new(inner: imp::Ident) -> Ident { Ident { inner, _marker: Marker, @@ -948,7 +917,7 @@ impl Ident { /// style="padding-right:0;">syn::parse_str</code></a><code /// style="padding-left:0;">::<Ident></code> /// rather than `Ident::new`. - pub fn new(string: &str, span: Span) -> Self { + pub fn new(string: &str, span: Span) -> Ident { Ident::_new(imp::Ident::new(string, span.inner)) } @@ -957,11 +926,11 @@ impl Ident { /// This method is semver exempt and not exposed by default. #[cfg(procmacro2_semver_exempt)] #[cfg_attr(doc_cfg, doc(cfg(procmacro2_semver_exempt)))] - pub fn new_raw(string: &str, span: Span) -> Self { + pub fn new_raw(string: &str, span: Span) -> Ident { Ident::_new_raw(string, span) } - fn _new_raw(string: &str, span: Span) -> Self { + fn _new_raw(string: &str, span: Span) -> Ident { Ident::_new(imp::Ident::new_raw(string, span.inner)) } @@ -1008,7 +977,7 @@ impl Ord for Ident { impl Hash for Ident { fn hash<H: Hasher>(&self, hasher: &mut H) { - self.to_string().hash(hasher); + self.to_string().hash(hasher) } } @@ -1079,14 +1048,14 @@ macro_rules! unsuffixed_int_literals { } impl Literal { - fn _new(inner: imp::Literal) -> Self { + fn _new(inner: imp::Literal) -> Literal { Literal { inner, _marker: Marker, } } - fn _new_stable(inner: fallback::Literal) -> Self { + fn _new_stable(inner: fallback::Literal) -> Literal { Literal { inner: inner.into(), _marker: Marker, @@ -1232,26 +1201,6 @@ impl Literal { pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> { self.inner.subspan(range).map(Span::_new) } - - // Intended for the `quote!` macro to use when constructing a proc-macro2 - // token out of a macro_rules $:literal token, which is already known to be - // a valid literal. This avoids reparsing/validating the literal's string - // representation. This is not public API other than for quote. - #[doc(hidden)] - pub unsafe fn from_str_unchecked(repr: &str) -> Self { - Literal::_new(imp::Literal::from_str_unchecked(repr)) - } -} - -impl FromStr for Literal { - type Err = LexError; - - fn from_str(repr: &str) -> Result<Self, LexError> { - repr.parse().map(Literal::_new).map_err(|inner| LexError { - inner, - _marker: Marker, - }) - } } impl Debug for Literal { diff --git a/src/parse.rs b/src/parse.rs index f77213a..e5caed8 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -59,7 +59,7 @@ impl<'a> Cursor<'a> { } } -pub(crate) struct Reject; +struct Reject; type PResult<'a, O> = Result<(Cursor<'a>, O), Reject>; fn skip_whitespace(input: Cursor) -> Cursor { @@ -168,7 +168,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> { let first = match input.bytes().next() { Some(first) => first, None => match stack.last() { - None => return Ok(TokenStream::from(trees)), + None => return Ok(TokenStream { inner: trees }), #[cfg(span_locations)] Some((lo, _frame)) => { return Err(LexError { @@ -209,7 +209,7 @@ pub(crate) fn token_stream(mut input: Cursor) -> Result<TokenStream, LexError> { return Err(lex_error(input)); } input = input.advance(1); - let mut g = Group::new(open_delimiter, TokenStream::from(trees)); + let mut g = Group::new(open_delimiter, TokenStream { inner: trees }); g.set_span(Span { #[cfg(span_locations)] lo, @@ -310,7 +310,7 @@ fn ident_not_raw(input: Cursor) -> PResult<&str> { Ok((input.advance(end), &input.rest[..end])) } -pub(crate) fn literal(input: Cursor) -> PResult<Literal> { +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()))) @@ -461,7 +461,7 @@ fn cooked_byte_string(mut input: Cursor) -> Result<Cursor, Reject> { fn raw_string(input: Cursor) -> Result<Cursor, Reject> { let mut chars = input.char_indices(); let mut n = 0; - for (i, ch) in &mut chars { + while let Some((i, ch)) = chars.next() { match ch { '"' => { n = i; @@ -621,7 +621,8 @@ fn float_digits(input: Cursor) -> Result<Cursor, Reject> { chars.next(); if chars .peek() - .map_or(false, |&ch| ch == '.' || is_ident_start(ch)) + .map(|&ch| ch == '.' || is_ident_start(ch)) + .unwrap_or(false) { return Err(Reject); } @@ -816,12 +817,12 @@ fn doc_comment(input: Cursor) -> PResult<Vec<TokenTree>> { TokenTree::Punct(Punct::new('=', Spacing::Alone)), TokenTree::Literal(crate::Literal::string(comment)), ]; - for tt in &mut stream { + for tt in stream.iter_mut() { tt.set_span(span); } - let group = Group::new(Delimiter::Bracket, TokenStream::from(stream)); + let group = Group::new(Delimiter::Bracket, stream.into_iter().collect()); trees.push(crate::Group::_new_stable(group).into()); - for tt in &mut trees { + for tt in trees.iter_mut() { tt.set_span(span); } Ok((rest, trees)) diff --git a/src/wrapper.rs b/src/wrapper.rs index 2ba76cc..24d86e8 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -29,14 +29,6 @@ pub(crate) enum LexError { Fallback(fallback::LexError), } -impl LexError { - fn call_site() -> Self { - LexError::Fallback(fallback::LexError { - span: fallback::Span::call_site(), - }) - } -} - fn mismatch() -> ! { panic!("stable/nightly mismatch") } @@ -69,7 +61,7 @@ impl DeferredTokenStream { } impl TokenStream { - pub fn new() -> Self { + pub fn new() -> TokenStream { if inside_proc_macro() { TokenStream::Compiler(DeferredTokenStream::new(proc_macro::TokenStream::new())) } else { @@ -116,7 +108,11 @@ impl FromStr for TokenStream { // Work around https://github.com/rust-lang/rust/issues/58736. fn proc_macro_parse(src: &str) -> Result<proc_macro::TokenStream, LexError> { let result = panic::catch_unwind(|| src.parse().map_err(LexError::Compiler)); - result.unwrap_or_else(|_| Err(LexError::call_site())) + result.unwrap_or_else(|_| { + Err(LexError::Fallback(fallback::LexError { + span: fallback::Span::call_site(), + })) + }) } impl Display for TokenStream { @@ -284,9 +280,9 @@ impl Debug for LexError { impl Display for LexError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - #[cfg(not(no_lexerror_display))] + #[cfg(lexerror_display)] LexError::Compiler(e) => Display::fmt(e, f), - #[cfg(no_lexerror_display)] + #[cfg(not(lexerror_display))] LexError::Compiler(_e) => Display::fmt( &fallback::LexError { span: fallback::Span::call_site(), @@ -408,7 +404,7 @@ pub(crate) enum Span { } impl Span { - pub fn call_site() -> Self { + pub fn call_site() -> Span { if inside_proc_macro() { Span::Compiler(proc_macro::Span::call_site()) } else { @@ -416,8 +412,8 @@ impl Span { } } - #[cfg(not(no_hygiene))] - pub fn mixed_site() -> Self { + #[cfg(hygiene)] + pub fn mixed_site() -> Span { if inside_proc_macro() { Span::Compiler(proc_macro::Span::mixed_site()) } else { @@ -426,7 +422,7 @@ impl Span { } #[cfg(super_unstable)] - pub fn def_site() -> Self { + pub fn def_site() -> Span { if inside_proc_macro() { Span::Compiler(proc_macro::Span::def_site()) } else { @@ -436,11 +432,11 @@ impl Span { pub fn resolved_at(&self, other: Span) -> Span { match (self, other) { - #[cfg(not(no_hygiene))] + #[cfg(hygiene)] (Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.resolved_at(b)), // Name resolution affects semantics, but location is only cosmetic - #[cfg(no_hygiene)] + #[cfg(not(hygiene))] (Span::Compiler(_), Span::Compiler(_)) => other, (Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.resolved_at(b)), @@ -450,11 +446,11 @@ impl Span { pub fn located_at(&self, other: Span) -> Span { match (self, other) { - #[cfg(not(no_hygiene))] + #[cfg(hygiene)] (Span::Compiler(a), Span::Compiler(b)) => Span::Compiler(a.located_at(b)), // Name resolution affects semantics, but location is only cosmetic - #[cfg(no_hygiene)] + #[cfg(not(hygiene))] (Span::Compiler(_), Span::Compiler(_)) => *self, (Span::Fallback(a), Span::Fallback(b)) => Span::Fallback(a.located_at(b)), @@ -575,7 +571,7 @@ pub(crate) enum Group { } impl Group { - pub fn new(delimiter: Delimiter, stream: TokenStream) -> Self { + pub fn new(delimiter: Delimiter, stream: TokenStream) -> Group { match stream { TokenStream::Compiler(tts) => { let delimiter = match delimiter { @@ -620,9 +616,9 @@ impl Group { pub fn span_open(&self) -> Span { match self { - #[cfg(not(no_group_open_close))] + #[cfg(proc_macro_span)] Group::Compiler(g) => Span::Compiler(g.span_open()), - #[cfg(no_group_open_close)] + #[cfg(not(proc_macro_span))] Group::Compiler(g) => Span::Compiler(g.span()), Group::Fallback(g) => Span::Fallback(g.span_open()), } @@ -630,9 +626,9 @@ impl Group { pub fn span_close(&self) -> Span { match self { - #[cfg(not(no_group_open_close))] + #[cfg(proc_macro_span)] Group::Compiler(g) => Span::Compiler(g.span_close()), - #[cfg(no_group_open_close)] + #[cfg(not(proc_macro_span))] Group::Compiler(g) => Span::Compiler(g.span()), Group::Fallback(g) => Span::Fallback(g.span_close()), } @@ -685,14 +681,14 @@ pub(crate) enum Ident { } impl Ident { - pub fn new(string: &str, span: Span) -> Self { + pub fn new(string: &str, span: Span) -> Ident { match span { Span::Compiler(s) => Ident::Compiler(proc_macro::Ident::new(string, s)), Span::Fallback(s) => Ident::Fallback(fallback::Ident::new(string, s)), } } - pub fn new_raw(string: &str, span: Span) -> Self { + pub fn new_raw(string: &str, span: Span) -> Ident { match span { Span::Compiler(s) => { let p: proc_macro::TokenStream = string.parse().unwrap(); @@ -804,14 +800,6 @@ macro_rules! unsuffixed_integers { } impl Literal { - pub unsafe fn from_str_unchecked(repr: &str) -> Self { - if inside_proc_macro() { - Literal::Compiler(compiler_literal_from_str(repr).expect("invalid literal")) - } else { - Literal::Fallback(fallback::Literal::from_str_unchecked(repr)) - } - } - suffixed_numbers! { u8_suffixed => u8, u16_suffixed => u16, @@ -924,37 +912,6 @@ impl From<fallback::Literal> for Literal { } } -impl FromStr for Literal { - type Err = LexError; - - fn from_str(repr: &str) -> Result<Self, Self::Err> { - if inside_proc_macro() { - compiler_literal_from_str(repr).map(Literal::Compiler) - } else { - let literal = fallback::Literal::from_str(repr)?; - Ok(Literal::Fallback(literal)) - } - } -} - -fn compiler_literal_from_str(repr: &str) -> Result<proc_macro::Literal, LexError> { - #[cfg(not(no_literal_from_str))] - { - proc_macro::Literal::from_str(repr).map_err(LexError::Compiler) - } - #[cfg(no_literal_from_str)] - { - let tokens = proc_macro_parse(repr)?; - let mut iter = tokens.into_iter(); - if let (Some(proc_macro::TokenTree::Literal(literal)), None) = (iter.next(), iter.next()) { - if literal.to_string().len() == repr.len() { - return Ok(literal); - } - } - Err(LexError::call_site()) - } -} - impl Display for Literal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/tests/comments.rs b/tests/comments.rs index 7174108..708cccb 100644 --- a/tests/comments.rs +++ b/tests/comments.rs @@ -1,16 +1,16 @@ use proc_macro2::{Delimiter, Literal, Spacing, TokenStream, TokenTree}; // #[doc = "..."] -> "..." -fn lit_of_outer_doc_comment(tokens: &TokenStream) -> Literal { +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 { +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 { +fn lit_of_doc_comment(tokens: TokenStream, inner: bool) -> Literal { let mut iter = tokens.clone().into_iter(); match iter.next().unwrap() { TokenTree::Punct(punct) => { @@ -71,30 +71,30 @@ fn incomplete() { #[test] fn lit() { let stream = "/// doc".parse::<TokenStream>().unwrap(); - let lit = lit_of_outer_doc_comment(&stream); + 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); + 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); + 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); + 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); + 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); + let lit = lit_of_outer_doc_comment(stream); assert_eq!(lit.to_string(), "\"\\r\\n\""); "///\r".parse::<TokenStream>().unwrap_err(); diff --git a/tests/marker.rs b/tests/marker.rs index 4fb2beb..70e5767 100644 --- a/tests/marker.rs +++ b/tests/marker.rs @@ -1,6 +1,4 @@ -use proc_macro2::{ - Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree, -}; +use proc_macro2::*; macro_rules! assert_impl { ($ty:ident is $($marker:ident) and +) => { @@ -53,7 +51,7 @@ assert_impl!(TokenTree is not Send or Sync); #[cfg(procmacro2_semver_exempt)] mod semver_exempt { - use proc_macro2::{LineColumn, SourceFile}; + use super::*; assert_impl!(LineColumn is Send and Sync); @@ -62,11 +60,7 @@ mod semver_exempt { #[cfg(not(no_libprocmacro_unwind_safe))] 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 super::*; use std::panic::{RefUnwindSafe, UnwindSafe}; macro_rules! assert_unwind_safe { diff --git a/tests/test.rs b/tests/test.rs index ab82390..6d0a93e 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,5 +1,3 @@ -#![allow(clippy::non_ascii_literal)] - use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; use std::panic; use std::str::{self, FromStr}; @@ -166,33 +164,12 @@ fn literal_iter_negative() { } #[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 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(); + let s2 = s.to_string().parse::<TokenStream>().unwrap().to_string(); assert_eq!(s, s2); } roundtrip("a"); @@ -488,7 +465,7 @@ TokenStream [ #[test] fn default_tokenstream_is_empty() { - let default_token_stream = <TokenStream as Default>::default(); + let default_token_stream: TokenStream = Default::default(); assert!(default_token_stream.is_empty()); } diff --git a/tests/test_fmt.rs b/tests/test_fmt.rs index 93dd19e..99a0aee 100644 --- a/tests/test_fmt.rs +++ b/tests/test_fmt.rs @@ -1,5 +1,3 @@ -#![allow(clippy::from_iter_instead_of_collect)] - use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; use std::iter::{self, FromIterator}; @@ -14,7 +12,7 @@ fn test_fmt_group() { 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); + let none_nonempty = Group::new(Delimiter::None, inner.clone()); // Matches libproc_macro. assert_eq!("()", parens_empty.to_string()); |