Skip to content

Commit

Permalink
Enable edition 2018 (#57)
Browse files Browse the repository at this point in the history
* Update MSRV in CI and Readme from 1.29 to 1.41.1

It seems we have consensus within the rust-bitcoin github organisation
on bumping the MSRV to 1.41.1, update CI job and the README to reflect
this.

* Update to use edition 2018

Add `edition = 2018` to the manifest file. No further changes were
necessary.

* Remove unneeded reference

Clippy emits:

  error: this expression borrows a reference (`&str`) that is
  immediately dereferenced by the compiler

As suggested, remove the unneeded reference.

* Use long literal separators

Clippy emits:

 warning: long literal lacking separators

As suggested, use separators.

* Use contains combinator instead of manual impl

Clippy emits:

 warning: manual `!RangeInclusive::contains` implementation

Use the code snippets suggested by clippy.

* Allow type_complexity

Clippy emits:

 warning: very complex type used. Consider factoring parts into `type` definitions

This code is in a unit test, its clear enough for the purpose.

Configure clippy to allow type_complexity

* Bump version 0.8.1 -> 0.9.0

We just bumped the MSRV, this is a major change but since we are pre 1.0
we just have to bump the minor version number.

Bump version from current `0.8.1` to `0.9.0`.
  • Loading branch information
tcharding committed May 13, 2022
1 parent e063fe7 commit 9a57c97
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
rust:
- 1.29.0
- 1.41.1
- stable
- nightly
steps:
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "bech32"
version = "0.8.1"
version = "0.9.0"
authors = ["Clark Moody"]
repository = "https://github.com/rust-bitcoin/rust-bech32"
description = "Encodes and decodes the Bech32 format"
readme = "README.md"
keywords = ["base32", "encoding", "bech32"]
categories = ["encoding"]
license = "MIT"
edition = "2018"

[features]
default = ["std"]
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ You can find some usage examples in the [documentation](https://docs.rs/bech32/)
Bitcoin-specific address encoding is handled by the `bitcoin-bech32` crate.

# MSRV
The minimum supported Rust version with the standard library is **1.29**.

With nostd, we use the `alloc` dependency, so the MSRV is instead **1.36**.
The minimum supported Rust version with the standard library is **1.41.1**.

2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.29.0"
msrv = "1.41.1"
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ fn check_hrp(hrp: &str) -> Result<Case, Error> {
let mut has_upper: bool = false;
for b in hrp.bytes() {
// Valid subset of ASCII
if b < 33 || b > 126 {
if !(33..=126).contains(&b) {
return Err(Error::InvalidChar(b as char));
}

if b >= b'a' && b <= b'z' {
if (b'a'..=b'z').contains(&b) {
has_lower = true;
} else if b >= b'A' && b <= b'Z' {
} else if (b'A'..=b'Z').contains(&b) {
has_upper = true;
};

Expand Down Expand Up @@ -406,7 +406,7 @@ pub fn encode_to_fmt<T: AsRef<[u5]>>(
data: T,
variant: Variant,
) -> Result<fmt::Result, Error> {
let hrp_lower = match check_hrp(&hrp)? {
let hrp_lower = match check_hrp(hrp)? {
Case::Upper => Cow::Owned(hrp.to_lowercase()),
Case::Lower | Case::None => Cow::Borrowed(hrp),
};
Expand All @@ -432,7 +432,7 @@ pub enum Variant {
}

const BECH32_CONST: u32 = 1;
const BECH32M_CONST: u32 = 0x2bc830a3;
const BECH32M_CONST: u32 = 0x2bc8_30a3;

impl Variant {
// Produce the variant based on the remainder of the polymod operation
Expand Down Expand Up @@ -485,7 +485,7 @@ pub fn decode(s: &str) -> Result<(String, Vec<u5>, Variant), Error> {
return Err(Error::InvalidLength);
}

let mut case = check_hrp(&raw_hrp)?;
let mut case = check_hrp(raw_hrp)?;
let hrp_lower = match case {
Case::Upper => raw_hrp.to_lowercase(),
// already lowercase
Expand Down Expand Up @@ -520,7 +520,7 @@ pub fn decode(s: &str) -> Result<(String, Vec<u5>, Variant), Error> {
// c should be <128 since it is in the ASCII range, CHARSET_REV.len() == 128
let num_value = CHARSET_REV[c as usize];

if num_value > 31 || num_value < 0 {
if !(0..=31).contains(&num_value) {
return Err(Error::InvalidChar(c));
}

Expand All @@ -529,7 +529,7 @@ pub fn decode(s: &str) -> Result<(String, Vec<u5>, Variant), Error> {
.collect::<Result<Vec<u5>, Error>>()?;

// Ensure checksum
match verify_checksum(&hrp_lower.as_bytes(), &data) {
match verify_checksum(hrp_lower.as_bytes(), &data) {
Some(variant) => {
// Remove checksum from data payload
let dbl: usize = data.len();
Expand Down Expand Up @@ -803,6 +803,7 @@ mod tests {
}

#[test]
#[allow(clippy::type_complexity)]
fn valid_conversion() {
// Set of [data, from_bits, to_bits, pad, result]
let tests: Vec<(Vec<u8>, u32, u32, bool, Vec<u8>)> = vec![
Expand Down

0 comments on commit 9a57c97

Please sign in to comment.