summary refs log tree commit diff
path: root/src/liblog
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-20 10:45:29 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-23 21:04:10 -0800
commit6c29708bf906fa9075bb96b76fd7f6cc81eda43c (patch)
treef34f763e8ee24bba284b7902496d370667e2a1f5 /src/liblog
parent494896f2dd4ff541c371a8952b8f38cb02409835 (diff)
downloadrust-6c29708bf906fa9075bb96b76fd7f6cc81eda43c.tar.gz
rust-6c29708bf906fa9075bb96b76fd7f6cc81eda43c.zip
regex: Remove in-tree version
The regex library was largely used for non-critical aspects of the compiler and
various external tooling. The library at this point is duplicated with its
out-of-tree counterpart and as such imposes a bit of a maintenance overhead as
well as compile time hit for the compiler itself.

The last major user of the regex library is the libtest library, using regexes
for filters when running tests. This removal means that the filtering has gone
back to substring matching rather than using regexes.
Diffstat (limited to 'src/liblog')
-rw-r--r--src/liblog/directive.rs15
-rw-r--r--src/liblog/lib.rs24
2 files changed, 12 insertions, 27 deletions
diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs
index d741019aa7b..5efa799f562 100644
--- a/src/liblog/directive.rs
+++ b/src/liblog/directive.rs
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use regex::Regex;
 use std::ascii::AsciiExt;
 use std::cmp;
 
@@ -34,7 +33,7 @@ fn parse_log_level(level: &str) -> Option<u32> {
 ///
 /// Valid log levels are 0-255, with the most likely ones being 1-4 (defined in
 /// std::).  Also supports string log levels of error, warn, info, and debug
-pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<Regex>) {
+pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<String>) {
     let mut dirs = Vec::new();
 
     let mut parts = spec.split('/');
@@ -80,17 +79,7 @@ pub fn parse_logging_spec(spec: &str) -> (Vec<LogDirective>, Option<Regex>) {
         });
     }});
 
-    let filter = filter.map_or(None, |filter| {
-        match Regex::new(filter) {
-            Ok(re) => Some(re),
-            Err(e) => {
-                println!("warning: invalid regex filter - {:?}", e);
-                None
-            }
-        }
-    });
-
-    return (dirs, filter);
+    (dirs, filter.map(|s| s.to_string()))
 }
 
 #[cfg(test)]
diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs
index 4da07c50c59..e7c5bc35f76 100644
--- a/src/liblog/lib.rs
+++ b/src/liblog/lib.rs
@@ -123,11 +123,11 @@
 //!
 //! # Filtering results
 //!
-//! A RUST_LOG directive may include a regex filter. The syntax is to append `/`
-//! followed by a regex. Each message is checked against the regex, and is only
-//! logged if it matches. Note that the matching is done after formatting the log
-//! string but before adding any logging meta-data. There is a single filter for all
-//! modules.
+//! A RUST_LOG directive may include a string filter. The syntax is to append
+//! `/` followed by a string. Each message is checked against the string and is
+//! only logged if it contains the string. Note that the matching is done after
+//! formatting the log string but before adding any logging meta-data. There is
+//! a single filter for all modules.
 //!
 //! Some examples:
 //!
@@ -172,8 +172,6 @@
 #![allow(unstable)]
 #![deny(missing_docs)]
 
-extern crate regex;
-
 use std::cell::RefCell;
 use std::fmt;
 use std::io::LineBufferedWriter;
@@ -185,8 +183,6 @@ use std::rt;
 use std::slice;
 use std::sync::{Once, ONCE_INIT};
 
-use regex::Regex;
-
 use directive::LOG_LEVEL_NAMES;
 
 #[macro_use]
@@ -209,8 +205,8 @@ static mut LOG_LEVEL: u32 = MAX_LOG_LEVEL;
 static mut DIRECTIVES: *const Vec<directive::LogDirective> =
     0 as *const Vec<directive::LogDirective>;
 
-/// Optional regex filter.
-static mut FILTER: *const Regex = 0 as *const _;
+/// Optional filter.
+static mut FILTER: *const String = 0 as *const _;
 
 /// Debug log level
 pub const DEBUG: u32 = 4;
@@ -288,7 +284,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) {
     // Test the literal string from args against the current filter, if there
     // is one.
     match unsafe { FILTER.as_ref() } {
-        Some(filter) if !filter.is_match(&args.to_string()[]) => return,
+        Some(filter) if !args.to_string().contains(&filter[]) => return,
         _ => {}
     }
 
@@ -435,8 +431,8 @@ fn init() {
             DIRECTIVES = ptr::null();
 
             if !FILTER.is_null() {
-                let _filter: Box<Regex> = mem::transmute(FILTER);
-                FILTER = ptr::null();
+                let _filter: Box<String> = mem::transmute(FILTER);
+                FILTER = 0 as *const _;
             }
         });
     }