From 2d85c0cd911457b1471f43f73028b33855366272 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 17 Feb 2024 16:11:56 +0000 Subject: [PATCH] Fix name collision and CI issues (#15) --- src/ast.rs | 5 ++--- src/lib.rs | 2 +- src/span.rs | 12 ++++++++++++ src/span_ext.rs | 28 ---------------------------- tests/ui/missing_discriminant.stderr | 2 +- 5 files changed, 16 insertions(+), 33 deletions(-) create mode 100644 src/span.rs delete mode 100644 src/span_ext.rs diff --git a/src/ast.rs b/src/ast.rs index 2b382a4..f190010 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -7,7 +7,6 @@ use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::{Attribute, DataEnum, Expr, Fields, Meta, Token}; -use crate::span_ext::SpanExt; use crate::Result; pub struct Repr { @@ -114,10 +113,10 @@ pub fn get_variants(enum_ident: &Ident, data: DataEnum) -> Result> for v in err_iter { if !matches!(&v.fields, Fields::Unit) { - diag = diag.span_error(v.fields.span(), "only unit variants are supported"); + diag = diag.span_warning(v.fields.span(), "only unit variants are supported"); } if v.discriminant.is_none() { - diag = diag.span_error(v.span().end(), "missing discriminant"); + diag = diag.span_warning(crate::span::end(v.span()), "missing discriminant"); } } diff --git a/src/lib.rs b/src/lib.rs index 10f37cb..6b15169 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,7 +4,7 @@ extern crate proc_macro; mod ast; mod expand; -mod span_ext; +mod span; use proc_macro::TokenStream; use proc_macro2_diagnostics::Diagnostic; diff --git a/src/span.rs b/src/span.rs new file mode 100644 index 0000000..a8b2750 --- /dev/null +++ b/src/span.rs @@ -0,0 +1,12 @@ +use proc_macro2::Span; + +pub fn end(span: Span) -> Span { + #[cfg(proc_macro_span)] + { + Span::from(span.unwrap().end()) + } + #[cfg(not(proc_macro_span))] + { + span + } +} diff --git a/src/span_ext.rs b/src/span_ext.rs deleted file mode 100644 index 333b2bb..0000000 --- a/src/span_ext.rs +++ /dev/null @@ -1,28 +0,0 @@ -use proc_macro2::Span; - -pub trait SpanExt { - fn start(&self) -> Span; - fn end(&self) -> Span; -} - -#[cfg(proc_macro_span)] -impl SpanExt for Span { - fn start(&self) -> Span { - std::panic::catch_unwind(|| Span::from(self.unwrap().start())).unwrap_or(*self) - } - - fn end(&self) -> Span { - std::panic::catch_unwind(|| Span::from(self.unwrap().end())).unwrap_or(*self) - } -} - -#[cfg(not(proc_macro_span))] -impl SpanExt for Span { - fn start(&self) -> Span { - *self - } - - fn end(&self) -> Span { - *self - } -} diff --git a/tests/ui/missing_discriminant.stderr b/tests/ui/missing_discriminant.stderr index 4af393e..40a536c 100644 --- a/tests/ui/missing_discriminant.stderr +++ b/tests/ui/missing_discriminant.stderr @@ -6,7 +6,7 @@ error: enum has variants that are not supported by this trait 5 | pub enum MissingDiscriminant { | ^^^^^^^^^^^^^^^^^^^ | -error: missing discriminant +warning: missing discriminant --> tests/ui/missing_discriminant.rs:7:19 | 7 | NoDiscriminant,