Skip to content

Commit ad3269c

Browse files
committed
Auto merge of #4093 - rust-lang:rustup, r=oli-obk
Rustup to rustc 1.36.0-nightly (1764b29 2019-05-12)
2 parents c79838e + dfbc74b commit ad3269c

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

+1261
-725
lines changed

clippy_lints/src/approx_const.rs

+27-22
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
use crate::utils::span_lint;
2+
use crate::utils::sym;
3+
use lazy_static::lazy_static;
24
use rustc::hir::*;
35
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
46
use rustc::{declare_lint_pass, declare_tool_lint};
57
use std::f64::consts as f64;
6-
use syntax::ast::{FloatTy, Lit, LitKind};
8+
use syntax::ast::{FloatTy, LitKind};
79
use syntax::symbol;
10+
use syntax::symbol::Symbol;
811

912
declare_clippy_lint! {
1013
/// **What it does:** Checks for floating point literals that approximate
@@ -30,38 +33,40 @@ declare_clippy_lint! {
3033
"the approximate of a known float constant (in `std::fXX::consts`)"
3134
}
3235

36+
lazy_static! {
3337
// Tuples are of the form (constant, name, min_digits)
34-
const KNOWN_CONSTS: &[(f64, &str, usize)] = &[
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),
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),
5155
];
56+
}
5257

5358
declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);
5459

5560
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
5661
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
5762
if let ExprKind::Lit(lit) = &e.node {
58-
check_lit(cx, lit, e);
63+
check_lit(cx, &lit.node, e);
5964
}
6065
}
6166
}
6267

63-
fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
64-
match lit.node {
68+
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
69+
match *lit {
6570
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
6671
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
6772
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
@@ -72,7 +77,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
7277
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
7378
let s = s.as_str();
7479
if s.parse::<f64>().is_ok() {
75-
for &(constant, name, min_digits) in KNOWN_CONSTS {
80+
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
7681
if is_approx_const(constant, &s, min_digits) {
7782
span_lint(
7883
cx,

clippy_lints/src/assertions_on_constants.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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;
89
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};
910

1011
declare_clippy_lint! {
@@ -40,9 +41,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
4041
!in_macro_or_desugar(span)
4142
};
4243
if_chain! {
43-
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
44+
if let Some(assert_span) = is_direct_expn_of(e.span, *sym::assert);
4445
if !in_macro_or_desugar(assert_span)
45-
|| is_direct_expn_of(assert_span, "debug_assert")
46+
|| is_direct_expn_of(assert_span, *sym::debug_assert)
4647
.map_or(false, debug_assert_not_in_macro_or_desugar);
4748
if let ExprKind::Unary(_, ref lit) = e.node;
4849
if let Some(bool_const) = constant(cx, cx.tables, lit);

clippy_lints/src/assign_ops.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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;
1213

1314
declare_clippy_lint! {
1415
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
@@ -88,8 +89,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
8889
$($trait_name:ident),+) => {
8990
match $op {
9091
$(hir::BinOpKind::$trait_name => {
91-
let [krate, module] = crate::utils::paths::OPS_MODULE;
92-
let path = [krate, module, concat!(stringify!($trait_name), "Assign")];
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];
9397
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
9498
trait_id
9599
} else {

clippy_lints/src/attrs.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! checks for attributes
22
33
use crate::reexport::*;
4+
use crate::utils::sym;
45
use crate::utils::{
5-
in_macro_or_desugar, is_present_in_source, last_line_of_span, paths, snippet_opt, span_lint, span_lint_and_sugg,
6-
span_lint_and_then, without_block_comments,
6+
in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
7+
span_lint_and_sugg, span_lint_and_then, without_block_comments,
78
};
89
use if_chain::if_chain;
910
use rustc::hir::*;
@@ -17,6 +18,7 @@ use rustc_errors::Applicability;
1718
use semver::Version;
1819
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
1920
use syntax::source_map::Span;
21+
use syntax::symbol::Symbol;
2022

2123
declare_clippy_lint! {
2224
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
@@ -205,14 +207,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
205207
},
206208
_ => {},
207209
}
208-
if items.is_empty() || !attr.check_name("deprecated") {
210+
if items.is_empty() || !attr.check_name(*sym::deprecated) {
209211
return;
210212
}
211213
for item in items {
212214
if_chain! {
213215
if let NestedMetaItem::MetaItem(mi) = &item;
214216
if let MetaItemKind::NameValue(lit) = &mi.node;
215-
if mi.check_name("since");
217+
if mi.check_name(*sym::since);
216218
then {
217219
check_semver(cx, item.span(), lit);
218220
}
@@ -228,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
228230
}
229231
match item.node {
230232
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
231-
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name("macro_use"));
233+
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(*sym::macro_use));
232234

233235
for attr in &item.attrs {
234236
if in_external_macro(cx.sess(), attr.span) {
@@ -243,15 +245,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
243245
for lint in lint_list {
244246
match item.node {
245247
ItemKind::Use(..) => {
246-
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
248+
if is_word(lint, *sym::unused_imports)
249+
|| is_word(lint, *sym::deprecated)
250+
{
247251
return;
248252
}
249253
},
250254
ItemKind::ExternCrate(..) => {
251-
if is_word(lint, "unused_imports") && skip_unused_imports {
255+
if is_word(lint, *sym::unused_imports) && skip_unused_imports {
252256
return;
253257
}
254-
if is_word(lint, "unused_extern_crates") {
258+
if is_word(lint, *sym::unused_extern_crates) {
255259
return;
256260
}
257261
},
@@ -395,7 +399,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
395399
ExprKind::Call(path_expr, _) => {
396400
if let ExprKind::Path(qpath) = &path_expr.node {
397401
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
398-
!cx.match_def_path(fun_id, &paths::BEGIN_PANIC)
402+
!match_def_path(cx, fun_id, &*paths::BEGIN_PANIC)
399403
} else {
400404
true
401405
}
@@ -441,10 +445,10 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
441445
}
442446

443447
if let Some(values) = attr.meta_item_list() {
444-
if values.len() != 1 || !attr.check_name("inline") {
448+
if values.len() != 1 || !attr.check_name(*sym::inline) {
445449
continue;
446450
}
447-
if is_word(&values[0], "always") {
451+
if is_word(&values[0], *sym::always) {
448452
span_lint(
449453
cx,
450454
INLINE_ALWAYS,
@@ -473,7 +477,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
473477
);
474478
}
475479

476-
fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
480+
fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
477481
if let NestedMetaItem::MetaItem(mi) = &nmi {
478482
mi.is_word() && mi.check_name(expected)
479483
} else {
@@ -487,16 +491,16 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
487491
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
488492
if_chain! {
489493
// check cfg_attr
490-
if attr.check_name("cfg_attr");
494+
if attr.check_name(*sym::cfg_attr);
491495
if let Some(items) = attr.meta_item_list();
492496
if items.len() == 2;
493497
// check for `rustfmt`
494498
if let Some(feature_item) = items[0].meta_item();
495-
if feature_item.check_name("rustfmt");
499+
if feature_item.check_name(*sym::rustfmt);
496500
// check for `rustfmt_skip` and `rustfmt::skip`
497501
if let Some(skip_item) = &items[1].meta_item();
498-
if skip_item.check_name("rustfmt_skip") ||
499-
skip_item.path.segments.last().expect("empty path in attribute").ident.name == "skip";
502+
if skip_item.check_name(*sym::rustfmt_skip) ||
503+
skip_item.path.segments.last().expect("empty path in attribute").ident.name == *sym::skip;
500504
// Only lint outer attributes, because custom inner attributes are unstable
501505
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
502506
if let AttrStyle::Outer = attr.style;

clippy_lints/src/booleans.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
use crate::utils::sym;
12
use crate::utils::{
23
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
34
span_lint_and_then, SpanlessEq,
45
};
6+
use lazy_static::lazy_static;
57
use rustc::hir::intravisit::*;
68
use rustc::hir::*;
79
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -10,6 +12,7 @@ use rustc_data_structures::thin_vec::ThinVec;
1012
use rustc_errors::Applicability;
1113
use syntax::ast::LitKind;
1214
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
15+
use syntax::symbol::Symbol;
1316

1417
declare_clippy_lint! {
1518
/// **What it does:** Checks for boolean expressions that can be written more
@@ -49,8 +52,13 @@ declare_clippy_lint! {
4952
"boolean expressions that contain terminals which can be eliminated"
5053
}
5154

55+
lazy_static! {
5256
// For each pairs, both orders are considered.
53-
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];
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+
}
5462

5563
declare_lint_pass!(NonminimalBool => [NONMINIMAL_BOOL, LOGIC_BUG]);
5664

@@ -187,16 +195,16 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
187195
},
188196
ExprKind::MethodCall(path, _, args) if args.len() == 1 => {
189197
let type_of_receiver = self.cx.tables.expr_ty(&args[0]);
190-
if !match_type(self.cx, type_of_receiver, &paths::OPTION)
191-
&& !match_type(self.cx, type_of_receiver, &paths::RESULT)
198+
if !match_type(self.cx, type_of_receiver, &*paths::OPTION)
199+
&& !match_type(self.cx, type_of_receiver, &*paths::RESULT)
192200
{
193201
return None;
194202
}
195203
METHODS_WITH_NEGATION
196204
.iter()
197205
.cloned()
198206
.flat_map(|(a, b)| vec![(a, b), (b, a)])
199-
.find(|&(a, _)| a == path.ident.as_str())
207+
.find(|&(a, _)| a == path.ident.name)
200208
.and_then(|(_, neg_method)| Some(format!("{}.{}()", self.snip(&args[0])?, neg_method)))
201209
},
202210
_ => None,
@@ -466,5 +474,5 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {
466474

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

clippy_lints/src/bytecount.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::utils::sym;
12
use crate::utils::{
23
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
34
span_lint_and_sugg, walk_ptrs_ty,
@@ -37,10 +38,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
3738
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
3839
if_chain! {
3940
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
40-
if count.ident.name == "count";
41+
if count.ident.name == *sym::count;
4142
if count_args.len() == 1;
4243
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].node;
43-
if filter.ident.name == "filter";
44+
if filter.ident.name == *sym::filter;
4445
if filter_args.len() == 2;
4546
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].node;
4647
then {
@@ -52,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
5253
if op.node == BinOpKind::Eq;
5354
if match_type(cx,
5455
walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
55-
&paths::SLICE_ITER);
56+
&*paths::SLICE_ITER);
5657
then {
5758
let needle = match get_path_name(l) {
5859
Some(name) if check_arg(name, argname, r) => r,
@@ -67,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
6768
let haystack = if let ExprKind::MethodCall(ref path, _, ref args) =
6869
filter_args[0].node {
6970
let p = path.ident.name;
70-
if (p == "iter" || p == "iter_mut") && args.len() == 1 {
71+
if (p == *sym::iter || p == *sym::iter_mut) && args.len() == 1 {
7172
&args[0]
7273
} else {
7374
&filter_args[0]

clippy_lints/src/cognitive_complexity.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ 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;
1213
use crate::utils::{in_macro_or_desugar, is_allowed, match_type, paths, span_help_and_lint, LimitStack};
1314

1415
declare_clippy_lint! {
@@ -71,7 +72,7 @@ impl CognitiveComplexity {
7172
..
7273
} = helper;
7374
let ret_ty = cx.tables.node_type(expr.hir_id);
74-
let ret_adjust = if match_type(cx, ret_ty, &paths::RESULT) {
75+
let ret_adjust = if match_type(cx, ret_ty, &*paths::RESULT) {
7576
returns
7677
} else {
7778
returns / 2
@@ -118,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
118119
hir_id: HirId,
119120
) {
120121
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
121-
if !cx.tcx.has_attr(def_id, "test") {
122+
if !cx.tcx.has_attr(def_id, *sym::test) {
122123
self.check(cx, body, span);
123124
}
124125
}

clippy_lints/src/const_static_lifetime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl StaticConst {
4747
if let Some(lifetime) = *optional_lifetime {
4848
match borrow_type.ty.node {
4949
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => {
50-
if lifetime.ident.name == "'static" {
50+
if lifetime.ident.name == syntax::symbol::keywords::StaticLifetime.name() {
5151
let snip = snippet(cx, borrow_type.ty.span, "<type>");
5252
let sugg = format!("&{}", snip);
5353
span_lint_and_then(

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,

0 commit comments

Comments
 (0)