From d610ff85f19885181b390cb4c16dee97226e4aba Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 30 Apr 2021 16:01:44 -0400 Subject: [PATCH] edition: manual fixups to code 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. --- PERFORMANCE.md | 4 +-- README.md | 8 +---- bench/Cargo.toml | 4 +-- bench/build.rs | 3 -- bench/src/bench.rs | 29 +++++++++--------- bench/src/ffi/pcre2.rs | 22 ++++++------- bench/src/main.rs | 17 +---------- bench/src/misc.rs | 4 +-- bench/src/regexdna.rs | 2 +- bench/src/sherlock.rs | 2 +- examples/shootout-regex-dna-bytes.rs | 2 -- examples/shootout-regex-dna-cheat.rs | 2 -- examples/shootout-regex-dna-replace.rs | 2 -- examples/shootout-regex-dna-single-cheat.rs | 2 -- examples/shootout-regex-dna-single.rs | 2 -- examples/shootout-regex-dna.rs | 2 -- regex-capi/Cargo.toml | 1 + regex-capi/src/error.rs | 2 +- regex-capi/src/lib.rs | 3 -- regex-debug/Cargo.toml | 4 +-- regex-debug/src/main.rs | 31 ++++++++----------- regex-syntax/Cargo.toml | 1 + regex-syntax/benches/bench.rs | 1 - regex-syntax/src/ast/mod.rs | 10 +++--- regex-syntax/src/ast/parse.rs | 17 ++++++----- regex-syntax/src/ast/visitor.rs | 4 +-- regex-syntax/src/error.rs | 6 ++-- regex-syntax/src/hir/interval.rs | 4 +-- regex-syntax/src/hir/literal/mod.rs | 6 ++-- regex-syntax/src/hir/mod.rs | 14 ++++----- regex-syntax/src/hir/translate.rs | 2 +- regex-syntax/src/unicode.rs | 6 ++-- regex-syntax/src/utf8.rs | 6 ++-- src/compile.rs | 10 +++--- src/exec.rs | 8 ++--- src/input.rs | 6 ++-- src/lib.rs | 34 ++++++++------------- src/literal/imp.rs | 3 +- src/re_bytes.rs | 28 ++++++++--------- src/re_unicode.rs | 31 +++++++++---------- 40 files changed, 143 insertions(+), 202 deletions(-) diff --git a/PERFORMANCE.md b/PERFORMANCE.md index b4aeb89..7904e1f 100644 --- a/PERFORMANCE.md +++ b/PERFORMANCE.md @@ -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 { diff --git a/README.md b/README.md index f7a2554..88affac 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/bench/Cargo.toml b/bench/Cargo.toml index 0c08a74..9e61fd0 100644 --- a/bench/Cargo.toml +++ b/bench/Cargo.toml @@ -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" @@ -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] diff --git a/bench/build.rs b/bench/build.rs index 5d44849..d16cc64 100644 --- a/bench/build.rs +++ b/bench/build.rs @@ -1,6 +1,3 @@ -extern crate cc; -extern crate pkg_config; - use std::env; use std::process; diff --git a/bench/src/bench.rs b/bench/src/bench.rs index ec0e547..a1b03de 100644 --- a/bench/src/bench.rs +++ b/bench/src/bench.rs @@ -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; @@ -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() }; } @@ -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) }} } @@ -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 @@ -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! { @@ -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! { @@ -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 = Mutex::new($re); static ref TEXT: Mutex = Mutex::new(text!($haystack)); @@ -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 = Mutex::new($re); static ref TEXT: Mutex = Mutex::new(text!($haystack)); diff --git a/bench/src/ffi/pcre2.rs b/bench/src/ffi/pcre2.rs index 59b9cb2..6fc5f6d 100644 --- a/bench/src/ffi/pcre2.rs +++ b/bench/src/ffi/pcre2.rs @@ -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, @@ -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; @@ -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, @@ -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; } diff --git a/bench/src/main.rs b/bench/src/main.rs index b8bab8d..7da9910 100644 --- a/bench/src/main.rs +++ b/bench/src/main.rs @@ -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; @@ -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, diff --git a/bench/src/misc.rs b/bench/src/misc.rs index 9e7b2c9..50bcef0 100644 --- a/bench/src/misc.rs +++ b/bench/src/misc.rs @@ -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"))] diff --git a/bench/src/regexdna.rs b/bench/src/regexdna.rs index 45ace9e..7a35aa4 100644 --- a/bench/src/regexdna.rs +++ b/bench/src/regexdna.rs @@ -1,6 +1,6 @@ use test::Bencher; -use {Regex, Text}; +use crate::{Regex, Text}; // USAGE: dna!(name, pattern, count) // diff --git a/bench/src/sherlock.rs b/bench/src/sherlock.rs index e7328df..8feb586 100644 --- a/bench/src/sherlock.rs +++ b/bench/src/sherlock.rs @@ -1,6 +1,6 @@ use test::Bencher; -use {Regex, Text}; +use crate::{Regex, Text}; // USAGE: sherlock!(name, pattern, count) // diff --git a/examples/shootout-regex-dna-bytes.rs b/examples/shootout-regex-dna-bytes.rs index c07fe10..773fd9b 100644 --- a/examples/shootout-regex-dna-bytes.rs +++ b/examples/shootout-regex-dna-bytes.rs @@ -5,8 +5,6 @@ // contributed by TeXitoi // contributed by BurntSushi - - use std::io::{self, Read}; use std::sync::Arc; use std::thread; diff --git a/examples/shootout-regex-dna-cheat.rs b/examples/shootout-regex-dna-cheat.rs index 962891f..1bde7ab 100644 --- a/examples/shootout-regex-dna-cheat.rs +++ b/examples/shootout-regex-dna-cheat.rs @@ -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; diff --git a/examples/shootout-regex-dna-replace.rs b/examples/shootout-regex-dna-replace.rs index b28a737..20694e0 100644 --- a/examples/shootout-regex-dna-replace.rs +++ b/examples/shootout-regex-dna-replace.rs @@ -1,5 +1,3 @@ - - use std::io::{self, Read}; macro_rules! regex { diff --git a/examples/shootout-regex-dna-single-cheat.rs b/examples/shootout-regex-dna-single-cheat.rs index 5bcfc24..70a979c 100644 --- a/examples/shootout-regex-dna-single-cheat.rs +++ b/examples/shootout-regex-dna-single-cheat.rs @@ -5,8 +5,6 @@ // contributed by TeXitoi // contributed by BurntSushi - - use std::io::{self, Read}; macro_rules! regex { diff --git a/examples/shootout-regex-dna-single.rs b/examples/shootout-regex-dna-single.rs index 2233316..b474059 100644 --- a/examples/shootout-regex-dna-single.rs +++ b/examples/shootout-regex-dna-single.rs @@ -5,8 +5,6 @@ // contributed by TeXitoi // contributed by BurntSushi - - use std::io::{self, Read}; macro_rules! regex { diff --git a/examples/shootout-regex-dna.rs b/examples/shootout-regex-dna.rs index 74085ee..b96518e 100644 --- a/examples/shootout-regex-dna.rs +++ b/examples/shootout-regex-dna.rs @@ -5,8 +5,6 @@ // contributed by TeXitoi // contributed by BurntSushi - - use std::io::{self, Read}; use std::sync::Arc; use std::thread; diff --git a/regex-capi/Cargo.toml b/regex-capi/Cargo.toml index 6d9807f..4793809 100644 --- a/regex-capi/Cargo.toml +++ b/regex-capi/Cargo.toml @@ -11,6 +11,7 @@ description = """ A C API for Rust's regular expression library. """ workspace = ".." +edition = "2018" [lib] name = "rure" diff --git a/regex-capi/src/error.rs b/regex-capi/src/error.rs index 95c9fdb..2ca3fae 100644 --- a/regex-capi/src/error.rs +++ b/regex-capi/src/error.rs @@ -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), diff --git a/regex-capi/src/lib.rs b/regex-capi/src/lib.rs index 9b2efc6..aa03c60 100644 --- a/regex-capi/src/lib.rs +++ b/regex-capi/src/lib.rs @@ -1,6 +1,3 @@ -extern crate libc; -extern crate regex; - #[macro_use] mod macros; mod error; diff --git a/regex-debug/Cargo.toml b/regex-debug/Cargo.toml index d174b47..34a62f8 100644 --- a/regex-debug/Cargo.toml +++ b/regex-debug/Cargo.toml @@ -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"] } diff --git a/regex-debug/src/main.rs b/regex-debug/src/main.rs index 489066f..a7dd453 100644 --- a/regex-debug/src/main.rs +++ b/regex-debug/src/main.rs @@ -1,10 +1,3 @@ -extern crate docopt; -extern crate regex; -extern crate regex_syntax as syntax; -extern crate serde; -#[macro_use] -extern crate serde_derive; - use std::error; use std::io::{self, Write}; use std::process; @@ -12,8 +5,8 @@ use std::result; use docopt::Docopt; use regex::internal::{Compiler, LiteralSearcher}; -use crate::syntax::hir::literal::Literals; -use crate::syntax::hir::Hir; +use regex_syntax::hir::literal::Literals; +use regex_syntax::hir::Hir; const USAGE: &'static str = " Usage: @@ -54,7 +47,7 @@ Options: --quiet Show less output. "; -#[derive(Deserialize)] +#[derive(serde::Deserialize)] struct Args { cmd_ast: bool, cmd_hir: bool, @@ -127,7 +120,7 @@ fn run(args: &Args) -> Result<()> { } fn cmd_ast(args: &Args) -> Result<()> { - use crate::syntax::ast::parse::Parser; + use regex_syntax::ast::parse::Parser; let mut parser = Parser::new(); let ast = parser.parse(&args.arg_pattern)?; @@ -136,7 +129,7 @@ fn cmd_ast(args: &Args) -> Result<()> { } fn cmd_hir(args: &Args) -> Result<()> { - use crate::syntax::ParserBuilder; + use regex_syntax::ParserBuilder; let mut parser = ParserBuilder::new().allow_invalid_utf8(false).build(); let hir = parser.parse(&args.arg_pattern)?; @@ -225,9 +218,9 @@ fn cmd_compile(args: &Args) -> Result<()> { } fn cmd_utf8_ranges(args: &Args) -> Result<()> { - use crate::syntax::hir::{self, HirKind}; - use crate::syntax::utf8::Utf8Sequences; - use crate::syntax::ParserBuilder; + use regex_syntax::hir::{self, HirKind}; + use regex_syntax::utf8::Utf8Sequences; + use regex_syntax::ParserBuilder; let hir = ParserBuilder::new() .build() @@ -258,9 +251,9 @@ fn cmd_utf8_ranges(args: &Args) -> Result<()> { } fn cmd_utf8_ranges_rev(args: &Args) -> Result<()> { - use crate::syntax::hir::{self, HirKind}; - use crate::syntax::utf8::Utf8Sequences; - use crate::syntax::ParserBuilder; + use regex_syntax::hir::{self, HirKind}; + use regex_syntax::utf8::Utf8Sequences; + use regex_syntax::ParserBuilder; let hir = ParserBuilder::new() .build() @@ -334,7 +327,7 @@ impl Args { } fn parse(re: &str) -> Result { - use crate::syntax::ParserBuilder; + use regex_syntax::ParserBuilder; ParserBuilder::new() .allow_invalid_utf8(true) .build() diff --git a/regex-syntax/Cargo.toml b/regex-syntax/Cargo.toml index 8461178..2833777 100644 --- a/regex-syntax/Cargo.toml +++ b/regex-syntax/Cargo.toml @@ -8,6 +8,7 @@ documentation = "https://docs.rs/regex-syntax" homepage = "https://github.com/rust-lang/regex" description = "A regular expression parser." workspace = ".." +edition = "2018" # Features are documented in the "Crate features" section of the crate docs: # https://docs.rs/regex-syntax/*/#crate-features diff --git a/regex-syntax/benches/bench.rs b/regex-syntax/benches/bench.rs index ba7f81c..d4703d4 100644 --- a/regex-syntax/benches/bench.rs +++ b/regex-syntax/benches/bench.rs @@ -1,6 +1,5 @@ #![feature(test)] -extern crate regex_syntax; extern crate test; use regex_syntax::Parser; diff --git a/regex-syntax/src/ast/mod.rs b/regex-syntax/src/ast/mod.rs index f1d21b6..9b9127b 100644 --- a/regex-syntax/src/ast/mod.rs +++ b/regex-syntax/src/ast/mod.rs @@ -220,13 +220,13 @@ impl error::Error for Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { crate::error::Formatter::from(self).fmt(f) } } impl fmt::Display for ErrorKind { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use self::ErrorKind::*; match *self { CaptureLimitExceeded => write!( @@ -328,7 +328,7 @@ pub struct Span { } impl fmt::Debug for Span { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Span({:?}, {:?})", self.start, self.end) } } @@ -361,7 +361,7 @@ pub struct Position { } impl fmt::Debug for Position { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Position(o: {:?}, l: {:?}, c: {:?})", @@ -542,7 +542,7 @@ impl Ast { /// This implementation uses constant stack space and heap space proportional /// to the size of the `Ast`. impl fmt::Display for Ast { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use crate::ast::print::Printer; Printer::new().print(self, f) } diff --git a/regex-syntax/src/ast/parse.rs b/regex-syntax/src/ast/parse.rs index 2e52aec..e62a7c2 100644 --- a/regex-syntax/src/ast/parse.rs +++ b/regex-syntax/src/ast/parse.rs @@ -58,7 +58,7 @@ impl Primitive { /// then return an error. fn into_class_set_item>( self, - p: &ParserI

, + p: &ParserI<'_, P>, ) -> Result { use self::Primitive::*; use crate::ast::ClassSetItem; @@ -79,7 +79,7 @@ impl Primitive { /// dot), then return an error. fn into_class_literal>( self, - p: &ParserI

, + p: &ParserI<'_, P>, ) -> Result { use self::Primitive::*; @@ -2137,7 +2137,7 @@ impl<'s, P: Borrow> ParserI<'s, P> { /// A type that traverses a fully parsed Ast and checks whether its depth /// exceeds the specified nesting limit. If it does, then an error is returned. #[derive(Debug)] -struct NestLimiter<'p, 's: 'p, P: 'p + 's> { +struct NestLimiter<'p, 's, P> { /// The parser that is checking the nest limit. p: &'p ParserI<'s, P>, /// The current depth while walking an Ast. @@ -2357,21 +2357,24 @@ mod tests { str.to_string() } - fn parser(pattern: &str) -> ParserI { + fn parser(pattern: &str) -> ParserI<'_, Parser> { ParserI::new(Parser::new(), pattern) } - fn parser_octal(pattern: &str) -> ParserI { + fn parser_octal(pattern: &str) -> ParserI<'_, Parser> { let parser = ParserBuilder::new().octal(true).build(); ParserI::new(parser, pattern) } - fn parser_nest_limit(pattern: &str, nest_limit: u32) -> ParserI { + fn parser_nest_limit( + pattern: &str, + nest_limit: u32, + ) -> ParserI<'_, Parser> { let p = ParserBuilder::new().nest_limit(nest_limit).build(); ParserI::new(p, pattern) } - fn parser_ignore_whitespace(pattern: &str) -> ParserI { + fn parser_ignore_whitespace(pattern: &str) -> ParserI<'_, Parser> { let p = ParserBuilder::new().ignore_whitespace(true).build(); ParserI::new(p, pattern) } diff --git a/regex-syntax/src/ast/visitor.rs b/regex-syntax/src/ast/visitor.rs index 3ab3331..a0d1e7d 100644 --- a/regex-syntax/src/ast/visitor.rs +++ b/regex-syntax/src/ast/visitor.rs @@ -478,7 +478,7 @@ impl<'a> ClassInduct<'a> { } impl<'a> fmt::Debug for ClassFrame<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let x = match *self { ClassFrame::Union { .. } => "Union", ClassFrame::Binary { .. } => "Binary", @@ -490,7 +490,7 @@ impl<'a> fmt::Debug for ClassFrame<'a> { } impl<'a> fmt::Debug for ClassInduct<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let x = match *self { ClassInduct::Item(it) => match *it { ast::ClassSetItem::Empty(_) => "Item(Empty)", diff --git a/regex-syntax/src/error.rs b/regex-syntax/src/error.rs index d782cd9..71cfa42 100644 --- a/regex-syntax/src/error.rs +++ b/regex-syntax/src/error.rs @@ -52,7 +52,7 @@ impl error::Error for 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 { Error::Parse(ref x) => x.fmt(f), Error::Translate(ref x) => x.fmt(f), @@ -67,7 +67,7 @@ impl fmt::Display for Error { /// readable format. Most of its complexity is from interspersing notational /// markers pointing out the position where an error occurred. #[derive(Debug)] -pub struct Formatter<'e, E: 'e> { +pub struct Formatter<'e, E> { /// The original regex pattern in which the error occurred. pattern: &'e str, /// The error kind. It must impl fmt::Display. @@ -102,7 +102,7 @@ impl<'e> From<&'e hir::Error> for Formatter<'e, hir::ErrorKind> { } impl<'e, E: fmt::Display> fmt::Display for Formatter<'e, E> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let spans = Spans::from_formatter(self); if self.pattern.contains('\n') { let divider = repeat_char('~', 79); diff --git a/regex-syntax/src/hir/interval.rs b/regex-syntax/src/hir/interval.rs index 1263a1a..cfaa2cb 100644 --- a/regex-syntax/src/hir/interval.rs +++ b/regex-syntax/src/hir/interval.rs @@ -60,7 +60,7 @@ impl IntervalSet { /// Return an iterator over all intervals in this set. /// /// The iterator yields intervals in ascending order. - pub fn iter(&self) -> IntervalSetIter { + pub fn iter(&self) -> IntervalSetIter<'_, I> { IntervalSetIter(self.ranges.iter()) } @@ -322,7 +322,7 @@ impl IntervalSet { /// An iterator over intervals. #[derive(Debug)] -pub struct IntervalSetIter<'a, I: 'a>(slice::Iter<'a, I>); +pub struct IntervalSetIter<'a, I>(slice::Iter<'a, I>); impl<'a, I> Iterator for IntervalSetIter<'a, I> { type Item = &'a I; diff --git a/regex-syntax/src/hir/literal/mod.rs b/regex-syntax/src/hir/literal/mod.rs index e2742b8..25ee88b 100644 --- a/regex-syntax/src/hir/literal/mod.rs +++ b/regex-syntax/src/hir/literal/mod.rs @@ -838,7 +838,7 @@ fn alternate_literals( } impl fmt::Debug for Literals { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Literals") .field("lits", &self.lits) .field("limit_size", &self.limit_size) @@ -882,7 +882,7 @@ impl PartialOrd for Literal { } impl fmt::Debug for Literal { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_cut() { write!(f, "Cut({})", escape_unicode(&self.v)) } else { @@ -1017,7 +1017,7 @@ mod tests { } impl fmt::Debug for ULiteral { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_cut() { write!(f, "Cut({})", self.v) } else { diff --git a/regex-syntax/src/hir/mod.rs b/regex-syntax/src/hir/mod.rs index a6cc06e..4969f12 100644 --- a/regex-syntax/src/hir/mod.rs +++ b/regex-syntax/src/hir/mod.rs @@ -123,13 +123,13 @@ impl error::Error for Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { crate::error::Formatter::from(self).fmt(f) } } impl fmt::Display for ErrorKind { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // TODO: Remove this on the next breaking semver release. #[allow(deprecated)] f.write_str(self.description()) @@ -727,7 +727,7 @@ impl HirKind { /// This implementation uses constant stack space and heap space proportional /// to the size of the `Hir`. impl fmt::Display for Hir { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use crate::hir::print::Printer; Printer::new().print(self, f) } @@ -859,7 +859,7 @@ impl ClassUnicode { /// Return an iterator over all ranges in this class. /// /// The iterator yields ranges in ascending order. - pub fn iter(&self) -> ClassUnicodeIter { + pub fn iter(&self) -> ClassUnicodeIter<'_> { ClassUnicodeIter(self.set.iter()) } @@ -972,7 +972,7 @@ pub struct ClassUnicodeRange { } impl fmt::Debug for ClassUnicodeRange { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let start = if !self.start.is_whitespace() && !self.start.is_control() { self.start.to_string() @@ -1102,7 +1102,7 @@ impl ClassBytes { /// Return an iterator over all ranges in this class. /// /// The iterator yields ranges in ascending order. - pub fn iter(&self) -> ClassBytesIter { + pub fn iter(&self) -> ClassBytesIter<'_> { ClassBytesIter(self.set.iter()) } @@ -1258,7 +1258,7 @@ impl ClassBytesRange { } impl fmt::Debug for ClassBytesRange { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug = f.debug_struct("ClassBytesRange"); if self.start <= 0x7F { debug.field("start", &(self.start as char)); diff --git a/regex-syntax/src/hir/translate.rs b/regex-syntax/src/hir/translate.rs index c319ad9..99c9493 100644 --- a/regex-syntax/src/hir/translate.rs +++ b/regex-syntax/src/hir/translate.rs @@ -1256,7 +1256,7 @@ mod tests { } #[allow(dead_code)] - fn hir_uclass_query(query: ClassQuery) -> Hir { + fn hir_uclass_query(query: ClassQuery<'_>) -> Hir { Hir::class(hir::Class::Unicode(unicode::class(query).unwrap())) } diff --git a/regex-syntax/src/unicode.rs b/regex-syntax/src/unicode.rs index 447d4f6..f205630 100644 --- a/regex-syntax/src/unicode.rs +++ b/regex-syntax/src/unicode.rs @@ -38,7 +38,7 @@ pub struct CaseFoldError(()); impl error::Error for CaseFoldError {} impl fmt::Display for CaseFoldError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Unicode-aware case folding is not available \ @@ -58,7 +58,7 @@ pub struct UnicodeWordError(()); impl error::Error for UnicodeWordError {} impl fmt::Display for UnicodeWordError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Unicode-aware \\w class is not available \ @@ -285,7 +285,7 @@ enum CanonicalClassQuery { /// Looks up a Unicode class given a query. If one doesn't exist, then /// `None` is returned. -pub fn class(query: ClassQuery) -> Result { +pub fn class(query: ClassQuery<'_>) -> Result { use self::CanonicalClassQuery::*; match query.canonicalize()? { diff --git a/regex-syntax/src/utf8.rs b/regex-syntax/src/utf8.rs index d768684..dc05503 100644 --- a/regex-syntax/src/utf8.rs +++ b/regex-syntax/src/utf8.rs @@ -203,7 +203,7 @@ impl<'a> IntoIterator for &'a Utf8Sequence { } impl fmt::Debug for Utf8Sequence { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use self::Utf8Sequence::*; match *self { One(ref r) => write!(f, "{:?}", r), @@ -237,7 +237,7 @@ impl Utf8Range { } impl fmt::Debug for Utf8Range { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.start == self.end { write!(f, "[{:X}]", self.start) } else { @@ -331,7 +331,7 @@ struct ScalarRange { } impl fmt::Debug for ScalarRange { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "ScalarRange({:X}, {:X})", self.start, self.end) } } diff --git a/src/compile.rs b/src/compile.rs index 1efe45a..8904f15 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -4,9 +4,9 @@ use std::iter; use std::result; use std::sync::Arc; -use crate::syntax::hir::{self, Hir}; -use crate::syntax::is_word_byte; -use crate::syntax::utf8::{Utf8Range, Utf8Sequence, Utf8Sequences}; +use regex_syntax::hir::{self, Hir}; +use regex_syntax::is_word_byte; +use regex_syntax::utf8::{Utf8Range, Utf8Sequence, Utf8Sequences}; use crate::prog::{ EmptyLook, Inst, InstBytes, InstChar, InstEmptyLook, InstPtr, InstRanges, @@ -256,7 +256,7 @@ impl Compiler { /// instruction, and so no patch.entry value makes sense. fn c(&mut self, expr: &Hir) -> ResultOrEmpty { use crate::prog; - use crate::syntax::hir::HirKind::*; + use regex_syntax::hir::HirKind::*; self.check_size()?; match *expr.kind() { @@ -554,7 +554,7 @@ impl Compiler { } fn c_repeat(&mut self, rep: &hir::Repetition) -> ResultOrEmpty { - use crate::syntax::hir::RepetitionKind::*; + use regex_syntax::hir::RepetitionKind::*; match rep.kind { ZeroOrOne => self.c_repeat_zero_or_one(&rep.hir, rep.greedy), ZeroOrMore => self.c_repeat_zero_or_more(&rep.hir, rep.greedy), diff --git a/src/exec.rs b/src/exec.rs index b3c1598..3cec8bb 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -5,9 +5,9 @@ use std::sync::Arc; #[cfg(feature = "perf-literal")] use aho_corasick::{AhoCorasick, AhoCorasickBuilder, MatchKind}; -use crate::syntax::hir::literal::Literals; -use crate::syntax::hir::Hir; -use crate::syntax::ParserBuilder; +use regex_syntax::hir::literal::Literals; +use regex_syntax::hir::Hir; +use regex_syntax::ParserBuilder; use crate::backtrack; use crate::compile::Compiler; @@ -1550,7 +1550,7 @@ impl ProgramCacheInner { /// literals, and if so, returns them. Otherwise, this returns None. #[cfg(feature = "perf-literal")] fn alternation_literals(expr: &Hir) -> Option>> { - use crate::syntax::hir::{HirKind, Literal}; + use regex_syntax::hir::{HirKind, Literal}; // This is pretty hacky, but basically, if `is_alternation_literal` is // true, then we can make several assumptions about the structure of our diff --git a/src/input.rs b/src/input.rs index d2a45c6..5d50ee3 100644 --- a/src/input.rs +++ b/src/input.rs @@ -4,8 +4,6 @@ use std::fmt; use std::ops; use std::u32; -use crate::syntax; - use crate::literal::LiteralSearcher; use crate::prog::InstEmptyLook; use crate::utf8::{decode_last_utf8, decode_utf8}; @@ -379,7 +377,7 @@ impl Char { // available. However, our compiler ensures that if a Unicode word // boundary is used, then the data must also be available. If it isn't, // then the compiler returns an error. - char::from_u32(self.0).map_or(false, syntax::is_word_character) + char::from_u32(self.0).map_or(false, regex_syntax::is_word_character) } /// Returns true iff the byte is a word byte. @@ -387,7 +385,7 @@ impl Char { /// If the byte is absent, then false is returned. pub fn is_word_byte(self) -> bool { match char::from_u32(self.0) { - Some(c) if c <= '\u{7F}' => syntax::is_word_byte(c as u8), + Some(c) if c <= '\u{7F}' => regex_syntax::is_word_byte(c as u8), None | Some(_) => false, } } diff --git a/src/lib.rs b/src/lib.rs index 84e6e49..7f2dec8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,12 +22,6 @@ used by adding `regex` to your dependencies in your project's `Cargo.toml`. regex = "1" ``` -If you're using Rust 2015, then you'll also need to add it to your crate root: - -```rust -extern crate regex; -``` - # Example: find a date General use of regular expressions in this package involves compiling an @@ -68,9 +62,7 @@ regular expressions are compiled exactly once. For example: ```rust -#[macro_use] extern crate lazy_static; -extern crate regex; - +use lazy_static::lazy_static; use regex::Regex; fn some_helper_function(text: &str) -> bool { @@ -94,7 +86,7 @@ matches. For example, to find all dates in a string and be able to access them by their component pieces: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap(); let text = "2012-03-14, 2013-01-01 and 2014-07-05"; @@ -119,7 +111,7 @@ clearer, we can *name* our capture groups and use those names as variables in our replacement text: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"(?P\d{4})-(?P\d{2})-(?P\d{2})").unwrap(); let before = "2012-03-14, 2013-01-01 and 2014-07-05"; @@ -136,7 +128,7 @@ Note that if your regex gets complicated, you can use the `x` flag to enable insignificant whitespace mode, which also lets you write comments: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"(?x) (?P\d{4}) # the year @@ -217,7 +209,7 @@ Unicode scalar values. This means you can use Unicode characters directly in your expression: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"(?i)Δ+").unwrap(); let mat = re.find("ΔδΔ").unwrap(); @@ -244,7 +236,7 @@ of boolean properties are available as character classes. For example, you can match a sequence of numerals, Greek or Cherokee letters: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"[\pN\p{Greek}\p{Cherokee}]+").unwrap(); let mat = re.find("abcΔᎠβⅠᏴγδⅡxyz").unwrap(); @@ -391,7 +383,7 @@ Flags can be toggled within a pattern. Here's an example that matches case-insensitively for the first part but case-sensitively for the second part: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"(?i)a+(?-i)b+").unwrap(); let cap = re.captures("AaAaAbbBBBb").unwrap(); @@ -425,7 +417,7 @@ Here is an example that uses an ASCII word boundary instead of a Unicode word boundary: ```rust -# extern crate regex; use regex::Regex; +# use regex::Regex; # fn main() { let re = Regex::new(r"(?-u:\b).+(?-u:\b)").unwrap(); let cap = re.captures("$$abc$$").unwrap(); @@ -620,12 +612,10 @@ another matching engine with fixed memory requirements. #[cfg(not(feature = "std"))] compile_error!("`std` feature is currently required to build this crate"); -#[cfg(feature = "perf-literal")] -extern crate aho_corasick; - - -extern crate regex_syntax as syntax; - +// To check README's example +// TODO: Re-enable this once the MSRV is 1.43 or greater. +// See: https://github.com/rust-lang/regex/issues/684 +// See: https://github.com/rust-lang/regex/issues/685 // #[cfg(doctest)] // doc_comment::doctest!("../README.md"); diff --git a/src/literal/imp.rs b/src/literal/imp.rs index 83fb648..82f050a 100644 --- a/src/literal/imp.rs +++ b/src/literal/imp.rs @@ -1,9 +1,8 @@ -// use std::cmp; use std::mem; use aho_corasick::{self, packed, AhoCorasick, AhoCorasickBuilder}; use memchr::{memchr, memchr2, memchr3, memmem}; -use crate::syntax::hir::literal::{Literal, Literals}; +use regex_syntax::hir::literal::{Literal, Literals}; /// A prefix extracted from a compiled regular expression. /// diff --git a/src/re_bytes.rs b/src/re_bytes.rs index 15afa19..ae55d6d 100644 --- a/src/re_bytes.rs +++ b/src/re_bytes.rs @@ -133,7 +133,7 @@ impl Regex { /// bytes: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let text = b"I categorically deny having triskaidekaphobia."; /// assert!(Regex::new(r"\b\w{13}\b").unwrap().is_match(text)); @@ -156,7 +156,7 @@ impl Regex { /// ASCII word bytes: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let text = b"I categorically deny having triskaidekaphobia."; /// let mat = Regex::new(r"\b\w{13}\b").unwrap().find(text).unwrap(); @@ -177,7 +177,7 @@ impl Regex { /// word bytes: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let text = b"Retroactively relinquishing remunerations is reprehensible."; /// for mat in Regex::new(r"\b\w{13}\b").unwrap().find_iter(text) { @@ -205,7 +205,7 @@ impl Regex { /// year separately. /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"'([^']+)'\s+\((\d{4})\)").unwrap(); /// let text = b"Not my favorite movie: 'Citizen Kane' (1941)."; @@ -227,7 +227,7 @@ impl Regex { /// We can make this example a bit clearer by using *named* capture groups: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"'(?P[^']+)'\s+\((?P<year>\d{4})\)") /// .unwrap(); @@ -271,7 +271,7 @@ impl Regex { /// some text, where the movie is formatted like "'Title' (xxxx)": /// /// ```rust - /// # extern crate regex; use std::str; use regex::bytes::Regex; + /// # use std::str; use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)") /// .unwrap(); @@ -305,7 +305,7 @@ impl Regex { /// To split a string delimited by arbitrary amounts of spaces or tabs: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"[ \t]+").unwrap(); /// let fields: Vec<&[u8]> = re.split(b"a b \t c\td e").collect(); @@ -331,7 +331,7 @@ impl Regex { /// Get the first two words in some text: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"\W+").unwrap(); /// let fields: Vec<&[u8]> = re.splitn(b"Hey! How are you?", 3).collect(); @@ -379,7 +379,7 @@ impl Regex { /// In typical usage, this can just be a normal byte string: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new("[^01]+").unwrap(); /// assert_eq!(re.replace(b"1078910", &b""[..]), &b"1010"[..]); @@ -392,7 +392,7 @@ impl Regex { /// group matches easily: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # use regex::bytes::Captures; fn main() { /// let re = Regex::new(r"([^,\s]+),\s+(\S+)").unwrap(); /// let result = re.replace(b"Springsteen, Bruce", |caps: &Captures| { @@ -411,7 +411,7 @@ impl Regex { /// with named capture groups: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)").unwrap(); /// let result = re.replace(b"Springsteen, Bruce", &b"$first $last"[..]); @@ -428,7 +428,7 @@ impl Regex { /// underscore: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let re = Regex::new(r"(?P<first>\w+)\s+(?P<second>\w+)").unwrap(); /// let result = re.replace(b"deep fried", &b"${first}_$second"[..]); @@ -445,7 +445,7 @@ impl Regex { /// byte string with `NoExpand`: /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// use regex::bytes::NoExpand; /// @@ -546,7 +546,7 @@ impl Regex { /// `a`. /// /// ```rust - /// # extern crate regex; use regex::bytes::Regex; + /// # use regex::bytes::Regex; /// # fn main() { /// let text = b"aaaaa"; /// let pos = Regex::new(r"a+").unwrap().shortest_match(text); diff --git a/src/re_unicode.rs b/src/re_unicode.rs index 9298bd9..142c78f 100644 --- a/src/re_unicode.rs +++ b/src/re_unicode.rs @@ -7,7 +7,6 @@ use std::str::FromStr; use std::sync::Arc; use crate::find_byte::find_byte; -use crate::syntax; use crate::error::Error; use crate::exec::{Exec, ExecNoSyncStr}; @@ -20,7 +19,7 @@ use crate::re_trait::{self, RegularExpression, SubCapturesPosIter}; /// The string returned may be safely used as a literal in a regular /// expression. pub fn escape(text: &str) -> String { - syntax::escape(text) + regex_syntax::escape(text) } /// Match represents a single match of a regex in a haystack. @@ -189,7 +188,7 @@ impl Regex { /// Unicode word characters: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let text = "I categorically deny having triskaidekaphobia."; /// assert!(Regex::new(r"\b\w{13}\b").unwrap().is_match(text)); @@ -212,7 +211,7 @@ impl Regex { /// Unicode word characters: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let text = "I categorically deny having triskaidekaphobia."; /// let mat = Regex::new(r"\b\w{13}\b").unwrap().find(text).unwrap(); @@ -234,7 +233,7 @@ impl Regex { /// word characters: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let text = "Retroactively relinquishing remunerations is reprehensible."; /// for mat in Regex::new(r"\b\w{13}\b").unwrap().find_iter(text) { @@ -262,7 +261,7 @@ impl Regex { /// year separately. /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"'([^']+)'\s+\((\d{4})\)").unwrap(); /// let text = "Not my favorite movie: 'Citizen Kane' (1941)."; @@ -284,7 +283,7 @@ impl Regex { /// We can make this example a bit clearer by using *named* capture groups: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)") /// .unwrap(); @@ -328,7 +327,7 @@ impl Regex { /// some text, where the movie is formatted like "'Title' (xxxx)": /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"'(?P<title>[^']+)'\s+\((?P<year>\d{4})\)") /// .unwrap(); @@ -361,7 +360,7 @@ impl Regex { /// To split a string delimited by arbitrary amounts of spaces or tabs: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"[ \t]+").unwrap(); /// let fields: Vec<&str> = re.split("a b \t c\td e").collect(); @@ -385,7 +384,7 @@ impl Regex { /// Get the first two words in some text: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"\W+").unwrap(); /// let fields: Vec<&str> = re.splitn("Hey! How are you?", 3).collect(); @@ -432,7 +431,7 @@ impl Regex { /// In typical usage, this can just be a normal string: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new("[^01]+").unwrap(); /// assert_eq!(re.replace("1078910", ""), "1010"); @@ -445,7 +444,7 @@ impl Regex { /// capturing group matches easily: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # use regex::Captures; fn main() { /// let re = Regex::new(r"([^,\s]+),\s+(\S+)").unwrap(); /// let result = re.replace("Springsteen, Bruce", |caps: &Captures| { @@ -461,7 +460,7 @@ impl Regex { /// with named capture groups: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"(?P<last>[^,\s]+),\s+(?P<first>\S+)").unwrap(); /// let result = re.replace("Springsteen, Bruce", "$first $last"); @@ -478,7 +477,7 @@ impl Regex { /// underscore: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let re = Regex::new(r"(?P<first>\w+)\s+(?P<second>\w+)").unwrap(); /// let result = re.replace("deep fried", "${first}_$second"); @@ -495,7 +494,7 @@ impl Regex { /// byte string with `NoExpand`: /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// use regex::NoExpand; /// @@ -605,7 +604,7 @@ impl Regex { /// `a`. /// /// ```rust - /// # extern crate regex; use regex::Regex; + /// # use regex::Regex; /// # fn main() { /// let text = "aaaaa"; /// let pos = Regex::new(r"a+").unwrap().shortest_match(text);