Преглед на файлове

Merge branch 'update-2021' into 'master'

Update to current stable rust edition 2021 and remove unneeded features

See merge request redox-os/posix-regex!3
Jeremy Soller преди 6 месеца
родител
ревизия
28952b0860
променени са 8 файла, в които са добавени 52 реда и са изтрити 54 реда
  1. 1 0
      Cargo.toml
  2. 0 1
      rust-toolchain
  3. 11 6
      src/compile.rs
  4. 9 9
      src/ctype.rs
  5. 3 3
      src/immut_vec.rs
  6. 1 15
      src/lib.rs
  7. 18 15
      src/matcher.rs
  8. 9 5
      src/tree.rs

+ 1 - 0
Cargo.toml

@@ -8,6 +8,7 @@ name = "posix-regex"
 readme = "README.md"
 repository = "https://gitlab.redox-os.org/redox-os/posix-regex"
 version = "0.1.1"
+edition = "2021"
 
 [dependencies]
 

+ 0 - 1
rust-toolchain

@@ -1 +0,0 @@
-nightly-2019-05-10

+ 11 - 6
src/compile.rs

@@ -2,13 +2,16 @@
 //! Produces a matcher ready to match input.
 
 #[cfg(feature = "no_std")]
-use std::prelude::*;
+use crate::std::collections::HashMap;
 
-use std::borrow::Cow;
+#[cfg(not(feature = "no_std"))]
 use std::collections::HashMap;
-use std::fmt;
-use tree::*;
-use {ctype, PosixRegex};
+
+use crate::{ctype, tree::*, PosixRegex};
+
+extern crate alloc;
+use alloc::{borrow::Cow, vec, vec::Vec};
+use core::fmt;
 
 /// Repetition bounds, for example + is (1, None), and ? is (0, Some(1))
 #[derive(Clone, Copy, PartialEq, Eq)]
@@ -317,7 +320,7 @@ impl<'a> PosixRegexBuilder<'a> {
                     if self
                         .input
                         .first()
-                        .map(|&c| (c as char).is_digit(10))
+                        .map(|&c| c.is_ascii_digit())
                         .unwrap_or(false) =>
                 {
                     let id = self.take_int()?.unwrap();
@@ -382,6 +385,8 @@ impl<'a> PosixRegexBuilder<'a> {
 mod tests {
     use super::*;
 
+    use alloc::{format, string::String};
+
     fn compile(input: &[u8]) -> String {
         format!(
             "{:?}",

+ 9 - 9
src/ctype.rs

@@ -2,37 +2,37 @@ pub fn is_alnum(c: u8) -> bool {
     is_alpha(c) || is_digit(c)
 }
 pub fn is_alpha(c: u8) -> bool {
-    is_lower(c) || is_upper(c)
+    c.is_ascii_alphabetic()
 }
 pub fn is_blank(c: u8) -> bool {
     c == b' ' || c == b'\t'
 }
 pub fn is_cntrl(c: u8) -> bool {
-    c <= 0x1f || c == 0x7f
+    c.is_ascii_control()
 }
 pub fn is_digit(c: u8) -> bool {
-    c >= b'0' && c <= b'9'
+    c.is_ascii_digit()
 }
 pub fn is_graph(c: u8) -> bool {
-    c >= 0x21 && c <= 0x7e
+    c.is_ascii_graphic()
 }
 pub fn is_lower(c: u8) -> bool {
-    c >= b'a' && c <= b'z'
+    c.is_ascii_lowercase()
 }
 pub fn is_print(c: u8) -> bool {
-    c >= 0x20 && c <= 0x7e
+    (0x20..=0x7e).contains(&c)
 }
 pub fn is_punct(c: u8) -> bool {
     is_graph(c) && !is_alnum(c)
 }
 pub fn is_space(c: u8) -> bool {
-    c == b' ' || (c >= 0x9 && c <= 0xD)
+    c == b' ' || (0x9..=0xD).contains(&c)
 }
 pub fn is_upper(c: u8) -> bool {
-    c >= b'A' && c <= b'Z'
+    c.is_ascii_uppercase()
 }
 pub fn is_xdigit(c: u8) -> bool {
-    is_digit(c) || (c >= b'a' && c <= b'f') || (c >= b'A' && c <= b'F')
+    c.is_ascii_hexdigit()
 }
 
 pub fn is_word_boundary(c: u8) -> bool {

+ 3 - 3
src/immut_vec.rs

@@ -1,7 +1,7 @@
-#[cfg(feature = "no_std")]
-use std::prelude::*;
+use core::cell::RefCell;
 
-use std::cell::RefCell;
+extern crate alloc;
+use alloc::vec::Vec;
 
 pub struct ImmutVecItem<T> {
     prev: Option<usize>,

+ 1 - 15
src/lib.rs

@@ -1,26 +1,12 @@
 #![cfg_attr(feature = "bench", feature(test))]
-#![cfg_attr(feature = "no_std", feature(alloc))]
 #![cfg_attr(feature = "no_std", no_std)]
-#![feature(nll)]
 
-#[cfg(feature = "no_std")]
-#[macro_use]
 extern crate alloc;
 
 #[cfg(feature = "no_std")]
 mod std {
-    pub use alloc::{borrow, rc};
-    pub use core::*;
-
     pub mod collections {
-        pub use alloc::collections::BTreeMap as HashMap;
-        pub use alloc::collections::BTreeSet as HashSet;
-    }
-    pub mod prelude {
-        pub use alloc::borrow::ToOwned;
-        pub use alloc::boxed::Box;
-        pub use alloc::string::String;
-        pub use alloc::vec::Vec;
+        pub use alloc::collections::{BTreeMap as HashMap, BTreeSet as HashSet};
     }
 }
 

+ 18 - 15
src/matcher.rs

@@ -1,18 +1,21 @@
 //! The matcher: Can find substrings in a string that match any compiled regex
 
 #[cfg(feature = "no_std")]
-use std::prelude::*;
+use crate::std::collections::HashSet;
 
-use std::borrow::Cow;
-use std::cell::RefCell;
+#[cfg(not(feature = "no_std"))]
 use std::collections::HashSet;
-use std::fmt;
-use std::rc::Rc;
 
-use compile::{Range, Token};
-use ctype;
-use immut_vec::ImmutVec;
-use tree::{Node as TreeNode, *};
+extern crate alloc;
+use alloc::{borrow::Cow, boxed::Box, rc::Rc, vec, vec::Vec};
+use core::{cell::RefCell, fmt};
+
+use crate::{
+    compile::{Range, Token},
+    ctype,
+    immut_vec::ImmutVec,
+    tree::{Node as TreeNode, *},
+};
 
 /// A regex matcher, ready to match stuff
 #[derive(Clone)]
@@ -274,7 +277,7 @@ impl<'a> Node<'a> {
         self.repeated += 1;
         let mut parent = Rc::new(self);
         let mut empty = true;
-        for alternative in parent.tree[parent.node].children(&parent.tree) {
+        for alternative in parent.tree[parent.node].children(parent.tree) {
             if let Some(node) = parent.tree[alternative].child {
                 empty = false;
                 branches.push(Self::prepare(Self {
@@ -292,7 +295,7 @@ impl<'a> Node<'a> {
             }
         }
         if empty {
-            let mut parent = Rc::get_mut(&mut parent)
+            let parent = Rc::get_mut(&mut parent)
                 .expect("group empty but still there's a dangling reference");
             for &open in &[true, false] {
                 parent.prev = parent.prev.push(GroupEvent { open, id, offset });
@@ -450,7 +453,7 @@ impl<'a> Node<'a> {
             let mut node = current.node();
             if node.token == Token::Alternative {
                 // Don't explore other alternatives
-                next = current.parent.as_ref().map(|node| &**node);
+                next = current.parent.as_deref();
                 node = &self.tree[node.parent.expect("found root alternative")];
             }
             if let Token::Group(_) = node.token {
@@ -462,7 +465,7 @@ impl<'a> Node<'a> {
             if node.next_sibling.is_some() {
                 break;
             }
-            next = current.parent.as_ref().map(|node| &**node);
+            next = current.parent.as_deref();
         }
         next.and_then(|node| self.tree[node.node].next_sibling)
             .is_none()
@@ -629,7 +632,7 @@ impl<'a> PosixRegexMatcher<'a> {
                                     && list
                                         .iter()
                                         .any(|c| c.matches(next, self.base.case_insensitive))
-                                        == !invert
+                                        != invert
                             } else {
                                 false
                             }
@@ -693,7 +696,7 @@ mod tests {
     use self::test::Bencher;
 
     use super::*;
-    use PosixRegexBuilder;
+    use crate::PosixRegexBuilder;
 
     // FIXME: Workaround to coerce a Box<[T; N]> into a Box<[T]>. Use type
     // ascription when stabilized.

+ 9 - 5
src/tree.rs

@@ -1,10 +1,12 @@
-#[cfg(feature = "no_std")]
-use std::prelude::*;
+use core::{
+    fmt,
+    ops::{Index, IndexMut},
+};
 
-use std::fmt;
-use std::ops::{Index, IndexMut};
+extern crate alloc;
+use alloc::{boxed::Box, vec::Vec};
 
-use compile::{Range, Token};
+use crate::compile::{Range, Token};
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
 pub struct NodeId(usize);
@@ -198,6 +200,8 @@ impl fmt::Debug for Tree {
 
 #[cfg(test)]
 mod tests {
+    use alloc::format;
+
     use super::*;
 
     fn sanity_check(tree: &Tree) {