Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lazy_static and lazycell dependencies #2817

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ jobs:
with:
# MSRV below is documented in Cargo.toml and README.md, please update those if you
# change this.
toolchain: 1.60.0
toolchain: 1.70.0

- name: Test lib with msrv
run: cargo +1.60.0 test --package bindgen
run: cargo +1.70.0 test --package bindgen

- name: Install msrv for cli
uses: dtolnay/rust-toolchain@master
with:
# MSRV below is documented in Cargo.toml and README.md, please update those if you
# change this.
toolchain: 1.64.0
toolchain: 1.70.0

- name: Test cli with msrv
run: cargo +1.64.0 build --package bindgen-cli
run: cargo +1.70.0 build --package bindgen-cli

minimal:
runs-on: ubuntu-latest
Expand Down
15 changes: 0 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ extern "C" {

## MSRV

The `bindgen` minimum supported Rust version is **1.60.0**.
The `bindgen` minimum supported Rust version is **1.70.0**.

The `bindgen-cli` minimum supported Rust version is **1.64.0**.
The `bindgen-cli` minimum supported Rust version is **1.70.0**.

No MSRV bump policy has been established yet, so MSRV may increase in any release.

Expand Down
2 changes: 1 addition & 1 deletion bindgen-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ documentation = "https://docs.rs/bindgen"
homepage = "https://rust-lang.github.io/rust-bindgen/"
version = "0.69.4"
edition = "2018"
rust-version = "1.64.0"
rust-version = "1.70.0"

[[bin]]
path = "main.rs"
Expand Down
3 changes: 1 addition & 2 deletions bindgen-tests/tests/quickchecking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "quickchecking"
description = "Bindgen property tests with quickcheck. Generate random valid C code and pass it to the csmith/predicate.py script"
version = "0.0.0"
publish = false
rust-version = "1.64"
rust-version = "1.70"
edition = "2018"

[lib]
Expand All @@ -16,7 +16,6 @@ path = "src/bin.rs"

[dependencies]
clap = "4"
lazy_static = "1.0"
quickcheck = "1.0"
tempfile = "3"

Expand Down
8 changes: 1 addition & 7 deletions bindgen-tests/tests/quickchecking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
//! println!("{}", header);
//! }
//! ```
//!
#![deny(missing_docs)]
#[macro_use]
extern crate lazy_static;

use quickcheck::{Gen, QuickCheck, TestResult};
use std::error::Error;
Expand All @@ -38,10 +35,7 @@ struct Context {
}

// Initialize global context.
lazy_static! {
static ref CONTEXT: Mutex<Context> =
Mutex::new(Context { output_path: None });
}
static CONTEXT: Mutex<Context> = Mutex::new(Context { output_path: None });

// Passes fuzzed header to the `csmith-fuzzing/predicate.py` script, returns
// output of the associated command.
Expand Down
4 changes: 1 addition & 3 deletions bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ version = "0.69.4"
edition = "2018"
build = "build.rs"
# If you change this, also update README.md and msrv in .github/workflows/bindgen.yml
rust-version = "1.60.0"
rust-version = "1.70.0"

[lib]
name = "bindgen"
Expand All @@ -30,8 +30,6 @@ bitflags = "2.2.1"
cexpr = "0.6"
clang-sys = { version = "1", features = ["clang_6_0"] }
itertools = { version = ">=0.10,<0.13", default-features = false }
lazy_static = "1"
lazycell = "1"
log = { version = "0.4", optional = true }
prettyplease = { version = "0.2.7", optional = true, features = ["verbatim"] }
proc-macro2 = { version = "1", default-features = false }
Expand Down
9 changes: 2 additions & 7 deletions bindgen/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@ pub use crate::ir::int::IntKind;
use std::fmt;

/// An enum to allow ignoring parsing of macros.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum MacroParsingBehavior {
/// Ignore the macro, generating no code for it, or anything that depends on
/// it.
Ignore,
/// The default behavior bindgen would have otherwise.
#[default]
Default,
}

impl Default for MacroParsingBehavior {
fn default() -> Self {
MacroParsingBehavior::Default
}
}

/// A trait to allow configuring different kinds of types in different
/// situations.
pub trait ParseCallbacks: fmt::Debug {
Expand Down
15 changes: 8 additions & 7 deletions bindgen/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use std::hash::Hash;
use std::hash::Hasher;
use std::os::raw::{c_char, c_int, c_longlong, c_uint, c_ulong, c_ulonglong};
use std::sync::OnceLock;
use std::{mem, ptr, slice};

/// Type representing a clang attribute.
Expand Down Expand Up @@ -1528,13 +1529,13 @@
pub(crate) fn is_associated_type(&self) -> bool {
// This is terrible :(
fn hacky_parse_associated_type<S: AsRef<str>>(spelling: S) -> bool {
lazy_static! {
static ref ASSOC_TYPE_RE: regex::Regex = regex::Regex::new(
r"typename type\-parameter\-\d+\-\d+::.+"
)
.unwrap();
}
ASSOC_TYPE_RE.is_match(spelling.as_ref())
static ASSOC_TYPE_RE: OnceLock<regex::Regex> = OnceLock::new();
ASSOC_TYPE_RE
.get_or_init(|| {
regex::Regex::new(r"typename type\-parameter\-\d+\-\d+::.+")
.unwrap()
})
.is_match(spelling.as_ref())
}

self.kind() == CXType_Unexposed &&
Expand Down Expand Up @@ -2355,7 +2356,7 @@

if unsafe { clang_EvalResult_isUnsignedInt(self.x) } != 0 {
let value = unsafe { clang_EvalResult_getAsUnsigned(self.x) };
if value > i64::max_value() as c_ulonglong {

Check warning on line 2359 in bindgen/clang.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

usage of a legacy numeric method

Check warning on line 2359 in bindgen/clang.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

usage of a legacy numeric method
return None;
}

Expand All @@ -2363,10 +2364,10 @@
}

let value = unsafe { clang_EvalResult_getAsLongLong(self.x) };
if value > i64::max_value() as c_longlong {

Check warning on line 2367 in bindgen/clang.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

usage of a legacy numeric method

Check warning on line 2367 in bindgen/clang.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

usage of a legacy numeric method
return None;
}
if value < i64::min_value() as c_longlong {

Check warning on line 2370 in bindgen/clang.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

usage of a legacy numeric method

Check warning on line 2370 in bindgen/clang.rs

View workflow job for this annotation

GitHub Actions / rustfmt-clippy

usage of a legacy numeric method
return None;
}
#[allow(clippy::unnecessary_cast)]
Expand Down
29 changes: 7 additions & 22 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2608,7 +2608,7 @@ impl CodeGenerator for CompInfo {
ctx,
&canonical_ident,
flex_inner_ty,
&*generic_param_names,
&generic_param_names,
&impl_generics_labels,
));
}
Expand Down Expand Up @@ -3010,7 +3010,7 @@ impl Method {
}

/// A helper type that represents different enum variations.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum EnumVariation {
/// The code for this enum will use a Rust enum. Note that creating this in unsafe code
/// (including FFI) with an invalid value will invoke undefined behaviour, whether or not
Expand All @@ -3027,6 +3027,7 @@ pub enum EnumVariation {
is_global: bool,
},
/// The code for this enum will use consts
#[default]
Consts,
/// The code for this enum will use a module containing consts
ModuleConsts,
Expand All @@ -3044,12 +3045,6 @@ impl EnumVariation {
}
}

impl Default for EnumVariation {
fn default() -> EnumVariation {
EnumVariation::Consts
}
}

impl fmt::Display for EnumVariation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
Expand Down Expand Up @@ -3757,11 +3752,12 @@ impl CodeGenerator for Enum {
}

/// Enum for the default type of macro constants.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum MacroTypeVariation {
/// Use i32 or i64
Signed,
/// Use u32 or u64
#[default]
Unsigned,
}

Expand All @@ -3775,12 +3771,6 @@ impl fmt::Display for MacroTypeVariation {
}
}

impl Default for MacroTypeVariation {
fn default() -> MacroTypeVariation {
MacroTypeVariation::Unsigned
}
}

impl std::str::FromStr for MacroTypeVariation {
type Err = std::io::Error;

Expand All @@ -3801,9 +3791,10 @@ impl std::str::FromStr for MacroTypeVariation {
}

/// Enum for how aliases should be translated.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Default)]
pub enum AliasVariation {
/// Convert to regular Rust alias
#[default]
TypeAlias,
/// Create a new type by wrapping the old type in a struct and using #[repr(transparent)]
NewType,
Expand All @@ -3823,12 +3814,6 @@ impl fmt::Display for AliasVariation {
}
}

impl Default for AliasVariation {
fn default() -> AliasVariation {
AliasVariation::TypeAlias
}
}

impl std::str::FromStr for AliasVariation {
type Err = std::io::Error;

Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/analysis/has_vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use std::cmp;
use std::ops;

/// The result of the `HasVtableAnalysis` for an individual item.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub(crate) enum HasVtableResult {
/// The item does not have a vtable pointer.
#[default]
No,

/// The item has a vtable and the actual vtable pointer is within this item.
Expand All @@ -22,12 +23,6 @@ pub(crate) enum HasVtableResult {
BaseHasVtable,
}

impl Default for HasVtableResult {
fn default() -> Self {
HasVtableResult::No
}
}

impl HasVtableResult {
/// Take the least upper bound of `self` and `rhs`.
pub(crate) fn join(self, rhs: Self) -> Self {
Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,17 @@ pub(crate) trait MonotoneFramework: Sized + fmt::Debug {

/// Whether an analysis's `constrain` function modified the incremental results
/// or not.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Default)]
pub(crate) enum ConstrainResult {
/// The incremental results were updated, and the fix-point computation
/// should continue.
Changed,

/// The incremental results were not updated.
#[default]
Same,
}

impl Default for ConstrainResult {
fn default() -> Self {
ConstrainResult::Same
}
}

impl ops::BitOr for ConstrainResult {
type Output = Self;

Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/analysis/sizedness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ use std::{cmp, ops};
///
/// We initially assume that all types are `ZeroSized` and then update our
/// understanding as we learn more about each type.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default)]
pub(crate) enum SizednessResult {
/// The type is zero-sized.
///
/// This means that if it is a C++ type, and is not being used as a base
/// member, then we must add an `_address` byte to enforce the
/// unique-address-per-distinct-object-instance rule.
#[default]
ZeroSized,

/// Whether this type is zero-sized or not depends on whether a type
Expand Down Expand Up @@ -62,12 +63,6 @@ pub(crate) enum SizednessResult {
NonZeroSized,
}

impl Default for SizednessResult {
fn default() -> Self {
SizednessResult::ZeroSized
}
}

impl SizednessResult {
/// Take the least upper bound of `self` and `rhs`.
pub(crate) fn join(self, rhs: Self) -> Self {
Expand Down
9 changes: 2 additions & 7 deletions bindgen/ir/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use std::str::FromStr;
use crate::clang;

/// What kind of visibility modifier should be used for a struct or field?
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug)]
#[derive(Copy, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Default)]
pub enum FieldVisibilityKind {
/// Fields are marked as private, i.e., struct Foo {bar: bool}
Private,
/// Fields are marked as crate public, i.e., struct Foo {pub(crate) bar: bool}
PublicCrate,
/// Fields are marked as public, i.e., struct Foo {pub bar: bool}
#[default]
Public,
}

Expand Down Expand Up @@ -44,12 +45,6 @@ impl std::fmt::Display for FieldVisibilityKind {
}
}

impl Default for FieldVisibilityKind {
fn default() -> Self {
FieldVisibilityKind::Public
}
}

/// What kind of accessor should we provide for a field?
#[derive(Copy, PartialEq, Eq, Clone, Debug)]
pub(crate) enum FieldAccessorKind {
Expand Down
Loading
Loading