You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rust-err-derive/0001-Move-to-proc-macro-err...

242 lines
9.5 KiB

diff -up err-derive-0.2.1/build.rs.orig err-derive-0.2.1/build.rs
--- err-derive-0.2.1/build.rs.orig 2019-10-09 12:21:01.000000000 +0200
+++ err-derive-0.2.1/build.rs 2019-12-06 22:41:25.114969835 +0100
@@ -1,22 +1,7 @@
-use rustc_version::version;
-
-fn version_ge(minor_min: u64) -> bool {
- let version = version().unwrap();
-
- version.major == 1 && version.minor >= minor_min
-}
+#[rustversion::before(1.32)]
+compile_error!("`err-derive` depends on `skeptic`, which requires rustc >= 1.32");
fn main() {
- if !version_ge(32) {
- panic!("`err-derive` depends on `quote 1.0`, which requires rustc >= 1.32");
- }
- generate_doc_tests()
-}
-
-#[cfg(feature = "skeptic")]
-fn generate_doc_tests() {
+ #[cfg(feature = "skeptic")]
skeptic::generate_doc_tests(&["README.md"]);
}
-
-#[cfg(not(feature = "skeptic"))]
-fn generate_doc_tests() { }
diff -up err-derive-0.2.1/Cargo.toml.orig err-derive-0.2.1/Cargo.toml
--- err-derive-0.2.1/Cargo.toml.orig 2019-12-06 22:41:25.113969837 +0100
+++ err-derive-0.2.1/Cargo.toml 2019-12-06 22:42:14.978892161 +0100
@@ -40,8 +40,8 @@ version = "1.0.5"
version = "0.12.0"
[dev-dependencies.skeptic]
version = "0.13"
-[build-dependencies.rustc_version]
-version = "0.2.3"
+[build-dependencies.rustversion]
+version = "1.0"
[build-dependencies.skeptic]
version = "0.13"
diff -up err-derive-0.2.1/src/lib.rs.orig err-derive-0.2.1/src/lib.rs
--- err-derive-0.2.1/src/lib.rs.orig 2019-10-09 13:08:03.000000000 +0200
+++ err-derive-0.2.1/src/lib.rs 2019-12-06 22:41:25.115969834 +0100
@@ -132,21 +132,13 @@ use syn::spanned::Spanned;
extern crate proc_macro_error;
-use proc_macro_error::{filter_macro_errors, span_error};
+use proc_macro_error::{abort, proc_macro_error};
use syn::Attribute;
decl_derive!([Error, attributes(error, source, cause)] => error_derive);
+#[proc_macro_error(allow_not_macro, assert_unwind_safe)]
fn error_derive(s: synstructure::Structure) -> TokenStream {
- // proc_macro_error requires all `quote!` call to be inside the `filter_macro_errors!` macro,
- // by using an inner method we satisfy this requirement while still getting proper syntax
- // highlighting
- filter_macro_errors! {
- error_derive_inner(s).into()
- }
-}
-
-fn error_derive_inner(s: synstructure::Structure) -> TokenStream2 {
let source_body = s.each_variant(|v| {
if let Some(source) = v.bindings().iter().find(|binding| {
has_attr(&binding.ast().attrs, "source") || has_attr(&binding.ast().attrs, "cause")
@@ -205,11 +197,7 @@ fn error_derive_inner(s: synstructure::S
let from = from_body(&s);
- quote! {
- #error
- #display
- #from
- }
+ quote!(#error #display #from).into()
}
fn display_body(s: &synstructure::Structure) -> quote::__rt::TokenStream {
@@ -217,10 +205,10 @@ fn display_body(s: &synstructure::Struct
let span = v.ast().ident.span();
let msg = match find_error_msg(&v.ast().attrs) {
Some(msg) => msg,
- None => span_error!(span, "Variant is missing display attribute."),
+ None => abort!(span, "Variant is missing display attribute."),
};
if msg.nested.is_empty() {
- span_error!(span, "Expected at least one argument to error attribute");
+ abort!(span, "Expected at least one argument to error attribute");
}
let format_string = match msg.nested[0] {
@@ -232,7 +220,7 @@ fn display_body(s: &synstructure::Struct
{
nv.lit.clone()
}
- _ => span_error!(
+ _ => abort!(
msg.nested.span(),
"Error attribute must begin `display = \"\"` to control the Display message."
),
@@ -241,14 +229,14 @@ fn display_body(s: &synstructure::Struct
syn::NestedMeta::Lit(syn::Lit::Int(ref i)) => {
let bi = &v.bindings()[i
.base10_parse::<usize>()
- .unwrap_or_else(|_| span_error!(i.span(), "integer literal overflows usize"))];
+ .unwrap_or_else(|_| abort!(i.span(), "integer literal overflows usize"))];
quote!(#bi)
}
syn::NestedMeta::Meta(syn::Meta::Path(ref path)) => {
let id = match path.get_ident() {
Some(id) => id,
// Allows std::u8::MAX (for example)
- None => return quote!(#arg)
+ None => return quote!(#arg),
};
let id_s = id.to_string();
if id_s.starts_with('_') {
@@ -256,7 +244,7 @@ fn display_body(s: &synstructure::Struct
let bi = match v.bindings().get(idx) {
Some(bi) => bi,
None => {
- span_error!(
+ abort!(
id.span(),
"display attempted to access field `{}` in `{}::{}` which \
does not exist (there {} {} field{})",
@@ -279,10 +267,10 @@ fn display_body(s: &synstructure::Struct
}
// Arg is not a field - might be in global scope
return quote!(#id);
- },
+ }
// Allows u8::max_value() (for example)
syn::NestedMeta::Meta(syn::Meta::List(ref list)) => return quote!(#list),
- _ => span_error!(msg.nested.span(), "Invalid argument to error attribute!"),
+ _ => abort!(msg.nested.span(), "Invalid argument to error attribute!"),
});
quote! {
@@ -302,11 +290,11 @@ fn find_error_msg(attrs: &[syn::Attribut
{
let span = attr.span();
if error_msg.is_some() {
- span_error!(span, "Cannot have two display attributes")
+ abort!(span, "Cannot have two display attributes")
} else if let syn::Meta::List(list) = meta {
error_msg = Some(list);
} else {
- span_error!(span, "error attribute must take a list in parentheses")
+ abort!(span, "error attribute must take a list in parentheses")
}
}
}
@@ -324,7 +312,7 @@ fn has_attr(attributes: &[Attribute], at
.map_or(false, |ident| ident == attr_name)
{
if found_attr {
- span_error!(attr.span(), "Cannot have two `{}` attributes", attr_name);
+ abort!(attr.span(), "Cannot have two `{}` attributes", attr_name);
}
found_attr = true;
}
@@ -341,7 +329,7 @@ fn has_attr(attributes: &[Attribute], at
ident.to_string().split(", ").any(|part| part == attr_name)
}) {
if found_attr {
- span_error!(
+ abort!(
path.span(),
"Cannot have two `{}` attributes",
attr_name
@@ -371,7 +359,7 @@ fn from_body(s: &synstructure::Structure
let exclude = has_attr(&binding.ast().attrs, "no_from");
if is_source && is_cause {
- span_error!(
+ abort!(
span,
"#[error(cause)] is deprecated, use #[error(source)] instead"
)
@@ -387,7 +375,7 @@ fn from_body(s: &synstructure::Structure
}) {
if v.bindings().len() > 1 {
if is_explicit {
- span_error!(
+ abort!(
span,
"Variants containing `from` can only contain a single field"
);
@@ -402,15 +390,18 @@ fn from_body(s: &synstructure::Structure
.iter()
.any(|existing_from_type| *existing_from_type == from_ident)
{
- span_error!(
- from_ident.span(),
- "`from` can only be applied for a type once{}",
- if is_explicit {
- ""
- } else {
- ", hint: use #[error(no_from)] to disable automatic From derive"
- }
- );
+ if is_explicit {
+ abort!(
+ from_ident.span(),
+ "`from` can only be applied for a type once"
+ );
+ } else {
+ abort!(
+ from_ident.span(),
+ "`from` can only be applied for a type once";
+ hint = "use #[error(no_from)] to disable automatic From derive"
+ );
+ }
}
from_types.push(from_ident);
diff -up err-derive-0.2.1/tests/tests.rs.orig err-derive-0.2.1/tests/tests.rs
--- err-derive-0.2.1/tests/tests.rs.orig 2019-10-08 21:38:59.000000000 +0200
+++ err-derive-0.2.1/tests/tests.rs 2019-12-06 22:41:25.115969834 +0100
@@ -125,7 +125,7 @@ pub enum TestsNonFieldDisplayValues {
#[error(display = "{}", u8::max_value())]
D,
#[error(display = "{}", std::u8::MAX)]
- E
+ E,
}
impl TestsNonFieldDisplayValues {
@@ -156,4 +156,4 @@ fn non_field_display() {
let s = format!("{}", TestsNonFieldDisplayValues::E);
assert_eq!(&s, "255");
-}
\ No newline at end of file
+}