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

Disallow duplicated version requirements #652

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
12 changes: 11 additions & 1 deletion cyclonedx-bom-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use syn::{
fold::{self, Fold},
parse_quote,
punctuated::Punctuated,
spanned::Spanned,
token::Comma,
Error, Expr, Item,
};
Expand Down Expand Up @@ -79,7 +80,16 @@ impl VersionFilter {

if path.is_ident("versioned") {
match attr.parse_args::<VersionReq>() {
Ok(version) => opt_version = Some(version),
Ok(version) => {
if opt_version.is_some() {
self.error = Some(syn::Error::new(
attr.span(),
"found duplicated version requirement",
))
} else {
opt_version = Some(version);
}
}
Err(err) => self.error = Some(err),
}

Expand Down
10 changes: 10 additions & 0 deletions cyclonedx-bom-macros/tests/ui/fail/duplicated_versioned.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cyclonedx_bom_macros::versioned;

#[versioned("1.0", "2.0")]
mod base {
#[versioned("1.0")]
#[versioned("2.0")]
struct Foo;
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: found duplicated version requirement while using the `#[versioned]` macro
--> tests/ui/fail/duplicated_versioned.rs:6:5
|
6 | #[versioned("2.0")]
| ^
Loading