Skip to content

Commit 81a70dd

Browse files
authored
Update (#38)
* Fix 1.53 lints This bumps the MSRV to 1.53, but this crate doesn't have a ton of dependencies, and most of them are using 0.3.x in any case. * Fixup changelog * Replace difference with similar-asserts * Add MSRV to README + CI * Update CHANGELOG * Remove unneeded ignore
1 parent 3c9624a commit 81a70dd

File tree

11 files changed

+59
-62
lines changed

11 files changed

+59
-62
lines changed

.github/workflows/ci.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ jobs:
3434
- uses: actions/checkout@v2
3535
- uses: EmbarkStudios/cargo-deny-action@v1
3636

37+
msrv-check:
38+
name: Minimum Stable Rust Version Check
39+
runs-on: ubuntu-20.04
40+
steps:
41+
- uses: actions/checkout@v2
42+
- uses: actions-rs/toolchain@v1
43+
with:
44+
toolchain: "1.53.0"
45+
override: true
46+
- run: cargo fetch
47+
- name: cargo check
48+
run: cargo check --all-targets
49+
3750
test:
3851
name: Test
3952
strategy:

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
<!-- next-header -->
88
## [Unreleased] - ReleaseDate
9+
### Changed
10+
- [PR#38](https://github.com/EmbarkStudios/spdx/pull/38) fixed various clippy lints which also bumps the MSRV to [1.53.0](https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html). Previously, PR#37 had bumped the MSRV to 1.52 so now this crate will check the MSRV so changes are intentional.
11+
- [PR#38](https://github.com/EmbarkStudios/spdx/pull/38) replaced the unmaintained `difference` crate with `similar-asserts`.
12+
913
## [0.4.1] - 2021-06-14
1014
### Changed
1115
- [PR#37](https://github.com/EmbarkStudios/spdx/pull/37) removed the dependencies on regex and lazy_static used for parsing some license expression parts, which gives a nice compile speed up with no behavior changes. Thanks [@Swagadon](https://github.com/Swagadon)!
@@ -51,9 +55,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5155
- The `GFDL*` licenses are now marked as copyleft
5256

5357
### Fixed
54-
- When creating a `LicenseReq` from a GNU license, the license identifier is converted into its base form,
55-
eg. `GPL-2.0-or-later` becomes `GPL-2.0+` so that the GNU style license identifiers can be used just the same
56-
as all of the other ones. See [this issue](https://github.com/EmbarkStudios/cargo-deny/issues/55)
58+
- When creating a `LicenseReq` from a GNU license, the license identifier is converted into its base form, eg. `GPL-2.0-or-later` becomes `GPL-2.0+` so that the GNU style license identifiers can be used just the same as all of the other ones. See [this issue](https://github.com/EmbarkStudios/cargo-deny/issues/55)
5759

5860
## [0.2.4] - 2019-11-25
5961
### Added

Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ include = [
1919
]
2020

2121
[dependencies]
22+
# In most cases expressions are quite small so we can avoid heap allocations
2223
smallvec = "1.6"
2324

2425
[dev-dependencies]
25-
difference = "2.0"
26+
# Used to print colored diffs in case of test failures
27+
similar-asserts = "1.1"

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Embark](https://img.shields.io/badge/discord-ark-%237289da.svg?logo=discord)](https://discord.gg/dAuKfZS)
55
[![Crates.io](https://img.shields.io/crates/v/spdx.svg)](https://crates.io/crates/spdx)
66
[![Docs](https://docs.rs/spdx/badge.svg)](https://docs.rs/spdx)
7+
[![Minimum Stable Rust Version](https://img.shields.io/badge/Rust-1.53.0-blue?color=fc8d62&logo=rust)](https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html)
78
[![SPDX Version](https://img.shields.io/badge/SPDX%20Version-3.11-blue.svg)](https://spdx.org/licenses/)
89
[![dependency status](https://deps.rs/repo/github/EmbarkStudios/spdx/status.svg)](https://deps.rs/repo/github/EmbarkStudios/spdx)
910
[![Build Status](https://github.com/EmbarkStudios/spdx/workflows/CI/badge.svg)](https://github.com/EmbarkStudios/spdx/actions?workflow=CI)

deny.toml

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ vulnerability = "deny"
44
unsound = "deny"
55
yanked = "deny"
66
ignore = [
7-
# difference is unmaintained but it works and is only a dev dependency
8-
"RUSTSEC-2020-0095",
97
]
108

119
[bans]

src/expression/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Expression {
8787
pub fn requirements(&self) -> impl Iterator<Item = &ExpressionReq> {
8888
self.expr.iter().filter_map(|item| match item {
8989
ExprNode::Req(req) => Some(req),
90-
_ => None,
90+
ExprNode::Op(_op) => None,
9191
})
9292
}
9393

src/expression/parser.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,11 @@ impl Expression {
7676

7777
let make_err_for_token = |last_token: Option<Token<'_>>, span: std::ops::Range<usize>| {
7878
let expected: &[&str] = match last_token {
79-
None | Some(Token::And) | Some(Token::Or) | Some(Token::OpenParen) => {
80-
&["<license>", "("]
81-
}
79+
None | Some(Token::And | Token::Or | Token::OpenParen) => &["<license>", "("],
8280
Some(Token::CloseParen) => &["AND", "OR"],
8381
Some(Token::Exception(_)) => &["AND", "OR", ")"],
8482
Some(Token::Spdx(_)) => &["AND", "OR", "WITH", ")", "+"],
85-
Some(Token::LicenseRef { .. }) | Some(Token::Plus) => &["AND", "OR", "WITH", ")"],
83+
Some(Token::LicenseRef { .. } | Token::Plus) => &["AND", "OR", "WITH", ")"],
8684
Some(Token::With) => &["<exception>"],
8785
};
8886

@@ -98,7 +96,7 @@ impl Expression {
9896
let lt = tok?;
9997
match &lt.token {
10098
Token::Spdx(id) => match last_token {
101-
None | Some(Token::And) | Some(Token::Or) | Some(Token::OpenParen) => {
99+
None | Some(Token::And | Token::Or | Token::OpenParen) => {
102100
expr_queue.push(ExprNode::Req(ExpressionReq {
103101
req: LicenseReq::from(*id),
104102
span: lt.span.start as u32..lt.span.end as u32,
@@ -107,7 +105,7 @@ impl Expression {
107105
_ => return make_err_for_token(last_token, lt.span),
108106
},
109107
Token::LicenseRef { doc_ref, lic_ref } => match last_token {
110-
None | Some(Token::And) | Some(Token::Or) | Some(Token::OpenParen) => {
108+
None | Some(Token::And | Token::Or | Token::OpenParen) => {
111109
expr_queue.push(ExprNode::Req(ExpressionReq {
112110
req: LicenseReq {
113111
license: LicenseItem::Other {
@@ -147,15 +145,17 @@ impl Expression {
147145
_ => return make_err_for_token(last_token, lt.span),
148146
},
149147
Token::With => match last_token {
150-
Some(Token::Spdx(_)) | Some(Token::LicenseRef { .. }) | Some(Token::Plus) => {}
148+
Some(Token::Spdx(_) | Token::LicenseRef { .. } | Token::Plus) => {}
151149
_ => return make_err_for_token(last_token, lt.span),
152150
},
153151
Token::Or | Token::And => match last_token {
154-
Some(Token::Spdx(_))
155-
| Some(Token::LicenseRef { .. })
156-
| Some(Token::CloseParen)
157-
| Some(Token::Exception(_))
158-
| Some(Token::Plus) => {
152+
Some(
153+
Token::Spdx(_)
154+
| Token::LicenseRef { .. }
155+
| Token::CloseParen
156+
| Token::Exception(_)
157+
| Token::Plus,
158+
) => {
159159
let new_op = match lt.token {
160160
Token::Or => Op::Or,
161161
Token::And => Op::And,
@@ -171,7 +171,7 @@ impl Expression {
171171

172172
match top.op {
173173
Op::And | Op::Or => apply_op(top, &mut expr_queue)?,
174-
_ => unreachable!(),
174+
Op::Open => unreachable!(),
175175
}
176176
} else {
177177
break;
@@ -188,7 +188,7 @@ impl Expression {
188188
_ => return make_err_for_token(last_token, lt.span),
189189
},
190190
Token::OpenParen => match last_token {
191-
None | Some(Token::And) | Some(Token::Or) | Some(Token::OpenParen) => {
191+
None | Some(Token::And | Token::Or | Token::OpenParen) => {
192192
op_stack.push(OpAndSpan {
193193
op: Op::Open,
194194
span: lt.span,
@@ -198,11 +198,13 @@ impl Expression {
198198
},
199199
Token::CloseParen => {
200200
match last_token {
201-
Some(Token::Spdx(_))
202-
| Some(Token::LicenseRef { .. })
203-
| Some(Token::Plus)
204-
| Some(Token::Exception(_))
205-
| Some(Token::CloseParen) => {
201+
Some(
202+
Token::Spdx(_)
203+
| Token::LicenseRef { .. }
204+
| Token::Plus
205+
| Token::Exception(_)
206+
| Token::CloseParen,
207+
) => {
206208
while let Some(top) = op_stack.pop() {
207209
match top.op {
208210
Op::And | Op::Or => apply_op(top, &mut expr_queue)?,
@@ -241,11 +243,13 @@ impl Expression {
241243

242244
// Validate that the terminating token is valid
243245
match last_token {
244-
Some(Token::Spdx(_))
245-
| Some(Token::LicenseRef { .. })
246-
| Some(Token::Exception(_))
247-
| Some(Token::CloseParen)
248-
| Some(Token::Plus) => {}
246+
Some(
247+
Token::Spdx(_)
248+
| Token::LicenseRef { .. }
249+
| Token::Exception(_)
250+
| Token::CloseParen
251+
| Token::Plus,
252+
) => {}
249253
// We have to have at least one valid license requirement
250254
None => {
251255
return Err(ParseError {

src/lexer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl<'a> Lexer<'a> {
112112
}
113113
}
114114

115+
#[inline]
115116
fn is_ref_char(c: &char) -> bool {
116117
c.is_ascii_alphanumeric() || *c == '-' || *c == '.'
117118
}
@@ -134,6 +135,7 @@ impl<'a> Lexer<'a> {
134135
}
135136

136137
/// Return a license ref if found - equivalent to the regex `^LicenseRef-([-a-zA-Z0-9.]+)`
138+
#[inline]
137139
fn find_license_ref(text: &'a str) -> Option<&'a str> {
138140
Self::find_ref("LicenseRef-", text)
139141
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl LicenseItem {
309309
pub fn id(&self) -> Option<LicenseId> {
310310
match self {
311311
Self::Spdx { id, .. } => Some(*id),
312-
_ => None,
312+
Self::Other { .. } => None,
313313
}
314314
}
315315
}

src/licensee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ mod test {
272272
.license
273273
{
274274
LicenseItem::Spdx { id, .. } => assert_eq!(*id, mpl_id),
275-
o => panic!("unexepcted {:?}", o),
275+
o @ LicenseItem::Other { .. } => panic!("unexpected {:?}", o),
276276
}
277277
}
278278

@@ -356,7 +356,7 @@ mod test {
356356
.license
357357
{
358358
LicenseItem::Spdx { id, .. } => assert_eq!(*id, lic_id),
359-
o => panic!("unexepcted {:?}", o),
359+
o @ LicenseItem::Other { .. } => panic!("unexpected {:?}", o),
360360
}
361361
}
362362
}

tests/validation.rs

+3-28
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@ macro_rules! test_validate {
88

99
$(
1010
let actual = reqs.next().unwrap();
11-
println!("{:?}", actual);
12-
1311
let actual_str = format!("{}", actual.1.req);
1412
let expected_str = $expected;
1513

16-
if actual_str != expected_str {
17-
assert!(
18-
false,
19-
"failed @ index {} - {}",
20-
actual.0,
21-
difference::Changeset::new(expected_str, &actual_str, " ")
22-
);
23-
}
14+
similar_asserts::assert_eq!(actual_str, expected_str, "failed @ index {}", actual.0);
2415
)+
2516

2617
if let Some((_, additional)) = reqs.next() {
@@ -40,15 +31,7 @@ macro_rules! err {
4031
reason: spdx::error::Reason::$reason,
4132
};
4233

43-
if act_err != expected {
44-
let act_text = format!("{:?}", act_err);
45-
let exp_text = format!("{:?}", expected);
46-
assert!(
47-
false,
48-
"{}",
49-
difference::Changeset::new(&exp_text, &act_text, "")
50-
);
51-
}
34+
similar_asserts::assert_eq!(act_err, expected);
5235
};
5336

5437
($text:expr => $unexpected:expr; $range:expr) => {
@@ -60,15 +43,7 @@ macro_rules! err {
6043
reason: spdx::error::Reason::Unexpected($unexpected),
6144
};
6245

63-
if act_err != expected {
64-
let act_text = format!("{:?}", act_err);
65-
let exp_text = format!("{:?}", expected);
66-
assert!(
67-
false,
68-
"{}",
69-
difference::Changeset::new(&exp_text, &act_text, "")
70-
);
71-
}
46+
similar_asserts::assert_eq!(act_err, expected);
7247
};
7348
}
7449

0 commit comments

Comments
 (0)