mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-01 00:49:30 +00:00
speed up lint using blocks and types
This commit is contained in:
parent
3b0b9e0e06
commit
275795fab3
1 changed files with 19 additions and 15 deletions
16
src/regex.rs
16
src/regex.rs
|
@ -5,12 +5,12 @@ use syntax::ast::Lit_::LitStr;
|
||||||
use syntax::codemap::{Span, BytePos};
|
use syntax::codemap::{Span, BytePos};
|
||||||
use syntax::parse::token::InternedString;
|
use syntax::parse::token::InternedString;
|
||||||
use rustc_front::hir::*;
|
use rustc_front::hir::*;
|
||||||
use rustc_front::intravisit::{Visitor, walk_expr};
|
use rustc_front::intravisit::{Visitor, walk_block};
|
||||||
use rustc::middle::const_eval::{eval_const_expr_partial, ConstVal};
|
use rustc::middle::const_eval::{eval_const_expr_partial, ConstVal};
|
||||||
use rustc::middle::const_eval::EvalHint::ExprTypeChecked;
|
use rustc::middle::const_eval::EvalHint::ExprTypeChecked;
|
||||||
use rustc::lint::*;
|
use rustc::lint::*;
|
||||||
|
|
||||||
use utils::{is_expn_of, match_path, REGEX_NEW_PATH, span_lint, span_help_and_lint};
|
use utils::{is_expn_of, match_path, match_type, REGEX_NEW_PATH, span_lint, span_help_and_lint};
|
||||||
|
|
||||||
/// **What it does:** This lint checks `Regex::new(_)` invocations for correct regex syntax.
|
/// **What it does:** This lint checks `Regex::new(_)` invocations for correct regex syntax.
|
||||||
///
|
///
|
||||||
|
@ -167,8 +167,12 @@ struct RegexVisitor<'v, 't: 'v> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'v, 't: 'v> Visitor<'v> for RegexVisitor<'v, 't> {
|
impl<'v, 't: 'v> Visitor<'v> for RegexVisitor<'v, 't> {
|
||||||
fn visit_expr(&mut self, expr: &'v Expr) {
|
fn visit_block(&mut self, block: &'v Block) {
|
||||||
if let Some(span) = is_expn_of(self.cx, expr.span, "regex") {
|
if_let_chain!{[
|
||||||
|
let Some(ref expr) = block.expr,
|
||||||
|
match_type(self.cx, self.cx.tcx.expr_ty(expr), &["regex", "re", "Regex"]),
|
||||||
|
let Some(span) = is_expn_of(self.cx, expr.span, "regex")
|
||||||
|
], {
|
||||||
if self.spans.contains(&span) {
|
if self.spans.contains(&span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -179,7 +183,7 @@ impl<'v, 't: 'v> Visitor<'v> for RegexVisitor<'v, 't> {
|
||||||
Please use `Regex::new(_)`, which is faster for now.");
|
Please use `Regex::new(_)`, which is faster for now.");
|
||||||
self.spans.insert(span);
|
self.spans.insert(span);
|
||||||
return;
|
return;
|
||||||
}
|
}}
|
||||||
walk_expr(self, expr);
|
walk_block(self, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue