From 3cd20a686c6afd2d573b2e00be613a45d0611627 Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Mon, 8 Jun 2026 21:46:47 +0800 Subject: [PATCH 1/3] Implement core::error::Error for ParseError --- src/parse_error.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/parse_error.rs b/src/parse_error.rs index 03ca4ae..faf3ff6 100644 --- a/src/parse_error.rs +++ b/src/parse_error.rs @@ -30,5 +30,4 @@ impl fmt::Display for ParseError { } } -#[cfg(feature = "std")] -impl std::error::Error for ParseError {} +impl core::error::Error for ParseError {} From 1e78c4ced558583f1fa30502d81e06b60f607077 Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Tue, 9 Jun 2026 02:12:15 +0800 Subject: [PATCH 2/3] Update build.rs --- build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 3375d89..e416578 100644 --- a/build.rs +++ b/build.rs @@ -52,12 +52,12 @@ fn main() { Triple::from_str(&target).unwrap_or_else(|_| panic!("Invalid target name: '{}'", target)); let out = File::create(out_dir.join("host.rs")).expect("error creating host.rs"); write_host_rs(out, triple).expect("error writing host.rs"); - if using_1_40() { - println!("cargo:rustc-cfg=feature=\"rust_1_40\""); + if using_1_81() { + println!("cargo:rustc-cfg=feature=\"rust_1_81\""); } } -fn using_1_40() -> bool { +fn using_1_81() -> bool { match (|| { let rustc = env::var_os("RUSTC").unwrap(); let output = Command::new(rustc).arg("--version").output().ok()?; @@ -75,7 +75,7 @@ fn using_1_40() -> bool { .parse::() .ok() })() { - Some(version) => version >= 40, + Some(version) => version >= 81, None => true, // assume we're using an up-to-date compiler } } From 1480f3d41fa2bbb00cebf3b6a0d0bdeb018c28ae Mon Sep 17 00:00:00 2001 From: Steve Fan <29133953+stevefan1999-personal@users.noreply.github.com> Date: Tue, 9 Jun 2026 02:16:59 +0800 Subject: [PATCH 3/3] remove the feature; use rust-version for minimal version guarantee --- Cargo.toml | 4 +--- build.rs | 26 -------------------------- src/data_model.rs | 2 +- src/targets.rs | 30 +++++++++++++++--------------- src/triple.rs | 2 +- 5 files changed, 18 insertions(+), 46 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9726763..33c2b64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ license = "Apache-2.0 WITH LLVM-exception" repository = "https://github.com/bytecodealliance/target-lexicon" edition = "2018" include = ["Cargo.toml", "README.md", "LICENSE", "build.rs", "src/**/*.rs"] +rust-version = "1.81" [dependencies] serde = { version = "1.0", optional = true } @@ -29,6 +30,3 @@ arch_z80 = [] [badges] maintenance = { status = "passively-maintained" } - -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(feature, values("rust_1_40", "cargo-clippy"))'] } diff --git a/build.rs b/build.rs index e416578..b6852bd 100644 --- a/build.rs +++ b/build.rs @@ -52,32 +52,6 @@ fn main() { Triple::from_str(&target).unwrap_or_else(|_| panic!("Invalid target name: '{}'", target)); let out = File::create(out_dir.join("host.rs")).expect("error creating host.rs"); write_host_rs(out, triple).expect("error writing host.rs"); - if using_1_81() { - println!("cargo:rustc-cfg=feature=\"rust_1_81\""); - } -} - -fn using_1_81() -> bool { - match (|| { - let rustc = env::var_os("RUSTC").unwrap(); - let output = Command::new(rustc).arg("--version").output().ok()?; - let stdout = if output.status.success() { - output.stdout - } else { - return None; - }; - std::str::from_utf8(&stdout) - .ok()? - .split(' ') - .nth(1)? - .split('.') - .nth(1)? - .parse::() - .ok() - })() { - Some(version) => version >= 81, - None => true, // assume we're using an up-to-date compiler - } } fn write_host_rs(mut out: File, triple: Triple) -> io::Result<()> { diff --git a/src/data_model.rs b/src/data_model.rs index 0954add..106a8b2 100644 --- a/src/data_model.rs +++ b/src/data_model.rs @@ -40,7 +40,7 @@ impl Size { /// /// See also https://en.cppreference.com/w/c/language/arithmetic_types #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] pub enum CDataModel { /// The data model used most commonly on Win16. `long` and `pointer` are 32 bits. LP32, diff --git a/src/targets.rs b/src/targets.rs index 2f4827b..3933caa 100644 --- a/src/targets.rs +++ b/src/targets.rs @@ -11,7 +11,7 @@ use core::str::FromStr; /// The "architecture" field, which in some cases also specifies a specific /// subarchitecture. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Architecture { @@ -60,7 +60,7 @@ pub enum Architecture { Z80(Z80Architecture), } -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum ArmArchitecture { @@ -110,7 +110,7 @@ pub enum ArmArchitecture { Thumbv8mMain, } -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Aarch64Architecture { @@ -123,7 +123,7 @@ pub enum Aarch64Architecture { Arm64_32, } -// #[cfg_attr(feature = "rust_1_40", non_exhaustive)] +// #[non_exhaustive] // #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] // #[allow(missing_docs)] // pub enum ArmFpu { @@ -401,7 +401,7 @@ impl Aarch64Architecture { } } -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum CleverArchitecture { @@ -422,7 +422,7 @@ impl CleverArchitecture { } /// An enum for all 32-bit RISC-V architectures. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Riscv32Architecture { @@ -455,7 +455,7 @@ impl Riscv32Architecture { } /// An enum for all 64-bit RISC-V architectures. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Riscv64Architecture { @@ -480,7 +480,7 @@ impl Riscv64Architecture { } /// An enum for all 32-bit x86 architectures. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum X86_32Architecture { @@ -503,7 +503,7 @@ impl X86_32Architecture { } /// An enum for all 32-bit MIPS architectures (not just "MIPS32"). -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Mips32Architecture { @@ -528,7 +528,7 @@ impl Mips32Architecture { } /// An enum for all 64-bit MIPS architectures (not just "MIPS64"). -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Mips64Architecture { @@ -553,7 +553,7 @@ impl Mips64Architecture { } #[cfg(feature = "arch_z80")] -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Z80Architecture { @@ -624,7 +624,7 @@ impl Hash for CustomVendor { /// The "vendor" field, which in practice is little more than an arbitrary /// modifier. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Vendor { @@ -699,7 +699,7 @@ pub struct DeploymentTarget { /// LLVM's Apple triples may optionally include the [deployment target]. /// /// [deployment target]: DeploymentTarget -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum OperatingSystem { @@ -845,7 +845,7 @@ impl OperatingSystem { /// The "environment" field, which specifies an ABI environment on top of the /// operating system. In many configurations, this field is omitted, and the /// environment is implied by the operating system. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum Environment { @@ -933,7 +933,7 @@ impl Environment { /// The "binary format" field, which is usually omitted, and the binary format /// is implied by the other fields. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[allow(missing_docs)] pub enum BinaryFormat { diff --git a/src/triple.rs b/src/triple.rs index d92ea67..a1103fe 100644 --- a/src/triple.rs +++ b/src/triple.rs @@ -52,7 +52,7 @@ impl PointerWidth { /// The calling convention, which specifies things like which registers are /// used for passing arguments, which registers are callee-saved, and so on. -#[cfg_attr(feature = "rust_1_40", non_exhaustive)] +#[non_exhaustive] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum CallingConvention { /// "System V", which is used on most Unix-like platfoms. Note that the