+33
| use std::env; | ||
| use std::process::Command; | ||
| use std::str; | ||
| fn main() { | ||
| println!("cargo:rerun-if-changed=build.rs"); | ||
| let version = match rustc_version() { | ||
| Some(version) => version, | ||
| None => return, | ||
| }; | ||
| if version.minor < 54 { | ||
| // https://github.com/rust-lang/rust/pull/84717 | ||
| println!("cargo:rustc-cfg=no_literal_fromstr"); | ||
| } | ||
| } | ||
| struct RustcVersion { | ||
| minor: u32, | ||
| } | ||
| fn rustc_version() -> Option<RustcVersion> { | ||
| let rustc = env::var_os("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; | ||
| } | ||
| let minor = pieces.next()?.parse().ok()?; | ||
| Some(RustcVersion { minor }) | ||
| } |
| { | ||
| "git": { | ||
| "sha1": "2839b84393cada03d60c849bd48ba99c5e8f01f9" | ||
| "sha1": "188ceccacedd20ff9ecc4037d43162f39a41f7bf" | ||
| }, | ||
| "path_in_vcs": "" | ||
| } |
@@ -8,2 +8,5 @@ name: CI | ||
| permissions: | ||
| contents: read | ||
| env: | ||
@@ -19,3 +22,4 @@ RUSTFLAGS: -Dwarnings | ||
| matrix: | ||
| rust: [nightly, beta, stable, 1.46.0] | ||
| rust: [nightly, beta, stable, 1.56.0] | ||
| timeout-minutes: 45 | ||
| steps: | ||
@@ -28,13 +32,6 @@ - uses: actions/checkout@v3 | ||
| mintest: | ||
| name: Rust 1.36.0 | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: dtolnay/rust-toolchain@1.36.0 | ||
| - run: cargo test --test test_item | ||
| msrv: | ||
| name: Rust 1.31.0 | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 45 | ||
| steps: | ||
@@ -48,2 +45,3 @@ - uses: actions/checkout@v3 | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 45 | ||
| steps: | ||
@@ -59,2 +57,3 @@ - uses: actions/checkout@v3 | ||
| if: github.event_name != 'pull_request' | ||
| timeout-minutes: 45 | ||
| steps: | ||
@@ -68,2 +67,3 @@ - uses: actions/checkout@v3 | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 45 | ||
| steps: | ||
@@ -80,2 +80,3 @@ - uses: actions/checkout@v3 | ||
| if: github.event_name != 'pull_request' | ||
| timeout-minutes: 45 | ||
| steps: | ||
@@ -82,0 +83,0 @@ - uses: actions/checkout@v3 |
+1
-1
@@ -16,3 +16,3 @@ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO | ||
| name = "paste" | ||
| version = "1.0.9" | ||
| version = "1.0.10" | ||
| authors = ["David Tolnay <dtolnay@gmail.com>"] | ||
@@ -19,0 +19,0 @@ description = "Macros for all your token pasting needs" |
+20
-0
@@ -414,2 +414,22 @@ //! [![github]](https://github.com/dtolnay/paste) [![crates-io]](https://crates.io/crates/paste) [![docs-rs]](https://docs.rs/paste) | ||
| #[cfg(not(no_literal_fromstr))] | ||
| { | ||
| use proc_macro::{LexError, Literal}; | ||
| use std::str::FromStr; | ||
| if pasted.starts_with(|ch: char| ch.is_ascii_digit()) { | ||
| let literal = match panic::catch_unwind(|| Literal::from_str(&pasted)) { | ||
| Ok(Ok(literal)) => TokenTree::Literal(literal), | ||
| Ok(Err(LexError { .. })) | Err(_) => { | ||
| return Err(Error::new( | ||
| span, | ||
| &format!("`{:?}` is not a valid literal", pasted), | ||
| )); | ||
| } | ||
| }; | ||
| tokens.extend(iter::once(literal)); | ||
| return Ok(tokens); | ||
| } | ||
| } | ||
| if pasted.starts_with('\'') { | ||
@@ -416,0 +436,0 @@ let mut apostrophe = TokenTree::Punct(Punct::new('\'', Spacing::Joint)); |
+12
-1
@@ -29,3 +29,3 @@ use paste::paste; | ||
| #[test] | ||
| fn test_literals() { | ||
| fn test_literal_to_identifier() { | ||
| const CONST0: &str = "const0"; | ||
@@ -50,2 +50,13 @@ | ||
| #[test] | ||
| fn test_literal_suffix() { | ||
| macro_rules! literal { | ||
| ($bit:tt) => { | ||
| paste!([<1_u $bit>]) | ||
| }; | ||
| } | ||
| assert_eq!(literal!(32), 1); | ||
| } | ||
| #[test] | ||
| fn test_underscore() { | ||
@@ -52,0 +63,0 @@ paste! { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet