Bug 1841878 - Upgrade minidump-common to latest trunk. r=gsvelto,supply-chain-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D182815
This commit is contained in:
Mike Hommey 2023-07-24 20:18:53 +00:00
parent 74033863ce
commit e7516e7935
29 changed files with 284 additions and 761 deletions

View File

@ -115,6 +115,11 @@ git = "https://github.com/rust-minidump/minidump-writer.git"
rev = "a15bd5cab6a3de251c0c23264be14b977c0af09c"
replace-with = "vendored-sources"
[source."git+https://github.com/rust-minidump/rust-minidump?rev=87a29fba5e19cfae5ebf73a57ba31504a3872545"]
git = "https://github.com/rust-minidump/rust-minidump"
rev = "87a29fba5e19cfae5ebf73a57ba31504a3872545"
replace-with = "vendored-sources"
# Take advantage of the fact that cargo will treat lines starting with #
# as comments to add preprocessing directives. This file can thus by copied

22
Cargo.lock generated
View File

@ -1449,17 +1449,6 @@ dependencies = [
"packed_simd_2",
]
[[package]]
name = "enum-primitive-derive"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c375b9c5eadb68d0a6efee2999fef292f45854c3444c86f09d8ab086ba942b0e"
dependencies = [
"num-traits",
"quote",
"syn 1.0.107",
]
[[package]]
name = "enumset"
version = "1.1.2"
@ -3268,12 +3257,11 @@ dependencies = [
[[package]]
name = "minidump-common"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9114b15d86ee5e5c3e3b4d05821d17237adbf98c11dd07fc8f5a9b037a010ee5"
source = "git+https://github.com/rust-minidump/rust-minidump?rev=87a29fba5e19cfae5ebf73a57ba31504a3872545#87a29fba5e19cfae5ebf73a57ba31504a3872545"
dependencies = [
"bitflags 1.3.2",
"debugid",
"enum-primitive-derive",
"num-derive",
"num-traits",
"range-map",
"scroll",
@ -4889,13 +4877,13 @@ dependencies = [
[[package]]
name = "smart-default"
version = "0.6.0"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6"
checksum = "0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.107",
"syn 2.0.18",
]
[[package]]

View File

@ -187,6 +187,8 @@ packed_simd = { package = "packed_simd_2", git = "https://github.com/hsivonen/pa
midir = { git = "https://github.com/mozilla/midir.git", rev = "519e651241e867af3391db08f9ae6400bc023e18" }
# Avoid the dependency on chrono
minidump-writer = { git = "https://github.com/rust-minidump/minidump-writer.git", rev = "a15bd5cab6a3de251c0c23264be14b977c0af09c" }
# Bump some dependencies
minidump-common = { git = "https://github.com/rust-minidump/rust-minidump", rev = "87a29fba5e19cfae5ebf73a57ba31504a3872545" }
# warp 0.3.3 + https://github.com/seanmonstar/warp/pull/1007
warp = { git = "https://github.com/glandium/warp", rev = "4af45fae95bc98b0eba1ef0db17e1dac471bb23d" }

View File

@ -1942,6 +1942,11 @@ who = "Gabriele Svelto <gsvelto@mozilla.com>"
criteria = "safe-to-deploy"
delta = "0.15.2 -> 0.17.0"
[[audits.minidump-common]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "0.17.0 -> 0.17.0@git:87a29fba5e19cfae5ebf73a57ba31504a3872545"
[[audits.minidump-writer]]
who = "Gabriele Svelto <gsvelto@mozilla.com>"
criteria = "safe-to-deploy"
@ -2890,6 +2895,11 @@ who = "Gabriele Svelto <gsvelto@mozilla.com>"
criteria = "safe-to-deploy"
version = "0.6.0"
[[audits.smart-default]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "0.6.0 -> 0.7.1"
[[audits.socket2]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"

View File

@ -87,6 +87,10 @@ audit-as-crates-io = false
audit-as-crates-io = true
notes = "This is a pinned version of the upstream code, presumably to get a fix that hadn't been released yet. We should consider switching to the latest official release."
[policy."minidump-common:0.17.0@git:87a29fba5e19cfae5ebf73a57ba31504a3872545"]
audit-as-crates-io = true
notes = "Unreleased upstream."
[policy.minidump-writer]
audit-as-crates-io = true
notes = "Unreleased upstream."

View File

@ -1 +0,0 @@
{"files":{"CHANGELOG.md":"75976e8cf25b724bd1db6d176d3bd98ad19554a2d64a57aaffa1b14c64a55f7a","Cargo.toml":"3d3e91b17cb7b10e130d8db6ebcfff05f37d799a8d5039d67aca802998501ae7","LICENSE":"819e0555b295079201b0670bb3302855303bdbbcc739f3819b13e1b3d2ec03bb","README.md":"a0d505b975f799d351e539720d26ed64f2022adcc8257d63c343c32a0c88f5de","src/lib.rs":"3751e744d351269d320cdc58e7fefd0f4bf657ed3a09b0fca68205696a1927c0"},"package":"c375b9c5eadb68d0a6efee2999fef292f45854c3444c86f09d8ab086ba942b0e"}

View File

@ -1,33 +0,0 @@
# ChangeLog
## 0.2.2
### Changed
- Switch to using core instead of std for no-std support
## 0.2.1
### Added
- support TryFrom
## 0.2.0 (yanked)
### Changed
- Upgrade [syn](https://crates.io/crates/syn) and [quote](https://crates.io/crates/quote) to 1.0
- add a better diagnostic for the case where a discriminant isn't specified for
an enum
- Move unnecessary [`num-traits`](https://crates.io/crates/num-traits) dependency to `dev-dependencies`
- Migrate to Rust 2018 edition
## 0.1.2
### Changed
- drop `extern crate core;` as core is unused
## 0.1.1
### Added
- Support for more casts on discriminants
## 0.1.0
Initial version

View File

@ -1,37 +0,0 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# 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.
#
# 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.
[package]
edition = "2018"
name = "enum-primitive-derive"
version = "0.2.2"
authors = ["Doug Goldstein <cardoe@cardoe.com>"]
description = "enum_primitive implementation using procedural macros to have a custom derive"
homepage = "https://gitlab.com/cardoe/enum-primitive-derive"
readme = "README.md"
keywords = ["derive", "enum", "fromprimitive", "primitive", "ffi"]
categories = ["rust-patterns"]
license = "MIT"
repository = "https://gitlab.com/cardoe/enum-primitive-derive.git"
[lib]
proc-macro = true
[dependencies.num-traits]
version = "0.2"
default-features = false
[dependencies.quote]
version = "1"
[dependencies.syn]
version = "1"
[badges.gitlab]
repository = "cardoe/enum-primitive-derive"

View File

@ -1,20 +0,0 @@
Copyright (c) 2017 Doug Goldstein <cardoe@cardoe.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -1,110 +0,0 @@
[![Build status](https://gitlab.com/cardoe/enum-primitive-derive/badges/master/pipeline.svg)](https://gitlab.com/cardoe/enum-primitive-derive/commits/master)
[![Rust version]( https://img.shields.io/badge/rust-1.34+-blue.svg)]()
[![Documentation](https://docs.rs/enum-primitive-derive/badge.svg)](https://docs.rs/enum-primitive-derive)
[![Latest version](https://img.shields.io/crates/v/enum-primitive-derive.svg)](https://crates.io/crates/enum-primitive-derive)
[![All downloads](https://img.shields.io/crates/d/enum-primitive-derive.svg)](https://crates.io/crates/enum-primitive-derive)
[![Downloads of latest version](https://img.shields.io/crates/dv/enum-primitive-derive.svg)](https://crates.io/crates/enum-primitive-derive)
This is a custom derive, using procedural macros, implementation of
[enum_primitive](https://crates.io/crates/enum_primitive).
MSRV is 1.34.0
## Documentation
[https://docs.rs/enum-primitive-derive/](https://docs.rs/enum-primitive-derive/)
## Usage
Add the following to `Cargo.toml`:
```
[dependencies]
enum-primitive-derive = "^0.1"
num-traits = "^0.1"
```
Then to your code add:
```rust
#[macro_use]
extern crate enum_primitive_derive;
extern crate num_traits;
#[derive(Primitive)]
enum Variant {
Value = 1,
Another = 2,
}
```
To be really useful you need `use num_traits::FromPrimitive` or
`use num_traits::ToPrimitive` or both. You will then be able to
use
[num_traits::FromPrimitive](https://rust-num.github.io/num/num/trait.FromPrimitive.html)
and/or
[num_traits::ToPrimitive](https://rust-num.github.io/num/num/trait.ToPrimitive.html)
on your enum.
## Full Example
```rust
#[macro_use]
extern crate enum_primitive_derive;
extern crate num_traits;
use num_traits::{FromPrimitive, ToPrimitive};
#[derive(Primitive)]
enum Foo {
Bar = 32,
Dead = 42,
Beef = 50,
}
fn main() {
assert_eq!(Foo::from_i32(32), Some(Foo::Bar));
assert_eq!(Foo::from_i32(42), Some(Foo::Dead));
assert_eq!(Foo::from_i64(50), Some(Foo::Beef));
assert_eq!(Foo::from_isize(17), None);
let bar = Foo::Bar;
assert_eq!(bar.to_i32(), Some(32));
let dead = Foo::Dead;
assert_eq!(dead.to_isize(), Some(42));
}
```
# Complex Example
In this case we attempt to use values created by
[bindgen](https://crates.io/crates/bindgen).
```rust
#[macro_use]
extern crate enum_primitive_derive;
extern crate num_traits;
use num_traits::{FromPrimitive, ToPrimitive};
pub const ABC: ::std::os::raw::c_uint = 1;
pub const DEF: ::std::os::raw::c_uint = 2;
pub const GHI: ::std::os::raw::c_uint = 4;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Primitive)]
enum BindGenLike {
ABC = ABC as isize,
DEF = DEF as isize,
GHI = GHI as isize,
}
fn main() {
assert_eq!(BindGenLike::from_isize(4), Some(BindGenLike::GHI));
assert_eq!(BindGenLike::from_u32(2), Some(BindGenLike::DEF));
assert_eq!(BindGenLike::from_u32(8), None);
let abc = BindGenLike::ABC;
assert_eq!(abc.to_u32(), Some(1));
}
```

View File

@ -1,278 +0,0 @@
// Copyright (c) 2017 Doug Goldstein <cardoe@cardoe.com>
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// “Software”), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//! This crate provides a custom derive `Primitive` that helps people
//! providing native Rust bindings to C code by allowing a C-like `enum`
//! declaration to convert to its primitve values and back from them. You
//! can selectively include `num_traits::ToPrimitive` and
//! `num_traits::FromPrimitive` to get these features.
//!
//! # Example
//!
//! ```rust
//! use enum_primitive_derive::Primitive;
//! use num_traits::{FromPrimitive, ToPrimitive};
//!
//! #[derive(Debug, Eq, PartialEq, Primitive)]
//! enum Foo {
//! Bar = 32,
//! Dead = 42,
//! Beef = 50,
//! }
//!
//! fn main() {
//! assert_eq!(Foo::from_i32(32), Some(Foo::Bar));
//! assert_eq!(Foo::from_i32(42), Some(Foo::Dead));
//! assert_eq!(Foo::from_i64(50), Some(Foo::Beef));
//! assert_eq!(Foo::from_isize(17), None);
//!
//! let bar = Foo::Bar;
//! assert_eq!(bar.to_i32(), Some(32));
//!
//! let dead = Foo::Dead;
//! assert_eq!(dead.to_isize(), Some(42));
//! }
//! ```
//!
//! # Complex Example
//!
//! ```rust
//! use enum_primitive_derive::Primitive;
//! use num_traits::{FromPrimitive, ToPrimitive};
//!
//! pub const ABC: ::std::os::raw::c_uint = 1;
//! pub const DEF: ::std::os::raw::c_uint = 2;
//! pub const GHI: ::std::os::raw::c_uint = 4;
//!
//! #[derive(Clone, Copy, Debug, Eq, PartialEq, Primitive)]
//! enum BindGenLike {
//! ABC = ABC as isize,
//! DEF = DEF as isize,
//! GHI = GHI as isize,
//! }
//!
//! fn main() {
//! assert_eq!(BindGenLike::from_isize(4), Some(BindGenLike::GHI));
//! assert_eq!(BindGenLike::from_u32(2), Some(BindGenLike::DEF));
//! assert_eq!(BindGenLike::from_u32(8), None);
//!
//! let abc = BindGenLike::ABC;
//! assert_eq!(abc.to_u32(), Some(1));
//! }
//! ```
//!
//! # TryFrom Example
//!
//! ```rust
//! use enum_primitive_derive::Primitive;
//! use core::convert::TryFrom;
//!
//! #[derive(Debug, Eq, PartialEq, Primitive)]
//! enum Foo {
//! Bar = 32,
//! Dead = 42,
//! Beef = 50,
//! }
//!
//! fn main() {
//! let bar = Foo::try_from(32);
//! assert_eq!(bar, Ok(Foo::Bar));
//!
//! let dead = Foo::try_from(42);
//! assert_eq!(dead, Ok(Foo::Dead));
//!
//! let unknown = Foo::try_from(12);
//! assert!(unknown.is_err());
//! }
//! ```
extern crate proc_macro;
use proc_macro::TokenStream;
/// Provides implementation of `num_traits::ToPrimitive` and
/// `num_traits::FromPrimitive`
#[proc_macro_derive(Primitive)]
pub fn primitive(input: TokenStream) -> TokenStream {
let ast = syn::parse_macro_input!(input as syn::DeriveInput);
impl_primitive(&ast)
}
fn impl_primitive(ast: &syn::DeriveInput) -> TokenStream {
let name = &ast.ident;
// Check if derive(Primitive) was specified for a struct
if let syn::Data::Enum(ref variant) = ast.data {
let (var_u64, dis_u64): (Vec<_>, Vec<_>) = variant
.variants
.iter()
.map(|v| {
match v.fields {
syn::Fields::Unit => (),
_ => panic!("#[derive(Primitive) can only operate on C-like enums"),
}
if v.discriminant.is_none() {
panic!(
"#[derive(Primitive) requires C-like enums with \
discriminants for all enum variants"
);
}
let discrim = match v.discriminant.clone().map(|(_eq, expr)| expr).unwrap() {
syn::Expr::Cast(real) => *real.expr,
orig => orig,
};
(v.ident.clone(), discrim)
})
.unzip();
// quote!{} needs this to be a vec since its in #( )*
let enum_u64 = vec![name.clone(); variant.variants.len()];
// can't reuse variables in quote!{} body
let var_i64 = var_u64.clone();
let dis_i64 = dis_u64.clone();
let enum_i64 = enum_u64.clone();
let to_name = name.clone();
let to_enum_u64 = enum_u64.clone();
let to_var_u64 = var_u64.clone();
let to_dis_u64 = dis_u64.clone();
let to_enum_i64 = enum_u64.clone();
let to_var_i64 = var_u64.clone();
let to_dis_i64 = dis_u64.clone();
TokenStream::from(quote::quote! {
impl ::num_traits::FromPrimitive for #name {
fn from_u64(val: u64) -> Option<Self> {
match val as _ {
#( #dis_u64 => Some(#enum_u64::#var_u64), )*
_ => None,
}
}
fn from_i64(val: i64) -> Option<Self> {
match val as _ {
#( #dis_i64 => Some(#enum_i64::#var_i64), )*
_ => None,
}
}
}
impl ::num_traits::ToPrimitive for #to_name {
fn to_u64(&self) -> Option<u64> {
match *self {
#( #to_enum_u64::#to_var_u64 => Some(#to_dis_u64 as u64), )*
}
}
fn to_i64(&self) -> Option<i64> {
match *self {
#( #to_enum_i64::#to_var_i64 => Some(#to_dis_i64 as i64), )*
}
}
}
impl ::core::convert::TryFrom<u64> for #to_name {
type Error = &'static str;
fn try_from(value: u64) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_u64(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<u32> for #to_name {
type Error = &'static str;
fn try_from(value: u32) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_u32(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<u16> for #to_name {
type Error = &'static str;
fn try_from(value: u16) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_u16(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<u8> for #to_name {
type Error = &'static str;
fn try_from(value: u8) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_u8(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<i64> for #name {
type Error = &'static str;
fn try_from(value: i64) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_i64(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<i32> for #name {
type Error = &'static str;
fn try_from(value: i32) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_i32(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<i16> for #name {
type Error = &'static str;
fn try_from(value: i16) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_i16(value).ok_or_else(|| "Unknown variant")
}
}
impl ::core::convert::TryFrom<i8> for #name {
type Error = &'static str;
fn try_from(value: i8) -> ::core::result::Result<Self, Self::Error> {
use ::num_traits::FromPrimitive;
#to_name::from_i8(value).ok_or_else(|| "Unknown variant")
}
}
})
} else {
panic!("#[derive(Primitive)] is only valid for C-like enums");
}
}

View File

@ -1 +1 @@
{"files":{"Cargo.toml":"bb451578b35529f9bb5dd3543b3a29b99a29e1f849b72ce4a6a640642000b49a","LICENSE":"06de63df29199a394442b57a28e886059ddc940973e10646877a0793fd53e2c9","README.md":"4c2a1448aab9177fd5f033faaf704af7bb222bf0804079fd3cff90fa1df4b812","src/errors/linux.rs":"daa23869d1ad317a7a20691a9e2712881952e1de6b2ae5c7e3c03c2775befd98","src/errors/macos.rs":"0283269623bacb90e15a9de90347a6a8cfaa4ac0784b516f9c6ff639e08f5060","src/errors/mod.rs":"f224af66124fd31a040c8da11bbab7b7795b48e4edea76e01c1f4dee537ea38a","src/errors/windows.rs":"15be6e938421f36eb082c1c6db8312c936a80b5d414925748f665f3c7a6245e5","src/format.rs":"8d2447593f3a15228323389af31fb889759b5d2fb649811ad6ad0dfddbd75339","src/lib.rs":"0900c00594b3c386b86127055889006f0d7d0004b08455fadb0e60d55a469cab","src/traits.rs":"93127ad69a849325ed66a0626e0bdae05868488f81c539d35c71a7bfbb9e51ac","src/utils.rs":"17e8777b05998a8149fc5168af3bca1e0f9aeffe28cb3d6dbfb89c546f75e5ed"},"package":"9114b15d86ee5e5c3e3b4d05821d17237adbf98c11dd07fc8f5a9b037a010ee5"}
{"files":{"Cargo.toml":"d7167fc703ca78f2b972d2c369ffec203e3d60af75a9748fc7a43772be77cb1c","LICENSE":"06de63df29199a394442b57a28e886059ddc940973e10646877a0793fd53e2c9","README.md":"4c2a1448aab9177fd5f033faaf704af7bb222bf0804079fd3cff90fa1df4b812","src/errors/linux.rs":"df743ac9478e39f8a577f4f10f2d1317babad7b7c0d26cdbba2ea6b5426f4126","src/errors/macos.rs":"02ac6427f376e6f587c1f3e4d5df2a72e4cf13c4858409e73f26d47ad8e54340","src/errors/mod.rs":"f224af66124fd31a040c8da11bbab7b7795b48e4edea76e01c1f4dee537ea38a","src/errors/windows.rs":"0567af7bfac3ae2a8dff418e10873d8a5bf15a8b8ac6892c5ffdab08ec3ac901","src/format.rs":"a5f52230a872082f0855fd4eab9b2db227350427e01f012c1b2db7841f89d7d1","src/lib.rs":"0900c00594b3c386b86127055889006f0d7d0004b08455fadb0e60d55a469cab","src/traits.rs":"93127ad69a849325ed66a0626e0bdae05868488f81c539d35c71a7bfbb9e51ac","src/utils.rs":"17e8777b05998a8149fc5168af3bca1e0f9aeffe28cb3d6dbfb89c546f75e5ed"},"package":null}

View File

@ -20,32 +20,22 @@ readme = "README.md"
license = "MIT"
repository = "https://github.com/rust-minidump/rust-minidump"
[dependencies]
bitflags = "1.3.2"
debugid = "0.8.0"
num-derive = "0.4"
num-traits = "0.2"
range-map = "0.2"
smart-default = "0.7.0"
[dependencies.arbitrary]
version = "1"
features = ["derive"]
optional = true
[dependencies.bitflags]
version = "1.3.2"
[dependencies.debugid]
version = "0.8.0"
[dependencies.enum-primitive-derive]
version = "0.2.2"
[dependencies.num-traits]
version = "0.2"
[dependencies.range-map]
version = "0.2"
[dependencies.scroll]
version = "0.11.0"
features = ["derive"]
[dependencies.smart-default]
version = "0.6.0"
[badges.travis-ci]
repository = "rust-minidump/rust-minidump"

View File

@ -1,7 +1,7 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
use enum_primitive_derive::Primitive;
use num_derive::FromPrimitive;
/// Values for
/// [`MINIDUMP_EXCEPTION::exception_code`](crate::format::MINIDUMP_EXCEPTION::exception_code)
@ -9,7 +9,7 @@ use enum_primitive_derive::Primitive;
///
/// These are primarily signal numbers from bits/signum.h.
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinux {
/// Hangup (POSIX)
SIGHUP = 0x1u32,
@ -78,7 +78,7 @@ pub enum ExceptionCodeLinux {
}
// These values come from asm-generic/siginfo.h
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
#[repr(i32)]
pub enum ExceptionCodeLinuxSicode {
SI_USER = 0,
@ -93,7 +93,7 @@ pub enum ExceptionCodeLinuxSicode {
SI_ASYNCNL = -60i32,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinuxSigillKind {
ILL_ILLOPC = 1,
ILL_ILLOPN = 2,
@ -106,7 +106,7 @@ pub enum ExceptionCodeLinuxSigillKind {
ILL_BADIADDR = 9,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinuxSigtrapKind {
TRAP_BRKPT = 1,
TRAP_TRACE = 2,
@ -116,7 +116,7 @@ pub enum ExceptionCodeLinuxSigtrapKind {
TRAP_PERF = 6,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinuxSigfpeKind {
FPE_INTDIV = 1,
FPE_INTOVF = 2,
@ -128,7 +128,7 @@ pub enum ExceptionCodeLinuxSigfpeKind {
FPE_FLTSUB = 8,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinuxSigsegvKind {
SEGV_MAPERR = 1,
SEGV_ACCERR = 2,
@ -136,7 +136,7 @@ pub enum ExceptionCodeLinuxSigsegvKind {
SEGV_PKUERR = 4,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinuxSigbusKind {
BUS_ADRALN = 1,
BUS_ADRERR = 2,
@ -145,7 +145,7 @@ pub enum ExceptionCodeLinuxSigbusKind {
BUS_MCEERR_AO = 5,
}
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeLinuxSigsysKind {
SYS_SECCOMP = 1,
SYS_USER_DISPATCH = 2,

View File

@ -1,7 +1,7 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
use enum_primitive_derive::Primitive;
use num_derive::FromPrimitive;
/// Values for
/// [`MINIDUMP_EXCEPTION::exception_code`](crate::format::MINIDUMP_EXCEPTION::exception_code)
@ -12,7 +12,7 @@ use enum_primitive_derive::Primitive;
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/exception_types.h#L64-L105
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMac {
/// code can be a kern_return_t
EXC_BAD_ACCESS = 1,
@ -39,7 +39,7 @@ pub enum ExceptionCodeMac {
/// These are the relevant kern_return_t values from [osfmk/mach/kern_return.h][header]
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/kern_return.h#L70-L340
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadAccessKernType {
KERN_INVALID_ADDRESS = 1,
KERN_PROTECTION_FAILURE = 2,
@ -55,7 +55,7 @@ pub enum ExceptionCodeMacBadAccessKernType {
/// See the [osfmk/mach/arm/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/exception.h#L66-L75
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadAccessArmType {
EXC_ARM_DA_ALIGN = 0x0101,
EXC_ARM_DA_DEBUG = 0x0102,
@ -69,7 +69,7 @@ pub enum ExceptionCodeMacBadAccessArmType {
/// See the [osfmk/mach/ppc/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/b472f0612b8556cd1c6eb1c285ec1953de759e35/osfmk/mach/ppc/exception.h#L71-L78
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadAccessPpcType {
EXC_PPC_VM_PROT_READ = 0x0101,
EXC_PPC_BADSPACE = 0x0102,
@ -81,7 +81,7 @@ pub enum ExceptionCodeMacBadAccessPpcType {
/// See the [osfmk/mach/i386/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/i386/exception.h#L122
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadAccessX86Type {
EXC_I386_GPFLT = 13,
}
@ -91,7 +91,7 @@ pub enum ExceptionCodeMacBadAccessX86Type {
/// See the [osfmk/mach/arm/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/exception.h#L48-L52
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadInstructionArmType {
EXC_ARM_UNDEFINED = 1,
}
@ -101,7 +101,7 @@ pub enum ExceptionCodeMacBadInstructionArmType {
/// See the [osfmk/mach/ppc/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/b472f0612b8556cd1c6eb1c285ec1953de759e35/osfmk/mach/ppc/exception.h#L60-L69
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadInstructionPpcType {
EXC_PPC_INVALID_SYSCALL = 1,
EXC_PPC_UNIPL_INST = 2,
@ -116,7 +116,7 @@ pub enum ExceptionCodeMacBadInstructionPpcType {
/// See the [osfmk/mach/i386/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/i386/exception.h#L74-L78
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBadInstructionX86Type {
/// Invalid Operation
EXC_I386_INVOP = 1,
@ -155,7 +155,7 @@ pub enum ExceptionCodeMacBadInstructionX86Type {
/// See the [osfmk/mach/arm/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/exception.h#L54-L64
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacArithmeticArmType {
EXC_ARM_FP_IO = 1,
EXC_ARM_FP_DZ = 2,
@ -170,7 +170,7 @@ pub enum ExceptionCodeMacArithmeticArmType {
/// See the [osfmk/mach/ppc/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/b472f0612b8556cd1c6eb1c285ec1953de759e35/osfmk/mach/ppc/exception.h#L80-L90
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacArithmeticPpcType {
/// Integer ovrflow
EXC_PPC_OVERFLOW = 1,
@ -198,7 +198,7 @@ pub enum ExceptionCodeMacArithmeticPpcType {
/// See the [osfmk/mach/i386/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/i386/exception.h#L80-L91
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacArithmeticX86Type {
EXC_I386_DIV = 1,
EXC_I386_INTO = 2,
@ -218,7 +218,7 @@ pub enum ExceptionCodeMacArithmeticX86Type {
/// [header1]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/bsd/sys/ux_exception.h#L48-L52
/// [header2]: https://github.com/apple/darwin-xnu/blob/b472f0612b8556cd1c6eb1c285ec1953de759e35/osfmk/mach/ppc/exception.h#L100-L105
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacSoftwareType {
SIGABRT = 0x00010002u32,
UNCAUGHT_NS_EXCEPTION = 0xDEADC0DE,
@ -234,7 +234,7 @@ pub enum ExceptionCodeMacSoftwareType {
/// See the [osfmk/mach/arm/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/arm/exception.h#L77-L81
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBreakpointArmType {
EXC_ARM_BREAKPOINT = 1,
}
@ -244,7 +244,7 @@ pub enum ExceptionCodeMacBreakpointArmType {
/// See the [osfmk/mach/ppc/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/b472f0612b8556cd1c6eb1c285ec1953de759e35/osfmk/mach/ppc/exception.h#L108-L112
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBreakpointPpcType {
EXC_PPC_BREAKPOINT = 1,
}
@ -254,7 +254,7 @@ pub enum ExceptionCodeMacBreakpointPpcType {
/// See the [osfmk/mach/i386/exception.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/mach/i386/exception.h#L102-L107
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacBreakpointX86Type {
EXC_I386_SGL = 1,
EXC_I386_BPT = 2,
@ -265,7 +265,7 @@ pub enum ExceptionCodeMacBreakpointX86Type {
/// See the [osfmk/kern/exc_resource.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/kern/exc_resource.h#L60-L65
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacResourceType {
RESOURCE_TYPE_CPU = 1,
RESOURCE_TYPE_WAKEUPS = 2,
@ -279,7 +279,7 @@ pub enum ExceptionCodeMacResourceType {
/// See the [osfmk/kern/exc_resource.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/kern/exc_resource.h#L67-L69
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacResourceCpuFlavor {
FLAVOR_CPU_MONITOR = 1,
FLAVOR_CPU_MONITOR_FATAL = 2,
@ -290,7 +290,7 @@ pub enum ExceptionCodeMacResourceCpuFlavor {
/// See the [osfmk/kern/exc_resource.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/kern/exc_resource.h#L67-L69
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacResourceWakeupsFlavor {
FLAVOR_WAKEUPS_MONITOR = 1,
}
@ -300,7 +300,7 @@ pub enum ExceptionCodeMacResourceWakeupsFlavor {
/// See the [osfmk/kern/exc_resource.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/kern/exc_resource.h#L102-L103
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacResourceMemoryFlavor {
FLAVOR_HIGH_WATERMARK = 1,
}
@ -310,7 +310,7 @@ pub enum ExceptionCodeMacResourceMemoryFlavor {
/// See the [osfmk/kern/exc_resource.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/kern/exc_resource.h#L164-L166
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacResourceIOFlavor {
FLAVOR_IO_PHYSICAL_WRITES = 1,
FLAVOR_IO_LOGICAL_WRITES = 2,
@ -321,7 +321,7 @@ pub enum ExceptionCodeMacResourceIOFlavor {
/// See the [osfmk/kern/exc_resource.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/osfmk/kern/exc_resource.h#L136-L137
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacResourceThreadsFlavor {
FLAVOR_THREADS_HIGH_WATERMARK = 1,
}
@ -331,7 +331,7 @@ pub enum ExceptionCodeMacResourceThreadsFlavor {
/// See the [osfmk/kern/exc_guard.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/main/osfmk/kern/exc_guard.h
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacGuardType {
GUARD_TYPE_NONE = 0,
GUARD_TYPE_MACH_PORT = 1,
@ -346,7 +346,7 @@ pub enum ExceptionCodeMacGuardType {
/// See the [osfmk/mach/port.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/main/osfmk/mach/port.h
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacGuardMachPortFlavor {
GUARD_EXC_DESTROY = 0x00000001,
GUARD_EXC_MOD_REFS = 0x00000002,
@ -378,7 +378,7 @@ pub enum ExceptionCodeMacGuardMachPortFlavor {
/// See the [bsd/sys/guarded.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/main/bsd/sys/guarded.h
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacGuardFDFlavor {
GUARD_EXC_CLOSE = 0x00000001,
GUARD_EXC_DUP = 0x00000002,
@ -394,7 +394,7 @@ pub enum ExceptionCodeMacGuardFDFlavor {
/// See the [bsd/sys/guarded.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/main/bsd/sys/guarded.h
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacGuardVNFlavor {
GUARD_EXC_RENAME_TO = 0x00000001,
GUARD_EXC_RENAME_FROM = 0x00000002,
@ -410,7 +410,7 @@ pub enum ExceptionCodeMacGuardVNFlavor {
/// See the [osfmk/mach/vm_statistics.h][header] header in Apple's kernel sources
///
/// [header]: https://github.com/apple/darwin-xnu/blob/main/osfmk/mach/vm_statistics.h
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeMacGuardVirtMemoryFlavor {
GUARD_EXC_DEALLOC_GAP = 0x00000001,
}

View File

@ -1,7 +1,7 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
use enum_primitive_derive::Primitive;
use num_derive::FromPrimitive;
/// Values for
/// [`MINIDUMP_EXCEPTION::exception_code`](crate::format::MINIDUMP_EXCEPTION::exception_code)
@ -9,7 +9,7 @@ use enum_primitive_derive::Primitive;
///
/// These values come from WinBase.h and WinNT.h with a few additions.
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeWindows {
EXCEPTION_GUARD_PAGE = 0x80000001u32,
EXCEPTION_DATATYPE_MISALIGNMENT = 0x80000002,
@ -55,7 +55,7 @@ pub enum ExceptionCodeWindows {
/// ```
/// For the time being we only retain the ones we actually encounter in the wide.
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum WinErrorFacilityWindows {
FACILITY_VISUALCPP = 109,
}
@ -72,7 +72,7 @@ pub enum WinErrorFacilityWindows {
/// | sed -r 's@([0-9]+) ([A-Z_0-9]+)@ \2 = \L\1,@'
/// ```
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum WinErrorWindows {
ERROR_SUCCESS = 0,
ERROR_INVALID_FUNCTION = 1,
@ -2914,7 +2914,7 @@ pub enum WinErrorWindows {
/// | sed -r 's@(0x[048C][0-9A-F]+) ([A-Z_0-9]+)@ \2 = \L\1,@'
/// ```
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum NtStatusWindows {
STATUS_SUCCESS = 0x00000000u32,
STATUS_WAIT_1 = 0x00000001,
@ -5763,7 +5763,7 @@ pub enum NtStatusWindows {
/// | sed -r 's@([0-9]+) ([A-Z_0-9]+)@ \2 = \1,@'
/// ```
#[repr(u64)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum FastFailCode {
FAST_FAIL_LEGACY_GS_VIOLATION = 0,
FAST_FAIL_VTGUARD_CHECK_FAILURE = 1,
@ -5842,7 +5842,7 @@ pub enum FastFailCode {
///
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
#[repr(u64)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeWindowsAccessType {
READ = 0,
WRITE = 1,
@ -5856,7 +5856,7 @@ pub enum ExceptionCodeWindowsAccessType {
///
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record
#[repr(u64)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ExceptionCodeWindowsInPageErrorType {
READ = 0,
WRITE = 1,

View File

@ -36,7 +36,7 @@
use std::fmt;
use bitflags::bitflags;
use enum_primitive_derive::Primitive;
use num_derive::FromPrimitive;
use scroll::{Endian, Pread, Pwrite, SizeWith};
use smart_default::SmartDefault;
@ -152,7 +152,7 @@ pub struct MINIDUMP_DIRECTORY {
///
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/minidumpapiset/ne-minidumpapiset-minidump_stream_type
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum MINIDUMP_STREAM_TYPE {
/// An unused stream directory entry
UnusedStream = 0,
@ -311,6 +311,12 @@ pub enum MINIDUMP_STREAM_TYPE {
///
/// See ['MINIDUMP_MAC_CRASH_INFO'].
MozMacosCrashInfoStream = 0x4d7a0001,
/// The kernel boot args on the machine where the crashed process is
/// running. Only available on macOS. 0x4D7A = "Mz".
///
/// See ['MINIDUMP_MAC_BOOTARGS']
MozMacosBootargsStream = 0x4d7a0002,
}
impl From<MINIDUMP_STREAM_TYPE> for u32 {
@ -430,7 +436,7 @@ pub const VS_FFI_STRUCVERSION: u32 = 0x00010000;
/// [sym]: http://web.archive.org/web/20070915060650/http://www.x86.org/ftp/manuals/tools/sym.pdf
/// [win2k]: https://dl.acm.org/citation.cfm?id=375734
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum CvSignature {
/// PDB 2.0 CodeView data: 'NB10': [`CV_INFO_PDB20`]
Pdb20 = 0x3031424e,
@ -1465,7 +1471,7 @@ pub struct MINIDUMP_SYSTEM_INFO {
/// Many of these are taken from definitions in WinNT.h, but several of them are
/// Breakpad extensions.
#[repr(u16)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum ProcessorArchitecture {
PROCESSOR_ARCHITECTURE_INTEL = 0,
PROCESSOR_ARCHITECTURE_MIPS = 1,
@ -1497,7 +1503,7 @@ pub enum ProcessorArchitecture {
/// The Windows values here are taken from defines in WinNT.h, but the rest are Breakpad
/// extensions.
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum PlatformId {
/// Windows 3.1
VER_PLATFORM_WIN32s = 1,
@ -1949,7 +1955,7 @@ pub struct MINIDUMP_ASSERTION_INFO {
///
/// [fmt]: https://chromium.googlesource.com/breakpad/breakpad/+/88d8114fda3e4a7292654bd6ac0c34d6c88a8121/src/google_breakpad/common/minidump_format.h#1011
#[repr(u32)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Primitive)]
#[derive(Copy, Clone, PartialEq, Eq, Debug, FromPrimitive)]
pub enum AssertionType {
Unknown = 0,
InvalidParameter = 1,
@ -2403,6 +2409,13 @@ pub const MAC_CRASH_INFO_STRING_MAX_SIZE: usize = 8192;
/// undocumented, so just in case we set a large maximum.
pub const MAC_CRASH_INFOS_MAX: usize = 20;
/// MacOS kernel boot args
#[derive(Debug, Clone, Pread, Pwrite, SizeWith)]
pub struct MINIDUMP_MAC_BOOTARGS {
pub stream_type: u32,
pub bootargs: RVA64,
}
bitflags! {
/// Possible values of [`ARMCpuInfo::elf_hwcaps`]
///

View File

@ -1 +1 @@
{"files":{"CHANGELOG.md":"18a0878db9cd4b571d96ec9f582a180072021d533fdae77316da1fef7649aa4f","Cargo.lock":"ec38d0341d418be606de310e72ab4018db002f8934654658c9c7c80cc39e624a","Cargo.toml":"e90e0d90e30a2b31b5b74dfdce525e2ae6c3945f132013b60a8318e873ead662","LICENSE":"f09111a2bf85257f1d098de0095ad77fd12649fbbe9a33c8a13e422848b601bb","README.md":"4acd18bb4f05c9e05fba459083e1b88901ee8f21a8cef90182c80f9224b811e8","examples/example.rs":"5bf4455ad1383bd8df85b4390bbb9fbe79aa3ed13bcefcddffccb8e91f95ba8e","src/body_impl.rs":"fa74f4354564c066a5ad9cea649e1de799019e362f95313f04f73af96fcbac16","src/default_attr.rs":"0f387d8aed64c28028d0ed798dea0671f5320ff738319cec2881bb7cb9e2536c","src/lib.rs":"4bb6e761b55b0ff50b0edc9bec561770b1ca8b487d370c420d3c0d6744590f66","src/util.rs":"ffa40f7845d63d10ac86ab495b07ac2605aa59288bf31ba37105a2bf61522984","tests/tests.rs":"1f02783a2b3e955675049b3027215a63b012aacf340dd4a5eca73d028cf3947c"},"package":"133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6"}
{"files":{"CHANGELOG.md":"391b5ca7965b379588e8cdd0fdc76a2c6ac44603dd007ddfb9263dc4232b6eb4","Cargo.lock":"6060bc53da766a9073b1fd836699f99b2fc28a99bf15dbf9f213f6bce3008dba","Cargo.toml":"886220167526d72040ace0629cab35e9e7a2b22d76bb28c7332a2e9ab2e42db8","LICENSE":"f09111a2bf85257f1d098de0095ad77fd12649fbbe9a33c8a13e422848b601bb","README.md":"553e1508b8e7b3fc0afeb8636263169da6a85d92aa6605fbeada927f62e6a88e","examples/example.rs":"5ea8b9f063549e46e74a8b5e7079a14a8296d945536271d1be65400a9377218b","src/body_impl.rs":"d1e3a209037d43ad653fdf7628ad52c4b70eced8d03e5e7b12e4381de8eb642a","src/default_attr.rs":"89e721794c16da3dbf59fc71381cbff74b7c0b5a5805765306fdfda0a9615ec2","src/lib.rs":"ff620a9442205980f0445f1624dba132f710ba5fcaccd65b8d1493f8af232333","src/util.rs":"8c553bfcf7d8a7d7960a1c3e3517218648ab4bd3ec5144b972a623b98bff1427","tests/tests.rs":"2f847e22064723d70145db3dfeadfa5b14b0d58ba9bdc36ff0e46b7f52eba511"},"package":"0eb01866308440fc64d6c44d9e86c5cc17adfe33c4d6eed55da9145044d0ffc1"}

9
third_party/rust/smart-default/CHANGELOG.md vendored Executable file → Normal file
View File

@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
## 0.7.1 - 2023-04-24
### Fixed
- Fixed bug where the macro fails on valid default expression that is also a
valid attribute meta because it was expecting the `_code` hack.
## 0.7.0 - 2023-04-23
### Changed
- Update `syn` to version 2
## 0.6.0 - 2019-12-13
### Changed
- Update `syn`, `quote` and `proc-macro2` versions to `1.*.*`.

View File

@ -1,47 +1,47 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "proc-macro2"
version = "1.0.6"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435"
dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.2"
version = "1.0.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
]
[[package]]
name = "smart-default"
version = "0.6.0"
version = "0.7.1"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "syn"
version = "1.0.11"
version = "2.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822"
dependencies = [
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-xid"
version = "0.2.0"
name = "unicode-ident"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9c9e470a8dc4aeae2dee2f335e8f533e2d4b347e1434e5671afc49b054592f27"
"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe"
"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"

View File

@ -3,16 +3,16 @@
# 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 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)
# 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.
[package]
edition = "2021"
name = "smart-default"
version = "0.6.0"
version = "0.7.1"
authors = ["IdanArye <idanarye@gmail.com>"]
description = "Rust custom-derive macro for Default with more control on the fields"
documentation = "https://idanarye.github.io/rust-smart-default/"
@ -23,6 +23,7 @@ repository = "https://github.com/idanarye/rust-smart-default"
[lib]
proc-macro = true
[dependencies.proc-macro2]
version = "1"
@ -30,5 +31,4 @@ version = "1"
version = "1"
[dependencies.syn]
version = "1"
features = ["full"]
version = "2"

0
third_party/rust/smart-default/LICENSE vendored Executable file → Normal file
View File

5
third_party/rust/smart-default/README.md vendored Executable file → Normal file
View File

@ -1,4 +1,4 @@
[![Build Status](https://api.travis-ci.org/idanarye/rust-smart-default.svg?branch=master)](https://travis-ci.org/idanarye/rust-smart-default)
[![Build Status](https://github.com/idanarye/rust-smart-default/workflows/CI/badge.svg)](https://github.com/idanarye/rust-smart-default/actions)
[![Latest Version](https://img.shields.io/crates/v/smart-default.svg)](https://crates.io/crates/smart-default)
[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://idanarye.github.io/rust-smart-default/)
@ -7,8 +7,7 @@
Custom derive for automatically implementing the `Default` trait with customized default values:
```rust
#[macro_use]
extern crate smart_default;
use smart_default::SmartDefault;
#[derive(SmartDefault)]
enum Foo {

19
third_party/rust/smart-default/examples/example.rs vendored Executable file → Normal file
View File

@ -1,5 +1,3 @@
extern crate smart_default;
use smart_default::SmartDefault;
#[derive(PartialEq, SmartDefault, Debug)]
@ -22,11 +20,14 @@ enum Foo {
}
fn main() {
assert!(Foo::default() == Foo::Baz {
a: 12,
b: 0,
c: Some(0),
d: vec![1, 2, 3],
e: "four".to_owned(),
});
assert!(
Foo::default()
== Foo::Baz {
a: 12,
b: 0,
c: Some(0),
d: vec![1, 2, 3],
e: "four".to_owned(),
}
);
}

98
third_party/rust/smart-default/src/body_impl.rs vendored Executable file → Normal file
View File

@ -1,12 +1,12 @@
use proc_macro2::TokenStream;
use syn::DeriveInput;
use syn::spanned::Spanned;
use syn::parse::Error;
use quote::quote;
use syn::parse::Error;
use syn::spanned::Spanned;
use syn::DeriveInput;
use default_attr::{DefaultAttr, ConversionStrategy};
use util::find_only;
use crate::default_attr::{ConversionStrategy, DefaultAttr};
use crate::util::find_only;
pub fn impl_my_derive(input: &DeriveInput) -> Result<TokenStream, Error> {
let name = &input.ident;
@ -15,9 +15,12 @@ pub fn impl_my_derive(input: &DeriveInput) -> Result<TokenStream, Error> {
let (default_expr, doc) = match input.data {
syn::Data::Struct(ref body) => {
let (body_assignment, doc) = default_body_tt(&body.fields)?;
(quote! {
#name #body_assignment
}, format!("Return `{}{}`", name, doc))
(
quote! {
#name #body_assignment
},
format!("Return `{}{}`", name, doc),
)
}
syn::Data::Enum(ref body) => {
let default_variant = find_only(body.variants.iter(), |variant| {
@ -25,17 +28,24 @@ pub fn impl_my_derive(input: &DeriveInput) -> Result<TokenStream, Error> {
if meta.code.is_none() {
Ok(true)
} else {
Err(Error::new(meta.code.span(), "Attribute #[default] on variants should have no value"))
Err(Error::new(
meta.code.span(),
"Attribute #[default] on variants should have no value",
))
}
} else {
Ok(false)
}
})?.ok_or_else(|| Error::new(input.span(), "No default variant"))?;
})?
.ok_or_else(|| Error::new(input.span(), "No default variant"))?;
let default_variant_name = &default_variant.ident;
let (body_assignment, doc) = default_body_tt(&default_variant.fields)?;
(quote! {
#name :: #default_variant_name #body_assignment
}, format!("Return `{}::{}{}`", name, default_variant_name, doc))
(
quote! {
#name :: #default_variant_name #body_assignment
},
format!("Return `{}::{}{}`", name, default_variant_name, doc),
)
}
syn::Data::Union(_) => {
panic!()
@ -58,51 +68,65 @@ fn default_body_tt(body: &syn::Fields) -> Result<(TokenStream, String), Error> {
let mut doc = String::new();
use std::fmt::Write;
let body_tt = match body {
&syn::Fields::Named(ref fields) => {
syn::Fields::Named(ref fields) => {
doc.push_str(" {");
let result = {
let field_assignments = fields.named.iter().map(|field| {
let field_name = field.ident.as_ref();
let (default_value, default_doc) = field_default_expr_and_doc(field)?;
write!(&mut doc, "\n {}: {},", field_name.expect("field value in struct is empty"), default_doc).unwrap();
// let default_value = default_value.into_token_stream();
Ok(quote! { #field_name : #default_value })
}).collect::<Result<Vec<_>, Error>>()?;
quote!{
let field_assignments = fields
.named
.iter()
.map(|field| {
let field_name = field.ident.as_ref();
let (default_value, default_doc) = field_default_expr_and_doc(field)?;
write!(
&mut doc,
"\n {}: {},",
field_name.expect("field value in struct is empty"),
default_doc
)
.unwrap();
// let default_value = default_value.into_token_stream();
Ok(quote! { #field_name : #default_value })
})
.collect::<Result<Vec<_>, Error>>()?;
quote! {
{
#( #field_assignments ),*
}
}
};
if (&mut doc).ends_with(",") {
if doc.ends_with(',') {
doc.pop();
doc.push('\n');
};
doc.push('}');
result
}
&syn::Fields::Unnamed(ref fields) => {
syn::Fields::Unnamed(ref fields) => {
doc.push('(');
let result = {
let field_assignments = fields.unnamed.iter().map(|field| {
let (default_value, default_doc) = field_default_expr_and_doc(field)?;
write!(&mut doc, "{}, ", default_doc).unwrap();
Ok(default_value)
}).collect::<Result<Vec<TokenStream>, Error>>()?;
let field_assignments = fields
.unnamed
.iter()
.map(|field| {
let (default_value, default_doc) = field_default_expr_and_doc(field)?;
write!(&mut doc, "{}, ", default_doc).unwrap();
Ok(default_value)
})
.collect::<Result<Vec<TokenStream>, Error>>()?;
quote! {
(
#( #field_assignments ),*
)
}
};
if (&mut doc).ends_with(", ") {
if doc.ends_with(", ") {
doc.pop();
doc.pop();
};
doc.push(')');
result
}
&syn::Fields::Unit => quote!{},
&syn::Fields::Unit => quote! {},
};
Ok((body_tt, doc))
}
@ -113,7 +137,8 @@ fn field_default_expr_and_doc(field: &syn::Field) -> Result<(TokenStream, String
if let Some(default_attr) = DefaultAttr::find_in_attributes(&field.attrs)? {
let conversion_strategy = default_attr.conversion_strategy();
let field_value = default_attr.code.ok_or_else(|| {
Error::new(field.span(), "Expected #[default = ...] or #[default(...)]")})?;
Error::new(field.span(), "Expected #[default = ...] or #[default(...)]")
})?;
let field_value = match conversion_strategy {
ConversionStrategy::NoConversion => field_value,
@ -123,8 +148,11 @@ fn field_default_expr_and_doc(field: &syn::Field) -> Result<(TokenStream, String
let field_doc = format!("{}", field_value);
Ok((field_value, field_doc))
} else {
Ok((quote! {
Default::default()
}, "Default::default()".to_owned()))
Ok((
quote! {
Default::default()
},
"Default::default()".to_owned(),
))
}
}

100
third_party/rust/smart-default/src/default_attr.rs vendored Executable file → Normal file
View File

@ -1,9 +1,8 @@
use proc_macro2::TokenStream;
use syn::parse::Error;
use syn::spanned::Spanned;
use quote::ToTokens;
use syn::{parse::Error, MetaNameValue};
use util::{find_only, single_value};
use crate::util::find_only;
#[derive(Debug, Clone, Copy)]
pub enum ConversionStrategy {
@ -18,49 +17,33 @@ pub struct DefaultAttr {
impl DefaultAttr {
pub fn find_in_attributes(attrs: &[syn::Attribute]) -> Result<Option<Self>, Error> {
if let Some(default_attr) = find_only(attrs.iter(), |attr| is_default_attr(attr))? {
match default_attr.parse_meta() {
Ok(syn::Meta::Path(_)) => Ok(Some(Self {
if let Some(default_attr) =
find_only(attrs.iter(), |attr| Ok(attr.path().is_ident("default")))?
{
match &default_attr.meta {
syn::Meta::Path(_) => Ok(Some(Self {
code: None,
conversion_strategy: None,
})),
Ok(syn::Meta::List(meta)) => {
if let Some(field_value) = parse_code_hack(&meta)? { // #[default(_code = "...")]
syn::Meta::List(meta) => {
// If the meta contains exactly (_code = "...") take the string literal as the
// expression
if let Ok(ParseCodeHack(code_hack)) = syn::parse(meta.tokens.clone().into()) {
Ok(Some(Self {
code: Some(field_value.into_token_stream()),
code: Some(code_hack),
conversion_strategy: Some(ConversionStrategy::NoConversion),
}))
} else if let Some(field_value) = single_value(meta.nested.iter()) { // #[default(...)]
} else {
Ok(Some(Self {
code: Some(field_value.into_token_stream()),
code: Some(meta.tokens.clone()),
conversion_strategy: None,
}))
} else {
return Err(Error::new(
if meta.nested.is_empty() {
meta.span()
} else {
meta.nested.span()
},
"Expected signle value in #[default(...)]"));
}
}
Ok(syn::Meta::NameValue(meta)) => {
Ok(Some(Self {
code: Some(meta.lit.into_token_stream()),
conversion_strategy: None,
}))
}
Err(error) => {
if let syn::Expr::Paren(as_parens) = syn::parse(default_attr.tokens.clone().into())? {
Ok(Some(Self {
code: Some(as_parens.expr.into_token_stream()),
conversion_strategy: None,
}))
} else {
Err(error)
}
}
syn::Meta::NameValue(MetaNameValue { value, .. }) => Ok(Some(Self {
code: Some(value.into_token_stream()),
conversion_strategy: None,
})),
}
} else {
Ok(None)
@ -79,47 +62,28 @@ impl DefaultAttr {
return ConversionStrategy::NoConversion;
};
match syn::parse::<syn::Lit>(code.clone().into()) {
Ok(syn::Lit::Str(_)) | Ok(syn::Lit::ByteStr(_))=> {
Ok(syn::Lit::Str(_)) | Ok(syn::Lit::ByteStr(_)) => {
// A string literal - so we need a conversion in case we need to make it a `String`
return ConversionStrategy::Into;
},
_ => {},
}
_ => {}
}
// Not handled by one of the rules, so we don't convert it to avoid causing trouble
ConversionStrategy::NoConversion
}
}
fn is_default_attr(attr: &syn::Attribute) -> Result<bool, Error> {
let path = &attr.path;
if path.leading_colon.is_some() {
return Ok(false);
}
let segment = if let Some(segment) = single_value(path.segments.iter()) {
segment
} else {
return Ok(false);
};
struct ParseCodeHack(TokenStream);
if let syn::PathArguments::None = segment.arguments {
} else {
return Ok(false);
impl syn::parse::Parse for ParseCodeHack {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let ident: syn::Ident = input.parse()?;
if ident != "_code" {
return Err(Error::new(ident.span(), "Expected `_code`"));
}
input.parse::<syn::token::Eq>()?;
let code: syn::LitStr = input.parse()?;
let code: TokenStream = code.parse()?;
Ok(ParseCodeHack(code))
}
Ok(segment.ident.to_string() == "default")
}
fn parse_code_hack(meta: &syn::MetaList) -> Result<Option<TokenStream>, Error> {
for meta in meta.nested.iter() {
if let syn::NestedMeta::Meta(syn::Meta::NameValue(meta)) = meta {
if !meta.path.is_ident("_code") {
continue;
}
if let syn::Lit::Str(lit) = &meta.lit {
use std::str::FromStr;
return Ok(Some(TokenStream::from_str(&lit.value())?));
}
};
}
Ok(None)
}

19
third_party/rust/smart-default/src/lib.rs vendored Executable file → Normal file
View File

@ -1,9 +1,3 @@
extern crate proc_macro;
extern crate proc_macro2;
extern crate syn;
extern crate quote;
use syn::{parse_macro_input, DeriveInput};
mod body_impl;
@ -12,7 +6,7 @@ mod util;
/// # Smart Default
///
/// This crate provides a custom derive for `SmartDefault`. `SmartDefault` is not a real type -
/// This crate provides a custom derive for `SmartDefault`. `SmartDefault` is not a real trait -
/// deriving it will actually `impl Default`. The difference from regular `#[derive(Default)]` is
/// that `#[derive(SmartDefault)]` allows you to use `#[default = "..."]` attributes to customize
/// the `::default()` method and to support `struct`s that don't have `Default` for all their
@ -21,8 +15,7 @@ mod util;
/// # Examples
///
/// ```
/// #[macro_use]
/// extern crate smart_default;
/// use smart_default::SmartDefault;
///
/// # fn main() {
/// #[derive(SmartDefault)]
@ -74,11 +67,7 @@ mod util;
pub fn derive_smart_default(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let input = parse_macro_input!(input as DeriveInput);
match body_impl::impl_my_derive(&input) {
Ok(output) => {
output.into()
},
Err(error) =>{
error.to_compile_error().into()
}
Ok(output) => output.into(),
Err(error) => error.to_compile_error().into(),
}
}

16
third_party/rust/smart-default/src/util.rs vendored Executable file → Normal file
View File

@ -1,11 +1,12 @@
use syn::spanned::Spanned;
use syn::parse::Error;
use syn::spanned::Spanned;
/// Return the value that fulfills the predicate if there is one in the slice. Panic if there is
/// more than one.
pub fn find_only<T, F>(iter: impl Iterator<Item = T>, pred: F) -> Result<Option<T>, Error>
where T: Spanned,
F: Fn(&T) -> Result<bool, Error>,
where
T: Spanned,
F: Fn(&T) -> Result<bool, Error>,
{
let mut result = None;
for item in iter {
@ -18,12 +19,3 @@ where T: Spanned,
}
Ok(result)
}
pub fn single_value<T>(mut it: impl Iterator<Item = T>) -> Option<T> {
if let Some(result) = it.next() {
if it.next().is_none() {
return Some(result)
}
}
None
}

58
third_party/rust/smart-default/tests/tests.rs vendored Executable file → Normal file
View File

@ -1,5 +1,4 @@
#[macro_use]
extern crate smart_default;
use smart_default::SmartDefault;
#[test]
fn test_unit() {
@ -12,11 +11,9 @@ fn test_unit() {
#[test]
fn test_tuple() {
#[derive(PartialEq, SmartDefault)]
struct Foo (
#[default = 10]
i32,
#[default = 20]
i32,
struct Foo(
#[default = 10] i32,
#[default = 20] i32,
// No default
i32,
);
@ -74,9 +71,7 @@ fn test_enum_of_structs() {
#[derive(PartialEq, SmartDefault)]
pub enum Foo {
#[allow(dead_code)]
Bar {
x: i32,
},
Bar { x: i32 },
#[default]
Baz {
#[default = 10]
@ -84,9 +79,7 @@ fn test_enum_of_structs() {
z: i32,
},
#[allow(dead_code)]
Qux {
w: i32,
},
Qux { w: i32 },
}
assert!(Foo::default() == Foo::Baz { y: 10, z: 0 });
@ -101,9 +94,7 @@ fn test_enum_mixed() {
#[default]
Baz(#[default = 10] i32),
#[allow(dead_code)]
Qux {
w: i32,
},
Qux { w: i32 },
}
assert!(Foo::default() == Foo::Baz(10));
@ -112,9 +103,12 @@ fn test_enum_mixed() {
#[test]
fn test_generics_type_parameters() {
#[derive(PartialEq, SmartDefault)]
struct Foo<T> where T: Default {
struct Foo<T>
where
T: Default,
{
#[default(Some(Default::default()))]
x: Option<T>
x: Option<T>,
}
assert!(Foo::default() == Foo { x: Some(0) });
@ -131,7 +125,7 @@ fn test_generics_lifetime_parameters() {
#[default]
Bar(i32),
#[allow(dead_code)]
Baz(&'a str)
Baz(&'a str),
}
assert!(Foo::default() == Foo::Bar(0));
@ -151,12 +145,26 @@ fn test_code_hack() {
#[test]
fn test_string_conversion() {
#[derive(PartialEq, SmartDefault)]
struct Foo(
#[default = "one"]
&'static str,
#[default("two")]
String,
);
struct Foo(#[default = "one"] &'static str, #[default("two")] String);
assert!(Foo::default() == Foo("one", "two".to_owned()));
}
#[test]
fn test_non_code_hack_valid_meta() {
#[derive(Debug, PartialEq, SmartDefault)]
struct Foo {
#[default(true)]
bar: bool,
#[default(Option::None)]
baz: Option<()>,
}
assert_eq!(
Foo::default(),
Foo {
bar: true,
baz: None
}
);
}