Skip to content

Commit

Permalink
style: clean up some recent lint violations
Browse files Browse the repository at this point in the history
It looks like `dead_code` got a little smarter, and more pervasively,
some new lint that detects superfluous imports found a bunch of them.
  • Loading branch information
BurntSushi committed Feb 26, 2024
1 parent d7f9347 commit 10fe722
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 72 deletions.
2 changes: 1 addition & 1 deletion regex-automata/src/dfa/dense.rs
Expand Up @@ -9,7 +9,7 @@ This module also contains a [`dense::Builder`](Builder) and a

#[cfg(feature = "dfa-build")]
use core::cmp;
use core::{convert::TryFrom, fmt, iter, mem::size_of, slice};
use core::{fmt, iter, mem::size_of, slice};

#[cfg(feature = "dfa-build")]
use alloc::{
Expand Down
6 changes: 1 addition & 5 deletions regex-automata/src/dfa/sparse.rs
Expand Up @@ -38,11 +38,7 @@ assert_eq!(Some(HalfMatch::must(0, 7)), state.get_match());

#[cfg(feature = "dfa-build")]
use core::iter;
use core::{
convert::{TryFrom, TryInto},
fmt,
mem::size_of,
};
use core::{fmt, mem::size_of};

#[cfg(feature = "dfa-build")]
use alloc::{vec, vec::Vec};
Expand Down
6 changes: 3 additions & 3 deletions regex-automata/src/nfa/thompson/compiler.rs
Expand Up @@ -1876,11 +1876,11 @@ impl Utf8Node {

#[cfg(test)]
mod tests {
use alloc::{vec, vec::Vec};
use alloc::vec;

use crate::{
nfa::thompson::{SparseTransitions, State, Transition, NFA},
util::primitives::{PatternID, SmallIndex, StateID},
nfa::thompson::{SparseTransitions, State},
util::primitives::SmallIndex,
};

use super::*;
Expand Down
6 changes: 1 addition & 5 deletions regex-automata/src/nfa/thompson/range_trie.rs
Expand Up @@ -141,7 +141,7 @@ construction later by virtue of producing a much much smaller NFA.
[2] - https://www.mitpressjournals.org/doi/pdfplus/10.1162/089120100561601
*/

use core::{cell::RefCell, convert::TryFrom, fmt, mem, ops::RangeInclusive};
use core::{cell::RefCell, fmt, mem, ops::RangeInclusive};

use alloc::{format, string::String, vec, vec::Vec};

Expand Down Expand Up @@ -915,10 +915,6 @@ fn intersects(r1: Utf8Range, r2: Utf8Range) -> bool {

#[cfg(test)]
mod tests {
use core::ops::RangeInclusive;

use regex_syntax::utf8::Utf8Range;

use super::*;

fn r(range: RangeInclusive<u8>) -> Utf8Range {
Expand Down
2 changes: 1 addition & 1 deletion regex-automata/src/util/determinize/state.rs
Expand Up @@ -86,7 +86,7 @@ serialized anywhere. So any kind of change can be made with reckless abandon,
as long as everything in this module agrees.
*/

use core::{convert::TryFrom, mem};
use core::mem;

use alloc::{sync::Arc, vec::Vec};

Expand Down
14 changes: 4 additions & 10 deletions regex-automata/src/util/int.rs
Expand Up @@ -41,6 +41,10 @@ like `u64::from` where possible, or even `usize::try_from()` for when we do
explicitly want to panic or when we want to return an error for overflow.
*/

// We define a little more than what we need, but I'd rather just have
// everything via a consistent and uniform API then have holes.
#![allow(dead_code)]

pub(crate) trait U8 {
fn as_usize(self) -> usize;
}
Expand Down Expand Up @@ -240,13 +244,3 @@ impl<T> Pointer for *const T {
self as usize
}
}

pub(crate) trait PointerMut {
fn as_usize(self) -> usize;
}

impl<T> PointerMut for *mut T {
fn as_usize(self) -> usize {
self as usize
}
}
19 changes: 1 addition & 18 deletions regex-automata/src/util/wire.rs
Expand Up @@ -41,11 +41,7 @@ generally requires serializing both its big-endian and little-endian variants,
and then loading the correct one based on the target's endianness.
*/

use core::{
cmp,
convert::{TryFrom, TryInto},
mem::size_of,
};
use core::{cmp, mem::size_of};

#[cfg(feature = "alloc")]
use alloc::{vec, vec::Vec};
Expand Down Expand Up @@ -867,11 +863,6 @@ pub(crate) trait Endian {
/// this panics.
fn write_u32(n: u32, dst: &mut [u8]);

/// Writes a u64 to the given destination buffer in a particular
/// endianness. If the destination buffer has a length smaller than 8, then
/// this panics.
fn write_u64(n: u64, dst: &mut [u8]);

/// Writes a u128 to the given destination buffer in a particular
/// endianness. If the destination buffer has a length smaller than 16,
/// then this panics.
Expand All @@ -897,10 +888,6 @@ impl Endian for LE {
dst[..4].copy_from_slice(&n.to_le_bytes());
}

fn write_u64(n: u64, dst: &mut [u8]) {
dst[..8].copy_from_slice(&n.to_le_bytes());
}

fn write_u128(n: u128, dst: &mut [u8]) {
dst[..16].copy_from_slice(&n.to_le_bytes());
}
Expand All @@ -915,10 +902,6 @@ impl Endian for BE {
dst[..4].copy_from_slice(&n.to_be_bytes());
}

fn write_u64(n: u64, dst: &mut [u8]) {
dst[..8].copy_from_slice(&n.to_be_bytes());
}

fn write_u128(n: u128, dst: &mut [u8]) {
dst[..16].copy_from_slice(&n.to_be_bytes());
}
Expand Down
3 changes: 1 addition & 2 deletions regex-capi/src/error.rs
Expand Up @@ -4,7 +4,6 @@ use std::fmt;
use std::str;

use libc::c_char;
use regex;

#[derive(Debug)]
pub struct Error {
Expand All @@ -22,7 +21,7 @@ pub enum ErrorKind {

impl Error {
pub fn new(kind: ErrorKind) -> Error {
Error { message: None, kind: kind }
Error { message: None, kind }
}

pub fn is_err(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion regex-cli/cmd/debug/dfa.rs
Expand Up @@ -5,7 +5,7 @@ use crate::{
util::{self, Table},
};

use {lexopt, regex_automata::dfa::Automaton};
use regex_automata::dfa::Automaton;

pub fn run_dense(p: &mut lexopt::Parser) -> anyhow::Result<()> {
const USAGE: &'static str = "\
Expand Down
2 changes: 1 addition & 1 deletion regex-cli/logger.rs
Expand Up @@ -3,7 +3,7 @@
// print to stderr. We therefore avoid bringing in extra dependencies just
// for this functionality.

use log::{self, Log};
use log::Log;

/// The simplest possible logger that logs to stderr.
///
Expand Down
2 changes: 0 additions & 2 deletions regex-syntax/src/ast/parse.rs
Expand Up @@ -2405,8 +2405,6 @@ mod tests {

use alloc::format;

use crate::ast::{self, Ast, Position, Span};

use super::*;

// Our own assert_eq, which has slightly better formatting (but honestly
Expand Down
17 changes: 0 additions & 17 deletions regex-syntax/src/hir/interval.rs
Expand Up @@ -479,23 +479,6 @@ pub trait Interval:
ret
}

/// Compute the symmetric difference the given range from this range. This
/// returns the union of the two ranges minus its intersection.
fn symmetric_difference(
&self,
other: &Self,
) -> (Option<Self>, Option<Self>) {
let union = match self.union(other) {
None => return (Some(self.clone()), Some(other.clone())),
Some(union) => union,
};
let intersection = match self.intersect(other) {
None => return (Some(self.clone()), Some(other.clone())),
Some(intersection) => intersection,
};
union.difference(&intersection)
}

/// Returns true if and only if the two ranges are contiguous. Two ranges
/// are contiguous if and only if the ranges are either overlapping or
/// adjacent.
Expand Down
5 changes: 2 additions & 3 deletions regex-syntax/src/hir/translate.rs
Expand Up @@ -1358,9 +1358,8 @@ fn ascii_class_as_chars(
#[cfg(test)]
mod tests {
use crate::{
ast::{self, parse::ParserBuilder, Ast, Position, Span},
hir::{self, Hir, HirKind, Look, Properties},
unicode::{self, ClassQuery},
ast::{parse::ParserBuilder, Position},
hir::{Look, Properties},
};

use super::*;
Expand Down
4 changes: 1 addition & 3 deletions regex-test/lib.rs
Expand Up @@ -99,9 +99,7 @@ See [`MatchKind`] for more details. This is an optional field and defaults to
/// For this reason, `anyhow` is a public dependency and is re-exported here.
pub extern crate anyhow;

use std::{
borrow::Borrow, collections::HashSet, convert::TryFrom, fs, path::Path,
};
use std::{borrow::Borrow, collections::HashSet, fs, path::Path};

use {
anyhow::{bail, Context, Result},
Expand Down

0 comments on commit 10fe722

Please sign in to comment.