1
Fork 0

Use symbols instead of strings

This commit is contained in:
Oliver Scherer 2019-05-14 01:34:08 +02:00
parent 42480fd031
commit b2dbda4d48
82 changed files with 1206 additions and 700 deletions

View file

@ -1,5 +1,6 @@
use crate::consts::{constant, Constant};
use crate::utils::{is_expn_of, match_type, paths, span_help_and_lint, span_lint};
use crate::utils::{is_expn_of, match_type, paths, span_help_and_lint, span_lint, match_def_path};
use crate::utils::sym;
use if_chain::if_chain;
use regex_syntax;
use rustc::hir::*;
@ -83,8 +84,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
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");
if match_type(cx, cx.tables.expr_ty(expr), &*paths::REGEX);
if let Some(span) = is_expn_of(expr.span, *sym::regex);
then {
if !self.spans.contains(&span) {
span_lint(cx,
@ -112,15 +113,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Regex {
if args.len() == 1;
if let Some(def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id();
then {
if cx.match_def_path(def_id, &paths::REGEX_NEW) ||
cx.match_def_path(def_id, &paths::REGEX_BUILDER_NEW) {
if match_def_path(cx, def_id, &*paths::REGEX_NEW) ||
match_def_path(cx, def_id, &*paths::REGEX_BUILDER_NEW) {
check_regex(cx, &args[0], true);
} else if cx.match_def_path(def_id, &paths::REGEX_BYTES_NEW) ||
cx.match_def_path(def_id, &paths::REGEX_BYTES_BUILDER_NEW) {
} else if match_def_path(cx, def_id, &*paths::REGEX_BYTES_NEW) ||
match_def_path(cx, def_id, &*paths::REGEX_BYTES_BUILDER_NEW) {
check_regex(cx, &args[0], false);
} else if cx.match_def_path(def_id, &paths::REGEX_SET_NEW) {
} else if match_def_path(cx, def_id, &*paths::REGEX_SET_NEW) {
check_set(cx, &args[0], true);
} else if cx.match_def_path(def_id, &paths::REGEX_BYTES_SET_NEW) {
} else if match_def_path(cx, def_id, &*paths::REGEX_BYTES_SET_NEW) {
check_set(cx, &args[0], false);
}
}