Skip to content

Commit 60a609a

Browse files
committed
Auto merge of #4110 - rust-lang:symbolic_wasteland, r=oli-obk
Prevent symbocalypse r? @Manishearth This is strictly better, we can just not modify rustc and bump solely the clippy submodule and then implement diagnostic lang items without beta looming over us changelog: none
2 parents 11194e3 + f49ef0e commit 60a609a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+714
-1228
lines changed

clippy_lints/src/approx_const.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use crate::utils::span_lint;
2-
use crate::utils::sym;
3-
use lazy_static::lazy_static;
42
use rustc::hir::*;
53
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
64
use rustc::{declare_lint_pass, declare_tool_lint};
75
use std::f64::consts as f64;
86
use syntax::ast::{FloatTy, LitKind};
97
use syntax::symbol;
10-
use syntax::symbol::Symbol;
118

129
declare_clippy_lint! {
1310
/// **What it does:** Checks for floating point literals that approximate
@@ -33,27 +30,25 @@ declare_clippy_lint! {
3330
"the approximate of a known float constant (in `std::fXX::consts`)"
3431
}
3532

36-
lazy_static! {
3733
// Tuples are of the form (constant, name, min_digits)
38-
static ref KNOWN_CONSTS: [(f64, Symbol, usize); 16] = [
39-
(f64::E, *sym::E, 4),
40-
(f64::FRAC_1_PI, *sym::FRAC_1_PI, 4),
41-
(f64::FRAC_1_SQRT_2, *sym::FRAC_1_SQRT_2, 5),
42-
(f64::FRAC_2_PI, *sym::FRAC_2_PI, 5),
43-
(f64::FRAC_2_SQRT_PI, *sym::FRAC_2_SQRT_PI, 5),
44-
(f64::FRAC_PI_2, *sym::FRAC_PI_2, 5),
45-
(f64::FRAC_PI_3, *sym::FRAC_PI_3, 5),
46-
(f64::FRAC_PI_4, *sym::FRAC_PI_4, 5),
47-
(f64::FRAC_PI_6, *sym::FRAC_PI_6, 5),
48-
(f64::FRAC_PI_8, *sym::FRAC_PI_8, 5),
49-
(f64::LN_10, *sym::LN_10, 5),
50-
(f64::LN_2, *sym::LN_2, 5),
51-
(f64::LOG10_E, *sym::LOG10_E, 5),
52-
(f64::LOG2_E, *sym::LOG2_E, 5),
53-
(f64::PI, *sym::PI, 3),
54-
(f64::SQRT_2, *sym::SQRT_2, 5),
34+
const KNOWN_CONSTS: [(f64, &str, usize); 16] = [
35+
(f64::E, "E", 4),
36+
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
37+
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
38+
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
39+
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
40+
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
41+
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
42+
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
43+
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
44+
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
45+
(f64::LN_10, "LN_10", 5),
46+
(f64::LN_2, "LN_2", 5),
47+
(f64::LOG10_E, "LOG10_E", 5),
48+
(f64::LOG2_E, "LOG2_E", 5),
49+
(f64::PI, "PI", 3),
50+
(f64::SQRT_2, "SQRT_2", 5),
5551
];
56-
}
5752

5853
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
5954

@@ -77,7 +72,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
7772
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
7873
let s = s.as_str();
7974
if s.parse::<f64>().is_ok() {
80-
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
75+
for &(constant, name, min_digits) in &KNOWN_CONSTS {
8176
if is_approx_const(constant, &s, min_digits) {
8277
span_lint(
8378
cx,

clippy_lints/src/assertions_on_constants.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc::{declare_lint_pass, declare_tool_lint};
55
use syntax_pos::Span;
66

77
use crate::consts::{constant, Constant};
8-
use crate::utils::sym;
98
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
109

1110
declare_clippy_lint! {
@@ -41,9 +40,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4140
!in_macro_or_desugar(span)
4241
};
4342
if_chain! {
44-
if let Some(assert_span) = is_direct_expn_of(e.span, *sym::assert);
43+
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
4544
if !in_macro_or_desugar(assert_span)
46-
|| is_direct_expn_of(assert_span, *sym::debug_assert)
45+
|| is_direct_expn_of(assert_span, "debug_assert")
4746
.map_or(false, debug_assert_not_in_macro_or_desugar);
4847
if let ExprKind::Unary(_, ref lit) = e.node;
4948
if let Some(bool_const) = constant(cx, cx.tables, lit);

clippy_lints/src/assign_ops.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::utils::{
99
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
1010
};
1111
use crate::utils::{higher, sugg};
12-
use syntax::symbol::Symbol;
1312

1413
declare_clippy_lint! {
1514
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
@@ -89,11 +88,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8988
$($trait_name:ident),+) => {
9089
match $op {
9190
$(hir::BinOpKind::$trait_name => {
92-
let [krate, module] = *crate::utils::paths::OPS_MODULE;
93-
let ident = {
94-
*crate::utils::sym::assign::$trait_name
95-
};
96-
let path: [Symbol; 3] = [krate, module, ident];
91+
let [krate, module] = crate::utils::paths::OPS_MODULE;
92+
let path: [&str; 3] = [krate, module, concat!(stringify!($trait_name), "Assign")];
9793
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
9894
trait_id
9995
} else {

clippy_lints/src/attrs.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! checks for attributes
22
33
use crate::reexport::*;
4-
use crate::utils::sym;
54
use crate::utils::{
65
in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
76
span_lint_and_sugg, span_lint_and_then, without_block_comments,
@@ -18,7 +17,7 @@ use rustc_errors::Applicability;
1817
use semver::Version;
1918
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
2019
use syntax::source_map::Span;
21-
use syntax::symbol::Symbol;
20+
use syntax_pos::symbol::Symbol;
2221

2322
declare_clippy_lint! {
2423
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
@@ -207,14 +206,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
207206
},
208207
_ => {},
209208
}
210-
if items.is_empty() || !attr.check_name(*sym::deprecated) {
209+
if items.is_empty() || !attr.check_name(sym!(deprecated)) {
211210
return;
212211
}
213212
for item in items {
214213
if_chain! {
215214
if let NestedMetaItem::MetaItem(mi) = &item;
216215
if let MetaItemKind::NameValue(lit) = &mi.node;
217-
if mi.check_name(*sym::since);
216+
if mi.check_name(sym!(since));
218217
then {
219218
check_semver(cx, item.span(), lit);
220219
}
@@ -230,7 +229,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
230229
}
231230
match item.node {
232231
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
233-
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(*sym::macro_use));
232+
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(sym!(macro_use)));
234233

235234
for attr in &item.attrs {
236235
if in_external_macro(cx.sess(), attr.span) {
@@ -245,17 +244,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
245244
for lint in lint_list {
246245
match item.node {
247246
ItemKind::Use(..) => {
248-
if is_word(lint, *sym::unused_imports)
249-
|| is_word(lint, *sym::deprecated)
247+
if is_word(lint, sym!(unused_imports))
248+
|| is_word(lint, sym!(deprecated))
250249
{
251250
return;
252251
}
253252
},
254253
ItemKind::ExternCrate(..) => {
255-
if is_word(lint, *sym::unused_imports) && skip_unused_imports {
254+
if is_word(lint, sym!(unused_imports)) && skip_unused_imports {
256255
return;
257256
}
258-
if is_word(lint, *sym::unused_extern_crates) {
257+
if is_word(lint, sym!(unused_extern_crates)) {
259258
return;
260259
}
261260
},
@@ -399,7 +398,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
399398
ExprKind::Call(path_expr, _) => {
400399
if let ExprKind::Path(qpath) = &path_expr.node {
401400
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
402-
!match_def_path(cx, fun_id, &*paths::BEGIN_PANIC)
401+
!match_def_path(cx, fun_id, &paths::BEGIN_PANIC)
403402
} else {
404403
true
405404
}
@@ -445,10 +444,10 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
445444
}
446445

447446
if let Some(values) = attr.meta_item_list() {
448-
if values.len() != 1 || !attr.check_name(*sym::inline) {
447+
if values.len() != 1 || !attr.check_name(sym!(inline)) {
449448
continue;
450449
}
451-
if is_word(&values[0], *sym::always) {
450+
if is_word(&values[0], sym!(always)) {
452451
span_lint(
453452
cx,
454453
INLINE_ALWAYS,
@@ -491,16 +490,16 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
491490
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
492491
if_chain! {
493492
// check cfg_attr
494-
if attr.check_name(*sym::cfg_attr);
493+
if attr.check_name(sym!(cfg_attr));
495494
if let Some(items) = attr.meta_item_list();
496495
if items.len() == 2;
497496
// check for `rustfmt`
498497
if let Some(feature_item) = items[0].meta_item();
499-
if feature_item.check_name(*sym::rustfmt);
498+
if feature_item.check_name(sym!(rustfmt));
500499
// check for `rustfmt_skip` and `rustfmt::skip`
501500
if let Some(skip_item) = &items[1].meta_item();
502-
if skip_item.check_name(*sym::rustfmt_skip) ||
503-
skip_item.path.segments.last().expect("empty path in attribute").ident.name == *sym::skip;
501+
if skip_item.check_name(sym!(rustfmt_skip)) ||
502+
skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip);
504503
// Only lint outer attributes, because custom inner attributes are unstable
505504
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
506505
if let AttrStyle::Outer = attr.style;

clippy_lints/src/booleans.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use crate::utils::sym;
21
use crate::utils::{
32
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
43
span_lint_and_then, SpanlessEq,
54
};
6-
use lazy_static::lazy_static;
75
use rustc::hir::intravisit::*;
86
use rustc::hir::*;
97
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -12,7 +10,6 @@ use rustc_data_structures::thin_vec::ThinVec;
1210
use rustc_errors::Applicability;
1311
use syntax::ast::LitKind;
1412
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
15-
use syntax::symbol::Symbol;
1613

1714
declare_clippy_lint! {
1815
/// **What it does:** Checks for boolean expressions that can be written more
@@ -52,13 +49,8 @@ declare_clippy_lint! {
5249
"boolean expressions that contain terminals which can be eliminated"
5350
}
5451

55-
lazy_static! {
5652
// For each pairs, both orders are considered.
57-
static ref METHODS_WITH_NEGATION: [(Symbol, Symbol); 2] = [
58-
(*sym::is_some, *sym::is_none),
59-
(*sym::is_err, *sym::is_ok),
60-
];
61-
}
53+
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];
6254

6355
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
6456

@@ -195,16 +187,16 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
195187
},
196188
ExprKind::MethodCall(path, _, args) if args.len() == 1 => {
197189
let type_of_receiver = self.cx.tables.expr_ty(&args[0]);
198-
if !match_type(self.cx, type_of_receiver, &*paths::OPTION)
199-
&& !match_type(self.cx, type_of_receiver, &*paths::RESULT)
190+
if !match_type(self.cx, type_of_receiver, &paths::OPTION)
191+
&& !match_type(self.cx, type_of_receiver, &paths::RESULT)
200192
{
201193
return None;
202194
}
203195
METHODS_WITH_NEGATION
204196
.iter()
205197
.cloned()
206198
.flat_map(|(a, b)| vec![(a, b), (b, a)])
207-
.find(|&(a, _)| a == path.ident.name)
199+
.find(|&(a, _)| a == path.ident.name.as_str())
208200
.and_then(|(_, neg_method)| Some(format!("{}.{}()", self.snip(&args[0])?, neg_method)))
209201
},
210202
_ => None,
@@ -474,5 +466,5 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
474466

475467
fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool {
476468
let ty = cx.tables.expr_ty(expr);
477-
get_trait_def_id(cx, &*paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
469+
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
478470
}

clippy_lints/src/bytecount.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::utils::sym;
21
use crate::utils::{
32
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
43
span_lint_and_sugg, walk_ptrs_ty,
@@ -38,10 +37,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
3837
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
3938
if_chain! {
4039
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
41-
if count.ident.name == *sym::count;
40+
if count.ident.name == sym!(count);
4241
if count_args.len() == 1;
4342
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].node;
44-
if filter.ident.name == *sym::filter;
43+
if filter.ident.name == sym!(filter);
4544
if filter_args.len() == 2;
4645
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].node;
4746
then {
@@ -53,7 +52,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
5352
if op.node == BinOpKind::Eq;
5453
if match_type(cx,
5554
walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
56-
&*paths::SLICE_ITER);
55+
&paths::SLICE_ITER);
5756
then {
5857
let needle = match get_path_name(l) {
5958
Some(name) if check_arg(name, argname, r) => r,
@@ -68,7 +67,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
6867
let haystack = if let ExprKind::MethodCall(ref path, _, ref args) =
6968
filter_args[0].node {
7069
let p = path.ident.name;
71-
if (p == *sym::iter || p == *sym::iter_mut) && args.len() == 1 {
70+
if (p == sym!(iter) || p == sym!(iter_mut)) && args.len() == 1 {
7271
&args[0]
7372
} else {
7473
&filter_args[0]

clippy_lints/src/cognitive_complexity.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc::{declare_tool_lint, impl_lint_pass};
99
use syntax::ast::Attribute;
1010
use syntax::source_map::Span;
1111

12-
use crate::utils::sym;
1312
use crate::utils::{in_macro_or_desugar, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
1413

1514
declare_clippy_lint! {
@@ -72,7 +71,7 @@ impl CognitiveComplexity {
7271
..
7372
} = helper;
7473
let ret_ty = cx.tables.node_type(expr.hir_id);
75-
let ret_adjust = if match_type(cx, ret_ty, &*paths::RESULT) {
74+
let ret_adjust = if match_type(cx, ret_ty, &paths::RESULT) {
7675
returns
7776
} else {
7877
returns / 2
@@ -119,7 +118,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
119118
hir_id: HirId,
120119
) {
121120
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
122-
if !cx.tcx.has_attr(def_id, *sym::test) {
121+
if !cx.tcx.has_attr(def_id, sym!(test)) {
123122
self.check(cx, body, span);
124123
}
125124
}

clippy_lints/src/copy_iterator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
3636
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
3737
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));
3838

39-
if is_copy(cx, ty) && match_path(&trait_ref.path, &*paths::ITERATOR) {
39+
if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
4040
span_note_and_lint(
4141
cx,
4242
COPY_ITERATOR,

clippy_lints/src/dbg_macro.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::utils::sym;
21
use crate::utils::{snippet_opt, span_help_and_lint, span_lint_and_sugg};
32
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
43
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -32,7 +31,7 @@ declare_lint_pass!(DbgMacro => [DBG_MACRO]);
3231

3332
impl EarlyLintPass for DbgMacro {
3433
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
35-
if mac.node.path == *sym::dbg {
34+
if mac.node.path == sym!(dbg) {
3635
if let Some(sugg) = tts_span(mac.node.tts.clone()).and_then(|span| snippet_opt(cx, span)) {
3736
span_lint_and_sugg(
3837
cx,

clippy_lints/src/default_trait_access.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DefaultTraitAccess {
3737
if !any_parent_is_automatically_derived(cx.tcx, expr.hir_id);
3838
if let ExprKind::Path(ref qpath) = path.node;
3939
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
40-
if match_def_path(cx, def_id, &*paths::DEFAULT_TRAIT_METHOD);
40+
if match_def_path(cx, def_id, &paths::DEFAULT_TRAIT_METHOD);
4141
then {
4242
match qpath {
4343
QPath::Resolved(..) => {

clippy_lints/src/derive.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn check_hash_peq<'a, 'tcx>(
8888
hash_is_automatically_derived: bool,
8989
) {
9090
if_chain! {
91-
if match_path(&trait_ref.path, &*paths::HASH);
91+
if match_path(&trait_ref.path, &paths::HASH);
9292
if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait();
9393
then {
9494
// Look for the PartialEq implementations for `ty`
@@ -129,7 +129,7 @@ fn check_hash_peq<'a, 'tcx>(
129129

130130
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
131131
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: Ty<'tcx>) {
132-
if match_path(&trait_ref.path, &*paths::CLONE_TRAIT) {
132+
if match_path(&trait_ref.path, &paths::CLONE_TRAIT) {
133133
if !is_copy(cx, ty) {
134134
return;
135135
}

0 commit comments

Comments
 (0)