-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
573 additions
and
142 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,46 @@ | ||
use std::sync::OnceLock; | ||
use std::{process::Command, sync::OnceLock}; | ||
|
||
fn rust_version_minor() -> u32 { | ||
static VERSION_MINOR: OnceLock<u32> = OnceLock::new(); | ||
*VERSION_MINOR.get_or_init(|| { | ||
crate::input::cargo_pkg_rust_version() | ||
.split('.') | ||
.nth(1) | ||
.unwrap_or("70") | ||
// assume build-rs's MSRV if none specified for the current package | ||
.unwrap_or(env!("CARGO_PKG_RUST_VERSION").split('.').nth(1).unwrap()) | ||
.parse() | ||
.unwrap() | ||
}) | ||
} | ||
|
||
fn cargo_version_minor() -> u32 { | ||
static VERSION_MINOR: OnceLock<u32> = OnceLock::new(); | ||
*VERSION_MINOR.get_or_init(|| { | ||
let out = Command::new(crate::input::cargo()) | ||
.arg("-V") | ||
.output() | ||
.expect("running `cargo -V` should succeed"); | ||
assert!(out.status.success(), "running `cargo -V` should succeed"); | ||
|
||
// > cargo -V # example output | ||
// cargo 1.82.0 (8f40fc59f 2024-08-21) | ||
|
||
String::from_utf8(out.stdout).expect("`cargo -V` should output valid UTF-8") | ||
["cargo 1.".len()..] | ||
.split('.') | ||
.next() | ||
.expect("`cargo -V` format should be stable") | ||
.parse() | ||
.unwrap() | ||
}) | ||
} | ||
|
||
pub(crate) fn double_colon_directives() -> bool { | ||
// cargo errors on `cargo::` directives with insufficient package.rust-version | ||
rust_version_minor() >= 77 | ||
} | ||
|
||
pub(crate) fn check_cfg() -> bool { | ||
// emit check-cfg if the toolchain being used supports it | ||
cargo_version_minor() >= 80 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use unicode_ident::{is_xid_continue, is_xid_start}; | ||
|
||
pub(crate) fn is_feature_name(s: &str) -> bool { | ||
s.chars() | ||
.all(|ch| is_xid_continue(ch) || matches!(ch, '-' | '+' | '.')) | ||
} | ||
|
||
pub(crate) fn is_ident(s: &str) -> bool { | ||
let mut cs = s.chars(); | ||
cs.next() | ||
.is_some_and(|ch| is_xid_start(ch) || matches!(ch, '_')) | ||
&& cs.all(is_xid_continue) | ||
} | ||
|
||
pub(crate) fn is_ascii_ident(s: &str) -> bool { | ||
let mut cs = s.chars(); | ||
cs.next() | ||
.is_some_and(|ch| ch.is_ascii_alphabetic() || matches!(ch, '_')) | ||
&& cs.all(|ch| ch.is_ascii_alphanumeric() || matches!(ch, '_')) | ||
} | ||
|
||
pub(crate) fn is_crate_name(s: &str) -> bool { | ||
let mut cs = s.chars(); | ||
cs.next() | ||
.is_some_and(|ch| is_xid_start(ch) || matches!(ch, '-' | '_')) | ||
&& cs.all(|ch| is_xid_continue(ch) || matches!(ch, '-')) | ||
} |
Oops, something went wrong.