Skip to content

Commit 20e8f43

Browse files
Merge pull request marshallpierce#184 from marshallpierce/mp/cleanup
Clippy fixes
2 parents 57468a6 + f2b42ad commit 20e8f43

File tree

7 files changed

+54
-42
lines changed

7 files changed

+54
-42
lines changed

.circleci/config.yml

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,51 @@ workflows:
88
matrix:
99
parameters:
1010
rust_img: [
11-
# The default rust images (not -slim or -alpine) are based on buildpack-deps. Hopefully this will
12-
# be easier on the CI hosts since presumably those fat lower layers will already be cached, and
13-
# therefore faster than a minimal, customized alpine.
14-
# MSRV
15-
'rust:1.47.0',
16-
# stable
17-
'rust:latest',
18-
'rustlang/rust:nightly'
19-
# would be nice to have beta as well: https://github.com/rust-lang/docker-rust/issues/14
11+
# Yes, a single-parameter axis, but means it can be referred to as a cache parameter easily without
12+
# duplicating the magic version number throughout this file.
13+
# The default rust images (not -slim or -alpine) are based on buildpack-deps. Hopefully this will
14+
# be easier on the CI hosts since presumably those fat lower layers will already be cached, and
15+
# therefore faster than a minimal, customized alpine.
16+
# MSRV
17+
'rust:1.47.0'
18+
]
19+
# a hacky scheme to work around CircleCI's inability to deal with mutable docker tags, forcing us to
20+
# get a nightly or stable toolchain via rustup instead of a mutable docker tag
21+
toolchain_override: [
22+
'__msrv__', # won't add any other toolchains, just uses what's in the docker image
23+
'stable',
24+
'nightly'
2025
]
2126

2227
jobs:
2328
build:
2429
parameters:
2530
rust_img:
2631
type: string
32+
toolchain_override:
33+
type: string
2734
docker:
2835
- image: << parameters.rust_img >>
2936
steps:
3037
- checkout
3138
- restore_cache:
32-
key: project-cache-v3-<< parameters.rust_img >>-{{ checksum "Cargo.toml" }}
39+
key: project-cache-v5-<< parameters.rust_img >>-<< parameters.toolchain_override >>-{{ checksum "Cargo.toml" }}
40+
- run:
41+
name: Setup toolchain
42+
command: |
43+
if [[ '<< parameters.toolchain_override >>' != '__msrv__' ]]
44+
then
45+
rustup toolchain add '<< parameters.toolchain_override >>'
46+
rustup default '<< parameters.toolchain_override >>'
47+
fi
48+
- run:
49+
name: Log rustc version
50+
command: rustc --version
3351
- run:
3452
name: Check formatting
3553
command: |
3654
rustup component add rustfmt
3755
cargo fmt -- --check
38-
- run:
39-
name: Add arm toolchain
40-
command: rustup target add thumbv6m-none-eabi
4156
- run:
4257
name: Build all targets
4358
command: cargo build --all-targets
@@ -47,6 +62,9 @@ jobs:
4762
- run:
4863
name: Build with only alloc
4964
command: cargo build --no-default-features --features alloc
65+
- run:
66+
name: Add arm toolchain
67+
command: rustup target add thumbv6m-none-eabi
5068
- run:
5169
name: Build ARM without default features (no_std)
5270
command: cargo build --target thumbv6m-none-eabi --no-default-features
@@ -60,19 +78,19 @@ jobs:
6078
name: Build docs
6179
command: cargo doc --verbose
6280
- run:
63-
name: Confirm a fuzzer can run
81+
name: Confirm fuzzers can run
6482
# TERM=dumb prevents cargo fuzz list from printing with color
6583
environment:
6684
TERM: dumb
6785
command: |
68-
if [[ '<< parameters.rust_img >>' = 'rustlang/rust:nightly' ]]
86+
if [[ '<< parameters.toolchain_override >>' = 'nightly' ]]
6987
then
7088
cargo install cargo-fuzz
7189
cargo fuzz list | xargs -I FUZZER cargo fuzz run FUZZER -- -max_total_time=1
7290
fi
7391
7492
- save_cache:
75-
key: project-cache-v3-<< parameters.rust_img >>-{{ checksum "Cargo.toml" }}
93+
key: project-cache-v5-<< parameters.rust_img >>-<< parameters.toolchain_override >>-{{ checksum "Cargo.toml" }}
7694
paths:
7795
# rust docker img doesn't use $HOME/[.cargo,.rustup]
7896
- /usr/local/cargo

src/alphabet.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Provides [Alphabet] and constants for alphabets commonly used in the wild.
22
33
use crate::PAD_BYTE;
4+
use core::{convert, fmt};
45
#[cfg(any(feature = "std", test))]
5-
use std::{convert, error, fmt};
6+
use std::error;
67

78
const ALPHABET_SIZE: usize = 64;
89

@@ -43,9 +44,6 @@ impl Alphabet {
4344
/// Create an `Alphabet` from a string of 64 unique printable ASCII bytes.
4445
///
4546
/// The `=` byte is not allowed as it is used for padding.
46-
///
47-
/// The `const`-ness of this function isn't useful as of rust 1.54.0 since `const` `unwrap()`,
48-
/// etc, haven't shipped yet, but that's [on the roadmap](https://github.com/rust-lang/rust/issues/85194).
4947
pub const fn from_str(alphabet: &str) -> Result<Self, ParseAlphabetError> {
5048
let bytes = alphabet.as_bytes();
5149
if bytes.len() != ALPHABET_SIZE {
@@ -95,7 +93,6 @@ impl Alphabet {
9593
}
9694
}
9795

98-
#[cfg(any(feature = "std", test))]
9996
impl convert::TryFrom<&str> for Alphabet {
10097
type Error = ParseAlphabetError;
10198

@@ -117,7 +114,6 @@ pub enum ParseAlphabetError {
117114
ReservedByte(u8),
118115
}
119116

120-
#[cfg(any(feature = "std", test))]
121117
impl fmt::Display for ParseAlphabetError {
122118
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
123119
match self {

src/decode.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ pub fn decode_engine<E: Engine, T: AsRef<[u8]>>(
146146
///}
147147
///```
148148
#[cfg(any(feature = "alloc", feature = "std", test))]
149-
pub fn decode_engine_vec<'e, 'o, E: Engine, T: AsRef<[u8]>>(
149+
pub fn decode_engine_vec<E: Engine, T: AsRef<[u8]>>(
150150
input: T,
151-
buffer: &'o mut Vec<u8>,
152-
engine: &'e E,
151+
buffer: &mut Vec<u8>,
152+
engine: &E,
153153
) -> Result<(), DecodeError> {
154154
let input_bytes = input.as_ref();
155155

@@ -184,10 +184,10 @@ pub fn decode_engine_vec<'e, 'o, E: Engine, T: AsRef<[u8]>>(
184184
/// # Panics
185185
///
186186
/// If the slice is not large enough, this will panic.
187-
pub fn decode_engine_slice<'e, 'o, E: Engine, T: AsRef<[u8]>>(
187+
pub fn decode_engine_slice<E: Engine, T: AsRef<[u8]>>(
188188
input: T,
189-
output: &'o mut [u8],
190-
engine: &'e E,
189+
output: &mut [u8],
190+
engine: &E,
191191
) -> Result<usize, DecodeError> {
192192
let input_bytes = input.as_ref();
193193

src/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ pub fn encode_engine_slice<E: Engine, T: AsRef<[u8]>>(
151151
let encoded_size = encoded_len(input_bytes.len(), engine.config().encode_padding())
152152
.expect("usize overflow when calculating buffer size");
153153

154-
let mut b64_output = &mut output_buf[0..encoded_size];
154+
let b64_output = &mut output_buf[0..encoded_size];
155155

156-
encode_with_padding(&input_bytes, &mut b64_output, engine, encoded_size);
156+
encode_with_padding(input_bytes, b64_output, engine, encoded_size);
157157

158158
encoded_size
159159
}

src/engine/fast_portable/decode.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,13 +319,11 @@ fn decode_chunk(
319319
decode_table: &[u8; 256],
320320
output: &mut [u8],
321321
) -> Result<(), DecodeError> {
322-
let mut accum: u64;
323-
324322
let morsel = decode_table[input[0] as usize];
325323
if morsel == INVALID_VALUE {
326324
return Err(DecodeError::InvalidByte(index_at_start_of_input, input[0]));
327325
}
328-
accum = (morsel as u64) << 58;
326+
let mut accum: u64 = (morsel as u64) << 58;
329327

330328
let morsel = decode_table[input[1] as usize];
331329
if morsel == INVALID_VALUE {

src/engine/fast_portable/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ impl FastPortable {
2727
/// if the engine will be used repeatedly.
2828
pub const fn from(alphabet: &Alphabet, config: FastPortableConfig) -> FastPortable {
2929
FastPortable {
30-
encode_table: encode_table(&alphabet),
31-
decode_table: decode_table(&alphabet),
30+
encode_table: encode_table(alphabet),
31+
decode_table: decode_table(alphabet),
3232
config,
3333
}
3434
}
@@ -194,7 +194,7 @@ pub(crate) const fn encode_table(alphabet: &Alphabet) -> [u8; 64] {
194194
}
195195
}
196196

197-
return encode_table;
197+
encode_table
198198
}
199199

200200
/// Returns a table mapping base64 bytes as the lookup index to either:
@@ -213,7 +213,7 @@ pub(crate) const fn decode_table(alphabet: &Alphabet) -> [u8; 256] {
213213
index += 1;
214214
}
215215

216-
return decode_table;
216+
decode_table
217217
}
218218

219219
#[inline]

src/read/decoder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'e, E: Engine, R: io::Read> DecoderReader<'e, E, R> {
9090
/// Returns a Result with the number of (decoded) bytes copied.
9191
fn flush_decoded_buf(&mut self, buf: &mut [u8]) -> io::Result<usize> {
9292
debug_assert!(self.decoded_len > 0);
93-
debug_assert!(buf.len() > 0);
93+
debug_assert!(!buf.is_empty());
9494

9595
let copy_len = cmp::min(self.decoded_len, buf.len());
9696
debug_assert!(copy_len > 0);
@@ -121,7 +121,7 @@ impl<'e, E: Engine, R: io::Read> DecoderReader<'e, E, R> {
121121

122122
debug_assert!(self.b64_offset + self.b64_len <= BUF_SIZE);
123123

124-
return Ok(read);
124+
Ok(read)
125125
}
126126

127127
/// Decode the requested number of bytes from the b64 buffer into the provided buffer. It's the
@@ -131,11 +131,11 @@ impl<'e, E: Engine, R: io::Read> DecoderReader<'e, E, R> {
131131
fn decode_to_buf(&mut self, num_bytes: usize, buf: &mut [u8]) -> io::Result<usize> {
132132
debug_assert!(self.b64_len >= num_bytes);
133133
debug_assert!(self.b64_offset + self.b64_len <= BUF_SIZE);
134-
debug_assert!(buf.len() > 0);
134+
debug_assert!(!buf.is_empty());
135135

136136
let decoded = decode_engine_slice(
137137
&self.b64_buffer[self.b64_offset..self.b64_offset + num_bytes],
138-
&mut buf[..],
138+
buf,
139139
self.engine,
140140
)
141141
.map_err(|e| match e {
@@ -183,7 +183,7 @@ impl<'e, E: Engine, R: Read> Read for DecoderReader<'e, E, R> {
183183
/// Any errors emitted by the delegate reader are returned. Decoding errors due to invalid
184184
/// base64 are also possible, and will have `io::ErrorKind::InvalidData`.
185185
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
186-
if buf.len() == 0 {
186+
if buf.is_empty() {
187187
return Ok(0);
188188
}
189189

0 commit comments

Comments
 (0)