mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-01 19:23:50 +00:00
Auto merge of #9169 - Alexendoo:message-convention-regex, r=flip1995
Use `LazyLock` for `lint_message_convention` regexes They were being recompiled for `Message::new` call, for me this shaves 7s off the time it takes to run the test. Also removes a redundant exception from the list and joins the various `message...` exceptions into one changelog: none
This commit is contained in:
commit
44be2d4b0e
@ -1,8 +1,10 @@
|
|||||||
|
#![feature(once_cell)]
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
#![warn(rust_2018_idioms, unused_lifetimes)]
|
#![warn(rust_2018_idioms, unused_lifetimes)]
|
||||||
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use regex::RegexSet;
|
use regex::RegexSet;
|
||||||
|
|
||||||
@ -14,43 +16,45 @@ struct Message {
|
|||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
fn new(path: PathBuf) -> Self {
|
fn new(path: PathBuf) -> Self {
|
||||||
let content: String = std::fs::read_to_string(&path).unwrap();
|
|
||||||
// we don't want the first letter after "error: ", "help: " ... to be capitalized
|
// we don't want the first letter after "error: ", "help: " ... to be capitalized
|
||||||
// also no punctuation (except for "?" ?) at the end of a line
|
// also no punctuation (except for "?" ?) at the end of a line
|
||||||
let regex_set: RegexSet = RegexSet::new(&[
|
static REGEX_SET: LazyLock<RegexSet> = LazyLock::new(|| {
|
||||||
r"error: [A-Z]",
|
RegexSet::new(&[
|
||||||
r"help: [A-Z]",
|
r"error: [A-Z]",
|
||||||
r"warning: [A-Z]",
|
r"help: [A-Z]",
|
||||||
r"note: [A-Z]",
|
r"warning: [A-Z]",
|
||||||
r"try this: [A-Z]",
|
r"note: [A-Z]",
|
||||||
r"error: .*[.!]$",
|
r"try this: [A-Z]",
|
||||||
r"help: .*[.!]$",
|
r"error: .*[.!]$",
|
||||||
r"warning: .*[.!]$",
|
r"help: .*[.!]$",
|
||||||
r"note: .*[.!]$",
|
r"warning: .*[.!]$",
|
||||||
r"try this: .*[.!]$",
|
r"note: .*[.!]$",
|
||||||
])
|
r"try this: .*[.!]$",
|
||||||
.unwrap();
|
])
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
// sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
|
// sometimes the first character is capitalized and it is legal (like in "C-like enum variants") or
|
||||||
// we want to ask a question ending in "?"
|
// we want to ask a question ending in "?"
|
||||||
let exceptions_set: RegexSet = RegexSet::new(&[
|
static EXCEPTIONS_SET: LazyLock<RegexSet> = LazyLock::new(|| {
|
||||||
r".*C-like enum variant discriminant is not portable to 32-bit targets",
|
RegexSet::new(&[
|
||||||
r".*did you mean `unix`?",
|
r"\.\.\.$",
|
||||||
r".*the arguments may be inverted...",
|
r".*C-like enum variant discriminant is not portable to 32-bit targets",
|
||||||
r".*Intel x86 assembly syntax used",
|
r".*Intel x86 assembly syntax used",
|
||||||
r".*AT&T x86 assembly syntax used",
|
r".*AT&T x86 assembly syntax used",
|
||||||
r".*remove .*the return type...",
|
r"note: Clippy version: .*",
|
||||||
r"note: Clippy version: .*",
|
r"the compiler unexpectedly panicked. this is a bug.",
|
||||||
r"the compiler unexpectedly panicked. this is a bug.",
|
])
|
||||||
r"remove the `if let` statement in the for loop and then...",
|
.unwrap()
|
||||||
])
|
});
|
||||||
.unwrap();
|
|
||||||
|
let content: String = std::fs::read_to_string(&path).unwrap();
|
||||||
|
|
||||||
let bad_lines = content
|
let bad_lines = content
|
||||||
.lines()
|
.lines()
|
||||||
.filter(|line| regex_set.matches(line).matched_any())
|
.filter(|line| REGEX_SET.matches(line).matched_any())
|
||||||
// ignore exceptions
|
// ignore exceptions
|
||||||
.filter(|line| !exceptions_set.matches(line).matched_any())
|
.filter(|line| !EXCEPTIONS_SET.matches(line).matched_any())
|
||||||
.map(ToOwned::to_owned)
|
.map(ToOwned::to_owned)
|
||||||
.collect::<Vec<String>>();
|
.collect::<Vec<String>>();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user