From 9930400616f4f1b19e866382eadb26962e0c4437 Mon Sep 17 00:00:00 2001 From: hzlinyiyu Date: Tue, 20 Feb 2024 14:48:15 +0800 Subject: [PATCH] chore: move `lazy_static` to `once_cell`, and some clippy fix --- logos-codegen/Cargo.toml | 2 +- logos-codegen/src/graph/impls.rs | 2 +- logos-codegen/src/graph/range.rs | 2 +- logos-codegen/src/graph/regex.rs | 1 - logos-codegen/src/leaf.rs | 2 +- logos-codegen/src/mir.rs | 10 +++------- 6 files changed, 7 insertions(+), 12 deletions(-) diff --git a/logos-codegen/Cargo.toml b/logos-codegen/Cargo.toml index da701525..7878ea48 100644 --- a/logos-codegen/Cargo.toml +++ b/logos-codegen/Cargo.toml @@ -1,7 +1,7 @@ [dependencies] beef = "0.5.0" fnv = "1.0.6" -lazy_static = "1.4.0" +once_cell = "1.19.0" proc-macro2 = "1.0.9" quote = "1.0.3" regex-syntax = "0.8.2" diff --git a/logos-codegen/src/graph/impls.rs b/logos-codegen/src/graph/impls.rs index dc97bdf1..03a6ac6d 100644 --- a/logos-codegen/src/graph/impls.rs +++ b/logos-codegen/src/graph/impls.rs @@ -55,7 +55,7 @@ mod debug { use super::*; use crate::graph::rope::Miss; use crate::graph::Disambiguate; - use std::cmp::{Ord, Ordering}; + use std::cmp::Ordering; impl Disambiguate for &str { fn cmp(left: &&str, right: &&str) -> Ordering { diff --git a/logos-codegen/src/graph/range.rs b/logos-codegen/src/graph/range.rs index a4d23d3b..e89d3874 100644 --- a/logos-codegen/src/graph/range.rs +++ b/logos-codegen/src/graph/range.rs @@ -2,7 +2,7 @@ use regex_syntax::hir::ClassBytesRange; use regex_syntax::hir::ClassUnicodeRange; use regex_syntax::utf8::Utf8Range; -use std::cmp::{Ord, Ordering}; +use std::cmp::Ordering; #[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct Range { diff --git a/logos-codegen/src/graph/regex.rs b/logos-codegen/src/graph/regex.rs index c245c1b6..ba88f3d0 100644 --- a/logos-codegen/src/graph/regex.rs +++ b/logos-codegen/src/graph/regex.rs @@ -194,7 +194,6 @@ fn is_one_ascii(class: &ClassUnicode, repeated: bool) -> bool { #[cfg(test)] mod tests { use super::*; - use crate::graph::Node; use pretty_assertions::assert_eq; #[test] diff --git a/logos-codegen/src/leaf.rs b/logos-codegen/src/leaf.rs index 5e0b810e..cfc98033 100644 --- a/logos-codegen/src/leaf.rs +++ b/logos-codegen/src/leaf.rs @@ -1,4 +1,4 @@ -use std::cmp::{Ord, Ordering}; +use std::cmp::Ordering; use std::fmt::{self, Debug, Display}; use proc_macro2::{Span, TokenStream}; diff --git a/logos-codegen/src/mir.rs b/logos-codegen/src/mir.rs index e07c5b78..49347830 100644 --- a/logos-codegen/src/mir.rs +++ b/logos-codegen/src/mir.rs @@ -1,6 +1,4 @@ -use std::convert::TryFrom; - -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use regex_syntax::hir::{Dot, Hir, HirKind}; use regex_syntax::ParserBuilder; @@ -8,10 +6,8 @@ pub use regex_syntax::hir::{Class, ClassUnicode, Literal}; use crate::error::{Error, Result}; -lazy_static! { - static ref DOT_UTF8: Hir = Hir::dot(Dot::AnyChar); - static ref DOT_BYTES: Hir = Hir::dot(Dot::AnyByte); -} +static DOT_UTF8: Lazy = Lazy::new(|| Hir::dot(Dot::AnyChar)); +static DOT_BYTES: Lazy = Lazy::new(|| Hir::dot(Dot::AnyByte)); /// Middle Intermediate Representation of the regex, built from /// `regex_syntax`'s `Hir`. The goal here is to strip and canonicalize