Deprecate regex_macro lint
This commit is contained in:
@@ -153,5 +153,13 @@ declare_deprecated_lint! {
|
|||||||
///
|
///
|
||||||
/// **Deprecation reason:** Associated-constants are now preferred.
|
/// **Deprecation reason:** Associated-constants are now preferred.
|
||||||
pub REPLACE_CONSTS,
|
pub REPLACE_CONSTS,
|
||||||
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants"
|
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants"
|
||||||
|
}
|
||||||
|
|
||||||
|
declare_deprecated_lint! {
|
||||||
|
/// **What it does:** Nothing. This lint has been deprecated.
|
||||||
|
///
|
||||||
|
/// **Deprecation reason:** The regex! macro does not exist anymore.
|
||||||
|
pub REGEX_MACRO,
|
||||||
|
"the regex! macro has been removed from the regex crate in 2018"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -460,7 +460,11 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
);
|
);
|
||||||
store.register_removed(
|
store.register_removed(
|
||||||
"clippy::replace_consts",
|
"clippy::replace_consts",
|
||||||
"associated-constants `MIN`/`MAX` of integers are prefer to `{min,max}_value()` and module constants",
|
"associated-constants `MIN`/`MAX` of integers are prefered to `{min,max}_value()` and module constants",
|
||||||
|
);
|
||||||
|
store.register_removed(
|
||||||
|
"clippy::regex_macro",
|
||||||
|
"the regex! macro has been removed from the regex crate in 2018",
|
||||||
);
|
);
|
||||||
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
|
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
|
||||||
|
|
||||||
@@ -755,7 +759,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
&reference::DEREF_ADDROF,
|
&reference::DEREF_ADDROF,
|
||||||
&reference::REF_IN_DEREF,
|
&reference::REF_IN_DEREF,
|
||||||
®ex::INVALID_REGEX,
|
®ex::INVALID_REGEX,
|
||||||
®ex::REGEX_MACRO,
|
|
||||||
®ex::TRIVIAL_REGEX,
|
®ex::TRIVIAL_REGEX,
|
||||||
&returns::NEEDLESS_RETURN,
|
&returns::NEEDLESS_RETURN,
|
||||||
&returns::UNUSED_UNIT,
|
&returns::UNUSED_UNIT,
|
||||||
@@ -1380,7 +1383,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
LintId::of(&reference::DEREF_ADDROF),
|
LintId::of(&reference::DEREF_ADDROF),
|
||||||
LintId::of(&reference::REF_IN_DEREF),
|
LintId::of(&reference::REF_IN_DEREF),
|
||||||
LintId::of(®ex::INVALID_REGEX),
|
LintId::of(®ex::INVALID_REGEX),
|
||||||
LintId::of(®ex::REGEX_MACRO),
|
|
||||||
LintId::of(®ex::TRIVIAL_REGEX),
|
LintId::of(®ex::TRIVIAL_REGEX),
|
||||||
LintId::of(&returns::NEEDLESS_RETURN),
|
LintId::of(&returns::NEEDLESS_RETURN),
|
||||||
LintId::of(&returns::UNUSED_UNIT),
|
LintId::of(&returns::UNUSED_UNIT),
|
||||||
@@ -1517,7 +1519,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
|
LintId::of(&redundant_field_names::REDUNDANT_FIELD_NAMES),
|
||||||
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
|
LintId::of(&redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING),
|
||||||
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
|
LintId::of(&redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES),
|
||||||
LintId::of(®ex::REGEX_MACRO),
|
|
||||||
LintId::of(®ex::TRIVIAL_REGEX),
|
LintId::of(®ex::TRIVIAL_REGEX),
|
||||||
LintId::of(&returns::NEEDLESS_RETURN),
|
LintId::of(&returns::NEEDLESS_RETURN),
|
||||||
LintId::of(&returns::UNUSED_UNIT),
|
LintId::of(&returns::UNUSED_UNIT),
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
use crate::utils::{is_expn_of, match_def_path, match_type, paths, span_lint, span_lint_and_help};
|
use crate::utils::{match_def_path, paths, span_lint, span_lint_and_help};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc_ast::ast::{LitKind, StrStyle};
|
use rustc_ast::ast::{LitKind, StrStyle};
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_hir::{Block, BorrowKind, Crate, Expr, ExprKind, HirId};
|
use rustc_hir::{BorrowKind, Expr, ExprKind, HirId};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
use rustc_span::source_map::{BytePos, Span};
|
use rustc_span::source_map::{BytePos, Span};
|
||||||
@@ -46,66 +46,15 @@ declare_clippy_lint! {
|
|||||||
"trivial regular expressions"
|
"trivial regular expressions"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare_clippy_lint! {
|
|
||||||
/// **What it does:** Checks for usage of `regex!(_)` which (as of now) is
|
|
||||||
/// usually slower than `Regex::new(_)` unless called in a loop (which is a bad
|
|
||||||
/// idea anyway).
|
|
||||||
///
|
|
||||||
/// **Why is this bad?** Performance, at least for now. The macro version is
|
|
||||||
/// likely to catch up long-term, but for now the dynamic version is faster.
|
|
||||||
///
|
|
||||||
/// **Known problems:** None.
|
|
||||||
///
|
|
||||||
/// **Example:**
|
|
||||||
/// ```ignore
|
|
||||||
/// regex!("foo|bar")
|
|
||||||
/// ```
|
|
||||||
pub REGEX_MACRO,
|
|
||||||
style,
|
|
||||||
"use of `regex!(_)` instead of `Regex::new(_)`"
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct Regex {
|
pub struct Regex {
|
||||||
spans: FxHashSet<Span>,
|
spans: FxHashSet<Span>,
|
||||||
last: Option<HirId>,
|
last: Option<HirId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl_lint_pass!(Regex => [INVALID_REGEX, REGEX_MACRO, TRIVIAL_REGEX]);
|
impl_lint_pass!(Regex => [INVALID_REGEX, TRIVIAL_REGEX]);
|
||||||
|
|
||||||
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
|
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
|
||||||
fn check_crate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx Crate<'_>) {
|
|
||||||
self.spans.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_block(&mut self, cx: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
|
|
||||||
if_chain! {
|
|
||||||
if self.last.is_none();
|
|
||||||
if let Some(ref expr) = block.expr;
|
|
||||||
if match_type(cx, cx.tables().expr_ty(expr), &paths::REGEX);
|
|
||||||
if let Some(span) = is_expn_of(expr.span, "regex");
|
|
||||||
then {
|
|
||||||
if !self.spans.contains(&span) {
|
|
||||||
span_lint(
|
|
||||||
cx,
|
|
||||||
REGEX_MACRO,
|
|
||||||
span,
|
|
||||||
"`regex!(_)` found. \
|
|
||||||
Please use `Regex::new(_)`, which is faster for now."
|
|
||||||
);
|
|
||||||
self.spans.insert(span);
|
|
||||||
}
|
|
||||||
self.last = Some(block.hir_id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_block_post(&mut self, _: &LateContext<'a, 'tcx>, block: &'tcx Block<'_>) {
|
|
||||||
if self.last.map_or(false, |id| block.hir_id == id) {
|
|
||||||
self.last = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Call(ref fun, ref args) = expr.kind;
|
if let ExprKind::Call(ref fun, ref args) = expr.kind;
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ pub const RANGE_TO_STD: [&str; 3] = ["std", "ops", "RangeTo"];
|
|||||||
pub const RC: [&str; 3] = ["alloc", "rc", "Rc"];
|
pub const RC: [&str; 3] = ["alloc", "rc", "Rc"];
|
||||||
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
|
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
|
||||||
pub const RECEIVER: [&str; 4] = ["std", "sync", "mpsc", "Receiver"];
|
pub const RECEIVER: [&str; 4] = ["std", "sync", "mpsc", "Receiver"];
|
||||||
pub const REGEX: [&str; 3] = ["regex", "re_unicode", "Regex"];
|
|
||||||
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
|
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
|
||||||
pub const REGEX_BYTES_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "bytes", "RegexBuilder", "new"];
|
pub const REGEX_BYTES_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "bytes", "RegexBuilder", "new"];
|
||||||
pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "re_bytes", "Regex", "new"];
|
pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "re_bytes", "Regex", "new"];
|
||||||
|
|||||||
@@ -1865,13 +1865,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
|
|||||||
deprecation: None,
|
deprecation: None,
|
||||||
module: "reference",
|
module: "reference",
|
||||||
},
|
},
|
||||||
Lint {
|
|
||||||
name: "regex_macro",
|
|
||||||
group: "style",
|
|
||||||
desc: "use of `regex!(_)` instead of `Regex::new(_)`",
|
|
||||||
deprecation: None,
|
|
||||||
module: "regex",
|
|
||||||
},
|
|
||||||
Lint {
|
Lint {
|
||||||
name: "rest_pat_in_fully_bound_structs",
|
name: "rest_pat_in_fully_bound_structs",
|
||||||
group: "restriction",
|
group: "restriction",
|
||||||
|
|||||||
@@ -7,5 +7,6 @@
|
|||||||
#[warn(clippy::invalid_ref)]
|
#[warn(clippy::invalid_ref)]
|
||||||
#[warn(clippy::into_iter_on_array)]
|
#[warn(clippy::into_iter_on_array)]
|
||||||
#[warn(clippy::unused_label)]
|
#[warn(clippy::unused_label)]
|
||||||
|
#[warn(clippy::regex_macro)]
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|||||||
@@ -54,11 +54,17 @@ error: lint `clippy::unused_label` has been removed: `this lint has been uplifte
|
|||||||
LL | #[warn(clippy::unused_label)]
|
LL | #[warn(clippy::unused_label)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: lint `clippy::regex_macro` has been removed: `the regex! macro has been removed from the regex crate in 2018`
|
||||||
|
--> $DIR/deprecated.rs:10:8
|
||||||
|
|
|
||||||
|
LL | #[warn(clippy::regex_macro)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
|
error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon`
|
||||||
--> $DIR/deprecated.rs:1:8
|
--> $DIR/deprecated.rs:1:8
|
||||||
|
|
|
|
||||||
LL | #[warn(clippy::str_to_string)]
|
LL | #[warn(clippy::str_to_string)]
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 10 previous errors
|
error: aborting due to 11 previous errors
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
#![warn(clippy::invalid_regex, clippy::trivial_regex, clippy::regex_macro)]
|
#![warn(clippy::invalid_regex, clippy::trivial_regex)]
|
||||||
|
|
||||||
extern crate regex;
|
extern crate regex;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user