Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup to rustc 1.36.0-nightly (1764b2972 2019-05-12) #4093

Merged
merged 5 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions clippy_lints/src/approx_const.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::utils::span_lint;
use crate::utils::sym;
use lazy_static::lazy_static;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::{declare_lint_pass, declare_tool_lint};
use std::f64::consts as f64;
use syntax::ast::{FloatTy, Lit, LitKind};
use syntax::ast::{FloatTy, LitKind};
use syntax::symbol;
use syntax::symbol::Symbol;

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

lazy_static! {
// Tuples are of the form (constant, name, min_digits)
const KNOWN_CONSTS: &[(f64, &str, usize)] = &[
(f64::E, "E", 4),
(f64::FRAC_1_PI, "FRAC_1_PI", 4),
(f64::FRAC_1_SQRT_2, "FRAC_1_SQRT_2", 5),
(f64::FRAC_2_PI, "FRAC_2_PI", 5),
(f64::FRAC_2_SQRT_PI, "FRAC_2_SQRT_PI", 5),
(f64::FRAC_PI_2, "FRAC_PI_2", 5),
(f64::FRAC_PI_3, "FRAC_PI_3", 5),
(f64::FRAC_PI_4, "FRAC_PI_4", 5),
(f64::FRAC_PI_6, "FRAC_PI_6", 5),
(f64::FRAC_PI_8, "FRAC_PI_8", 5),
(f64::LN_10, "LN_10", 5),
(f64::LN_2, "LN_2", 5),
(f64::LOG10_E, "LOG10_E", 5),
(f64::LOG2_E, "LOG2_E", 5),
(f64::PI, "PI", 3),
(f64::SQRT_2, "SQRT_2", 5),
static ref KNOWN_CONSTS: [(f64, Symbol, usize); 16] = [
(f64::E, *sym::E, 4),
(f64::FRAC_1_PI, *sym::FRAC_1_PI, 4),
(f64::FRAC_1_SQRT_2, *sym::FRAC_1_SQRT_2, 5),
(f64::FRAC_2_PI, *sym::FRAC_2_PI, 5),
(f64::FRAC_2_SQRT_PI, *sym::FRAC_2_SQRT_PI, 5),
(f64::FRAC_PI_2, *sym::FRAC_PI_2, 5),
(f64::FRAC_PI_3, *sym::FRAC_PI_3, 5),
(f64::FRAC_PI_4, *sym::FRAC_PI_4, 5),
(f64::FRAC_PI_6, *sym::FRAC_PI_6, 5),
(f64::FRAC_PI_8, *sym::FRAC_PI_8, 5),
(f64::LN_10, *sym::LN_10, 5),
(f64::LN_2, *sym::LN_2, 5),
(f64::LOG10_E, *sym::LOG10_E, 5),
(f64::LOG2_E, *sym::LOG2_E, 5),
(f64::PI, *sym::PI, 3),
(f64::SQRT_2, *sym::SQRT_2, 5),
];
}

declare_lint_pass!(ApproxConstant => [APPROX_CONSTANT]);

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ApproxConstant {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Lit(lit) = &e.node {
check_lit(cx, lit, e);
check_lit(cx, &lit.node, e);
}
}
}

fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
match lit.node {
fn check_lit(cx: &LateContext<'_, '_>, lit: &LitKind, e: &Expr) {
match *lit {
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
Expand All @@ -72,7 +77,7 @@ fn check_lit(cx: &LateContext<'_, '_>, lit: &Lit, e: &Expr) {
fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, module: &str) {
let s = s.as_str();
if s.parse::<f64>().is_ok() {
for &(constant, name, min_digits) in KNOWN_CONSTS {
for &(constant, name, min_digits) in KNOWN_CONSTS.iter() {
if is_approx_const(constant, &s, min_digits) {
span_lint(
cx,
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/assertions_on_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
use syntax_pos::Span;

use crate::consts::{constant, Constant};
use crate::utils::sym;
use crate::utils::{in_macro_or_desugar, is_direct_expn_of, span_help_and_lint};

declare_clippy_lint! {
Expand Down Expand Up @@ -40,9 +41,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssertionsOnConstants {
!in_macro_or_desugar(span)
};
if_chain! {
if let Some(assert_span) = is_direct_expn_of(e.span, "assert");
if let Some(assert_span) = is_direct_expn_of(e.span, *sym::assert);
if !in_macro_or_desugar(assert_span)
|| is_direct_expn_of(assert_span, "debug_assert")
|| is_direct_expn_of(assert_span, *sym::debug_assert)
.map_or(false, debug_assert_not_in_macro_or_desugar);
if let ExprKind::Unary(_, ref lit) = e.node;
if let Some(bool_const) = constant(cx, cx.tables, lit);
Expand Down
8 changes: 6 additions & 2 deletions clippy_lints/src/assign_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::utils::{
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
};
use crate::utils::{higher, sugg};
use syntax::symbol::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
Expand Down Expand Up @@ -88,8 +89,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AssignOps {
$($trait_name:ident),+) => {
match $op {
$(hir::BinOpKind::$trait_name => {
let [krate, module] = crate::utils::paths::OPS_MODULE;
let path = [krate, module, concat!(stringify!($trait_name), "Assign")];
let [krate, module] = *crate::utils::paths::OPS_MODULE;
let ident = {
*crate::utils::sym::assign::$trait_name
};
let path: [Symbol; 3] = [krate, module, ident];
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
trait_id
} else {
Expand Down
36 changes: 20 additions & 16 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! checks for attributes

use crate::reexport::*;
use crate::utils::sym;
use crate::utils::{
in_macro_or_desugar, is_present_in_source, last_line_of_span, paths, snippet_opt, span_lint, span_lint_and_sugg,
span_lint_and_then, without_block_comments,
in_macro_or_desugar, is_present_in_source, last_line_of_span, match_def_path, paths, snippet_opt, span_lint,
span_lint_and_sugg, span_lint_and_then, without_block_comments,
};
use if_chain::if_chain;
use rustc::hir::*;
Expand All @@ -17,6 +18,7 @@ use rustc_errors::Applicability;
use semver::Version;
use syntax::ast::{AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
use syntax::source_map::Span;
use syntax::symbol::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for items annotated with `#[inline(always)]`,
Expand Down Expand Up @@ -205,14 +207,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
},
_ => {},
}
if items.is_empty() || !attr.check_name("deprecated") {
if items.is_empty() || !attr.check_name(*sym::deprecated) {
return;
}
for item in items {
if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.node;
if mi.check_name("since");
if mi.check_name(*sym::since);
then {
check_semver(cx, item.span(), lit);
}
Expand All @@ -228,7 +230,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
}
match item.node {
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name("macro_use"));
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(*sym::macro_use));

for attr in &item.attrs {
if in_external_macro(cx.sess(), attr.span) {
Expand All @@ -243,15 +245,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Attributes {
for lint in lint_list {
match item.node {
ItemKind::Use(..) => {
if is_word(lint, "unused_imports") || is_word(lint, "deprecated") {
if is_word(lint, *sym::unused_imports)
|| is_word(lint, *sym::deprecated)
{
return;
}
},
ItemKind::ExternCrate(..) => {
if is_word(lint, "unused_imports") && skip_unused_imports {
if is_word(lint, *sym::unused_imports) && skip_unused_imports {
return;
}
if is_word(lint, "unused_extern_crates") {
if is_word(lint, *sym::unused_extern_crates) {
return;
}
},
Expand Down Expand Up @@ -395,7 +399,7 @@ fn is_relevant_expr(cx: &LateContext<'_, '_>, tables: &ty::TypeckTables<'_>, exp
ExprKind::Call(path_expr, _) => {
if let ExprKind::Path(qpath) = &path_expr.node {
if let Some(fun_id) = tables.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
!cx.match_def_path(fun_id, &paths::BEGIN_PANIC)
!match_def_path(cx, fun_id, &*paths::BEGIN_PANIC)
} else {
true
}
Expand Down Expand Up @@ -441,10 +445,10 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
}

if let Some(values) = attr.meta_item_list() {
if values.len() != 1 || !attr.check_name("inline") {
if values.len() != 1 || !attr.check_name(*sym::inline) {
continue;
}
if is_word(&values[0], "always") {
if is_word(&values[0], *sym::always) {
span_lint(
cx,
INLINE_ALWAYS,
Expand Down Expand Up @@ -473,7 +477,7 @@ fn check_semver(cx: &LateContext<'_, '_>, span: Span, lit: &Lit) {
);
}

fn is_word(nmi: &NestedMetaItem, expected: &str) -> bool {
fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
if let NestedMetaItem::MetaItem(mi) = &nmi {
mi.is_word() && mi.check_name(expected)
} else {
Expand All @@ -487,16 +491,16 @@ impl EarlyLintPass for DeprecatedCfgAttribute {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! {
// check cfg_attr
if attr.check_name("cfg_attr");
if attr.check_name(*sym::cfg_attr);
if let Some(items) = attr.meta_item_list();
if items.len() == 2;
// check for `rustfmt`
if let Some(feature_item) = items[0].meta_item();
if feature_item.check_name("rustfmt");
if feature_item.check_name(*sym::rustfmt);
// check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item();
if skip_item.check_name("rustfmt_skip") ||
skip_item.path.segments.last().expect("empty path in attribute").ident.name == "skip";
if skip_item.check_name(*sym::rustfmt_skip) ||
skip_item.path.segments.last().expect("empty path in attribute").ident.name == *sym::skip;
// Only lint outer attributes, because custom inner attributes are unstable
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
if let AttrStyle::Outer = attr.style;
Expand Down
18 changes: 13 additions & 5 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::utils::sym;
use crate::utils::{
get_trait_def_id, implements_trait, in_macro, in_macro_or_desugar, match_type, paths, snippet_opt,
span_lint_and_then, SpanlessEq,
};
use lazy_static::lazy_static;
use rustc::hir::intravisit::*;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
Expand All @@ -10,6 +12,7 @@ use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::Applicability;
use syntax::ast::LitKind;
use syntax::source_map::{dummy_spanned, Span, DUMMY_SP};
use syntax::symbol::Symbol;

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

lazy_static! {
// For each pairs, both orders are considered.
const METHODS_WITH_NEGATION: [(&str, &str); 2] = [("is_some", "is_none"), ("is_err", "is_ok")];
static ref METHODS_WITH_NEGATION: [(Symbol, Symbol); 2] = [
(*sym::is_some, *sym::is_none),
(*sym::is_err, *sym::is_ok),
];
}

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

Expand Down Expand Up @@ -187,16 +195,16 @@ impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> {
},
ExprKind::MethodCall(path, _, args) if args.len() == 1 => {
let type_of_receiver = self.cx.tables.expr_ty(&args[0]);
if !match_type(self.cx, type_of_receiver, &paths::OPTION)
&& !match_type(self.cx, type_of_receiver, &paths::RESULT)
if !match_type(self.cx, type_of_receiver, &*paths::OPTION)
&& !match_type(self.cx, type_of_receiver, &*paths::RESULT)
{
return None;
}
METHODS_WITH_NEGATION
.iter()
.cloned()
.flat_map(|(a, b)| vec![(a, b), (b, a)])
.find(|&(a, _)| a == path.ident.as_str())
.find(|&(a, _)| a == path.ident.name)
.and_then(|(_, neg_method)| Some(format!("{}.{}()", self.snip(&args[0])?, neg_method)))
},
_ => None,
Expand Down Expand Up @@ -466,5 +474,5 @@ impl<'a, 'tcx> Visitor<'tcx> for NonminimalBoolVisitor<'a, 'tcx> {

fn implements_ord<'a, 'tcx>(cx: &'a LateContext<'a, 'tcx>, expr: &Expr) -> bool {
let ty = cx.tables.expr_ty(expr);
get_trait_def_id(cx, &paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
get_trait_def_id(cx, &*paths::ORD).map_or(false, |id| implements_trait(cx, ty, id, &[]))
}
9 changes: 5 additions & 4 deletions clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils::sym;
use crate::utils::{
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability,
span_lint_and_sugg, walk_ptrs_ty,
Expand Down Expand Up @@ -37,10 +38,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
fn check_expr(&mut self, cx: &LateContext<'_, '_>, expr: &Expr) {
if_chain! {
if let ExprKind::MethodCall(ref count, _, ref count_args) = expr.node;
if count.ident.name == "count";
if count.ident.name == *sym::count;
if count_args.len() == 1;
if let ExprKind::MethodCall(ref filter, _, ref filter_args) = count_args[0].node;
if filter.ident.name == "filter";
if filter.ident.name == *sym::filter;
if filter_args.len() == 2;
if let ExprKind::Closure(_, _, body_id, _, _) = filter_args[1].node;
then {
Expand All @@ -52,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
if op.node == BinOpKind::Eq;
if match_type(cx,
walk_ptrs_ty(cx.tables.expr_ty(&filter_args[0])),
&paths::SLICE_ITER);
&*paths::SLICE_ITER);
then {
let needle = match get_path_name(l) {
Some(name) if check_arg(name, argname, r) => r,
Expand All @@ -67,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
let haystack = if let ExprKind::MethodCall(ref path, _, ref args) =
filter_args[0].node {
let p = path.ident.name;
if (p == "iter" || p == "iter_mut") && args.len() == 1 {
if (p == *sym::iter || p == *sym::iter_mut) && args.len() == 1 {
&args[0]
} else {
&filter_args[0]
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc::{declare_tool_lint, impl_lint_pass};
use syntax::ast::Attribute;
use syntax::source_map::Span;

use crate::utils::sym;
use crate::utils::{in_macro_or_desugar, is_allowed, match_type, paths, span_help_and_lint, LimitStack};

declare_clippy_lint! {
Expand Down Expand Up @@ -71,7 +72,7 @@ impl CognitiveComplexity {
..
} = helper;
let ret_ty = cx.tables.node_type(expr.hir_id);
let ret_adjust = if match_type(cx, ret_ty, &paths::RESULT) {
let ret_adjust = if match_type(cx, ret_ty, &*paths::RESULT) {
returns
} else {
returns / 2
Expand Down Expand Up @@ -118,7 +119,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CognitiveComplexity {
hir_id: HirId,
) {
let def_id = cx.tcx.hir().local_def_id_from_hir_id(hir_id);
if !cx.tcx.has_attr(def_id, "test") {
if !cx.tcx.has_attr(def_id, *sym::test) {
self.check(cx, body, span);
}
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/const_static_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl StaticConst {
if let Some(lifetime) = *optional_lifetime {
match borrow_type.ty.node {
TyKind::Path(..) | TyKind::Slice(..) | TyKind::Array(..) | TyKind::Tup(..) => {
if lifetime.ident.name == "'static" {
if lifetime.ident.name == syntax::symbol::keywords::StaticLifetime.name() {
let snip = snippet(cx, borrow_type.ty.span, "<type>");
let sugg = format!("&{}", snip);
span_lint_and_then(
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/copy_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for CopyIterator {
if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, _) = item.node {
let ty = cx.tcx.type_of(cx.tcx.hir().local_def_id_from_hir_id(item.hir_id));

if is_copy(cx, ty) && match_path(&trait_ref.path, &paths::ITERATOR) {
if is_copy(cx, ty) && match_path(&trait_ref.path, &*paths::ITERATOR) {
span_note_and_lint(
cx,
COPY_ITERATOR,
Expand Down
Loading