Skip to content

Commit

Permalink
edition: manual fixups to code
Browse files Browse the repository at this point in the history
This commit does a number of manual fixups to the code after the
previous two commits were done via 'cargo fix' automatically.

Actually, this contains more 'cargo fix' annotations, since I had
forgotten to add 'edition = "2018"' to all sub-crates.
  • Loading branch information
BurntSushi committed Apr 30, 2021
1 parent 964d1ef commit ab98561
Show file tree
Hide file tree
Showing 40 changed files with 143 additions and 202 deletions.
4 changes: 1 addition & 3 deletions PERFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ on how your program is structured. Thankfully, the
[`lazy_static`](https://crates.io/crates/lazy_static)
crate provides an answer that works well:

#[macro_use] extern crate lazy_static;
extern crate regex;

use lazy_static::lazy_static;
use regex::Regex;

fn some_helper_function(text: &str) -> bool {
Expand Down
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ Add this to your `Cargo.toml`:

```toml
[dependencies]
regex = "1"
```

and this to your crate root (if you're using Rust 2015):

```rust
extern crate regex;
regex = "1.5"
```

Here's a simple example that matches a date in YYYY-MM-DD format and prints the
Expand Down
4 changes: 2 additions & 2 deletions bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ homepage = "https://github.com/rust-lang/regex"
description = "Regex benchmarks for Rust's and other engines."
build = "build.rs"
workspace = ".."
edition = "2018"

[dependencies]
docopt = "1"
Expand All @@ -20,8 +21,7 @@ libpcre-sys = { version = "0.2", optional = true }
memmap = "0.6.2"
regex = { version = "1", path = ".." }
regex-syntax = { version = "0.6", path = "../regex-syntax" }
serde = "1"
serde_derive = "1"
serde = { version = "1", features = ["derive"] }
cfg-if = "0.1"

[build-dependencies]
Expand Down
3 changes: 0 additions & 3 deletions bench/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate cc;
extern crate pkg_config;

use std::env;
use std::process;

Expand Down
29 changes: 14 additions & 15 deletions bench/src/bench.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
// Enable the benchmarking harness.
#![feature(test)]
// It's too annoying to carefully define macros based on which regex engines
// have which benchmarks, so just ignore these warnings.
#![allow(unused_macros)]

#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate cfg_if;

#[cfg(not(any(feature = "re-rust", feature = "re-rust-bytes")))]
extern crate libc;

extern crate regex_syntax;
extern crate test;

use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "re-pcre1")] {
extern crate libpcre_sys;
pub use ffi::pcre1::Regex;
} else if #[cfg(feature = "re-onig")] {
extern crate onig;
pub use ffi::onig::Regex;
} else if #[cfg(any(feature = "re-rust"))] {
extern crate regex;
pub use regex::{Regex, RegexSet};
} else if #[cfg(feature = "re-rust-bytes")] {
extern crate regex;
pub use regex::bytes::{Regex, RegexSet};
} else if #[cfg(feature = "re-re2")] {
pub use ffi::re2::Regex;
Expand Down Expand Up @@ -51,7 +43,7 @@ cfg_if! {
// native and dynamic regexes.
macro_rules! regex {
($re:expr) => {
::Regex::new(&$re.to_owned()).unwrap()
crate::Regex::new(&$re.to_owned()).unwrap()
};
}

Expand All @@ -72,7 +64,7 @@ cfg_if! {
// regex accepts in its `is_match` and `find_iter` methods.
macro_rules! text {
($text:expr) => {{
use ffi::tcl::Text;
use crate::ffi::tcl::Text;
Text::new($text)
}}
}
Expand Down Expand Up @@ -148,6 +140,7 @@ macro_rules! bench_is_match {
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
use lazy_static::lazy_static;
use std::sync::Mutex;

// Why do we use lazy_static here? It seems sensible to just
Expand Down Expand Up @@ -192,6 +185,7 @@ macro_rules! bench_find {
($name:ident, $pattern:expr, $count:expr, $haystack:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
Expand Down Expand Up @@ -224,6 +218,7 @@ macro_rules! bench_captures {
#[cfg(feature = "re-rust")]
#[bench]
fn $name(b: &mut Bencher) {
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
Expand All @@ -246,7 +241,9 @@ macro_rules! bench_is_match_set {
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
static ref RE: Mutex<RegexSet> = Mutex::new($re);
static ref TEXT: Mutex<Text> = Mutex::new(text!($haystack));
Expand All @@ -272,7 +269,9 @@ macro_rules! bench_matches_set {
($name:ident, $is_match:expr, $re:expr, $haystack:expr) => {
#[bench]
fn $name(b: &mut Bencher) {
use lazy_static::lazy_static;
use std::sync::Mutex;

lazy_static! {
static ref RE: Mutex<RegexSet> = Mutex::new($re);
static ref TEXT: Mutex<Text> = Mutex::new(text!($haystack));
Expand Down
22 changes: 11 additions & 11 deletions bench/src/ffi/pcre2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fmt;
use std::ptr;
use std::str;

use libc::{c_int, c_void, size_t, uint32_t, uint8_t};
use libc::{c_int, c_void, size_t};

pub struct Regex {
code: *mut code,
Expand Down Expand Up @@ -142,10 +142,10 @@ impl fmt::Debug for Error {

// PCRE2 FFI. We only wrap the bits we need.

const PCRE2_UCP: uint32_t = 0x00020000;
const PCRE2_UTF: uint32_t = 0x00080000;
const PCRE2_NO_UTF_CHECK: uint32_t = 0x40000000;
const PCRE2_JIT_COMPLETE: uint32_t = 0x00000001;
const PCRE2_UCP: u32 = 0x00020000;
const PCRE2_UTF: u32 = 0x00080000;
const PCRE2_NO_UTF_CHECK: u32 = 0x40000000;
const PCRE2_JIT_COMPLETE: u32 = 0x00000001;
const PCRE2_ERROR_NOMATCH: c_int = -1;

type code = c_void;
Expand All @@ -160,9 +160,9 @@ type match_context = c_void; // unused

extern "C" {
fn pcre2_compile_8(
pattern: *const uint8_t,
pattern: *const u8,
len: size_t,
options: uint32_t,
options: u32,
error_code: *mut c_int,
error_offset: *mut size_t,
context: *mut compile_context,
Expand All @@ -180,21 +180,21 @@ extern "C" {
fn pcre2_get_ovector_pointer_8(match_data: *mut match_data)
-> *mut size_t;

fn pcre2_jit_compile_8(code: *const code, options: uint32_t) -> c_int;
fn pcre2_jit_compile_8(code: *const code, options: u32) -> c_int;

fn pcre2_jit_match_8(
code: *const code,
subject: *const uint8_t,
subject: *const u8,
length: size_t,
startoffset: size_t,
options: uint32_t,
options: u32,
match_data: *mut match_data,
match_context: *mut match_context,
) -> c_int;

fn pcre2_get_error_message_8(
error_code: c_int,
buf: *mut uint8_t,
buf: *mut u8,
buflen: size_t,
) -> c_int;
}
17 changes: 1 addition & 16 deletions bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
extern crate docopt;
extern crate libc;
#[cfg(feature = "re-pcre1")]
extern crate libpcre_sys;
extern crate memmap;
#[cfg(feature = "re-onig")]
extern crate onig;
#[cfg(any(feature = "re-rust", feature = "re-rust-bytes",))]
extern crate regex;
#[cfg(feature = "re-rust")]
extern crate regex_syntax;
extern crate serde;
#[macro_use]
extern crate serde_derive;

use std::fs::File;
use std::str;

Expand All @@ -39,7 +24,7 @@ Options:
-h, --help Show this usage message.
";

#[derive(Debug, Deserialize)]
#[derive(Debug, serde::Deserialize)]
struct Args {
arg_pattern: String,
arg_file: String,
Expand Down
4 changes: 2 additions & 2 deletions bench/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use std::iter::repeat;
use test::Bencher;

#[cfg(any(feature = "re-rust", feature = "re-rust-bytes"))]
use RegexSet;
use {Regex, Text};
use crate::RegexSet;
use crate::{Regex, Text};

#[cfg(not(feature = "re-onig"))]
#[cfg(not(feature = "re-pcre1"))]
Expand Down
2 changes: 1 addition & 1 deletion bench/src/regexdna.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use test::Bencher;

use {Regex, Text};
use crate::{Regex, Text};

// USAGE: dna!(name, pattern, count)
//
Expand Down
2 changes: 1 addition & 1 deletion bench/src/sherlock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use test::Bencher;

use {Regex, Text};
use crate::{Regex, Text};

// USAGE: sherlock!(name, pattern, count)
//
Expand Down
2 changes: 0 additions & 2 deletions examples/shootout-regex-dna-bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// contributed by TeXitoi
// contributed by BurntSushi



use std::io::{self, Read};
use std::sync::Arc;
use std::thread;
Expand Down
2 changes: 0 additions & 2 deletions examples/shootout-regex-dna-cheat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
// replacing them with a single linear scan. i.e., it re-implements
// `replace_all`. As a result, this is around 25% faster. ---AG



use std::io::{self, Read};
use std::sync::Arc;
use std::thread;
Expand Down
2 changes: 0 additions & 2 deletions examples/shootout-regex-dna-replace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


use std::io::{self, Read};

macro_rules! regex {
Expand Down
2 changes: 0 additions & 2 deletions examples/shootout-regex-dna-single-cheat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// contributed by TeXitoi
// contributed by BurntSushi



use std::io::{self, Read};

macro_rules! regex {
Expand Down
2 changes: 0 additions & 2 deletions examples/shootout-regex-dna-single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// contributed by TeXitoi
// contributed by BurntSushi



use std::io::{self, Read};

macro_rules! regex {
Expand Down
2 changes: 0 additions & 2 deletions examples/shootout-regex-dna.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// contributed by TeXitoi
// contributed by BurntSushi



use std::io::{self, Read};
use std::sync::Arc;
use std::thread;
Expand Down
1 change: 1 addition & 0 deletions regex-capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ description = """
A C API for Rust's regular expression library.
"""
workspace = ".."
edition = "2018"

[lib]
name = "rure"
Expand Down
2 changes: 1 addition & 1 deletion regex-capi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Error {
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.kind {
ErrorKind::None => write!(f, "no error"),
ErrorKind::Str(ref e) => e.fmt(f),
Expand Down
3 changes: 0 additions & 3 deletions regex-capi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate libc;
extern crate regex;

#[macro_use]
mod macros;
mod error;
Expand Down
4 changes: 2 additions & 2 deletions regex-debug/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ documentation = "https://docs.rs/regex"
homepage = "https://github.com/rust-lang/regex"
description = "A tool useful for debugging regular expressions."
workspace = ".."
edition = "2018"

[dependencies]
docopt = "1"
regex = { version = "1.1", path = ".." }
regex-syntax = { version = "0.6", path = "../regex-syntax" }
serde = "1"
serde_derive = "1"
serde = { version = "1", features = ["derive"] }
Loading

0 comments on commit ab98561

Please sign in to comment.