Skip to content

Commit

Permalink
submodules: update clippy from 9d33731 to 5afdf8b
Browse files Browse the repository at this point in the history
Changes:

````
fix for rustc master
mem_forget: fix syntax error in code sample
explicit_counter_loop fix rust-lang#3308 false positive
new_ret_no_self test remove tool lints cfg flag
Added new_ret_no_self exception to clippy to pass dogfood tests
Removed new_ret_no_self tests from method.rs
new_ret_no_self correctly lint impl return
Removed unused variables
new_ret_no_self fix false positive for impl trait return with associated type self
new_ret_no_self corrected panic and added test stderr
new_ret_no_self added positive test cases
Fix some more `stutter` warnings
unused unit lint
Install Windows SDK 10.0 on travis
cmp_owned refactor
cmp_owned correct error message if rhs is deref
Add a comment reminding to update README if the default changes
Specify which categories are enabled by default
Only run markdown linter on linux
Move Travis Windows build to allowed failures
Add Travis windows build
Fix `doc_markdown` lints
Fix `stutter` lints
Fix `similar_names` warnings
cmp_owned current suggestion for multiple deref
cmp_owned add test for multiple dereference
Corrected single-character string constant used as pattern found in dogfood test
Fixes 3289, cmp_owned wording and false positive
````
  • Loading branch information
matthiaskrgr committed Oct 15, 2018
1 parent 38d2261 commit 7da731a
Show file tree
Hide file tree
Showing 37 changed files with 558 additions and 110 deletions.
20 changes: 16 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ rust: nightly
os:
- linux
- osx
- windows

sudo: false

Expand All @@ -24,10 +25,15 @@ before_install:
install:
- |
if [ -z ${INTEGRATION} ]; then
. $HOME/.nvm/nvm.sh
nvm install stable
nvm use stable
npm install remark-cli remark-lint
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
. $HOME/.nvm/nvm.sh
nvm install stable
nvm use stable
npm install remark-cli remark-lint
fi
if [ "$TRAVIS_OS_NAME" == "windows" ]; then
choco install windows-sdk-10.0
fi
fi
matrix:
Expand All @@ -36,6 +42,8 @@ matrix:
env: BASE_TESTS=true
- os: linux
env: BASE_TESTS=true
- os: windows
env: BASE_TEST=true
- env: INTEGRATION=rust-lang/cargo
- env: INTEGRATION=rust-lang-nursery/rand
- env: INTEGRATION=rust-lang-nursery/stdsimd
Expand All @@ -49,10 +57,14 @@ matrix:
- env: INTEGRATION=serde-rs/serde
- env: INTEGRATION=Geal/nom
- env: INTEGRATION=hyperium/hyper
allow_failures:
- os: windows
env: BASE_TEST=true
# prevent these jobs with default env vars
exclude:
- os: linux
- os: osx
- os: windows

script:
- |
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ All notable changes to this project will be documented in this file.
[`unused_collect`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unused_collect
[`unused_io_amount`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unused_io_amount
[`unused_label`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unused_label
[`unused_unit`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#unused_unit
[`use_debug`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#use_debug
[`use_self`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#use_self
[`used_underscore_binding`]: https://rust-lang-nursery.github.io/rust-clippy/master/index.html#used_underscore_binding
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ We are currently in the process of discussing Clippy 1.0 via the RFC process in

A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.

[There are 279 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)
[There are 280 lints included in this crate!](https://rust-lang-nursery.github.io/rust-clippy/master/index.html)

We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:

Expand All @@ -24,6 +24,15 @@ We have a bunch of lint categories to allow you to choose how much Clippy is sup

More to come, please [file an issue](https://github.com/rust-lang-nursery/rust-clippy/issues) if you have ideas!

Only the following of those categories are enabled by default:

* `clippy::style`
* `clippy::correctness`
* `clippy::complexity`
* `clippy::perf`

Other categories need to be enabled in order for their lints to be executed.

Table of contents:

* [Usage instructions](#usage)
Expand Down
4 changes: 3 additions & 1 deletion ci/base-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ set -ex
echo "Running clippy base tests"

PATH=$PATH:./node_modules/.bin
remark -f *.md > /dev/null
if [ "$TRAVIS_OS_NAME" == "linux" ]; then
remark -f *.md > /dev/null
fi
# build clippy in debug mode and run tests
cargo build --features debugging
cargo test --features debugging
Expand Down
9 changes: 5 additions & 4 deletions clippy_lints/src/double_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ declare_clippy_lint! {
"unnecessary double comparisons that can be simplified"
}

pub struct DoubleComparisonPass;
pub struct Pass;

impl LintPass for DoubleComparisonPass {
impl LintPass for Pass {
fn get_lints(&self) -> LintArray {
lint_array!(DOUBLE_COMPARISONS)
}
}

impl<'a, 'tcx> DoubleComparisonPass {
impl<'a, 'tcx> Pass {
#[allow(clippy::similar_names)]
fn check_binop(
&self,
cx: &LateContext<'a, 'tcx>,
Expand Down Expand Up @@ -87,7 +88,7 @@ impl<'a, 'tcx> DoubleComparisonPass {
}
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DoubleComparisonPass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Binary(ref kind, ref lhs, ref rhs) = expr.node {
self.check_binop(cx, kind.node, lhs, rhs, expr.span);
Expand Down
12 changes: 6 additions & 6 deletions clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
let variant = &var.node;
if let Some(ref anon_const) = variant.disr_expr {
let param_env = ty::ParamEnv::empty();
let did = cx.tcx.hir.body_owner_def_id(anon_const.body);
let substs = Substs::identity_for_item(cx.tcx.global_tcx(), did);
let instance = ty::Instance::new(did, substs);
let cid = GlobalId {
let def_id = cx.tcx.hir.body_owner_def_id(anon_const.body);
let substs = Substs::identity_for_item(cx.tcx.global_tcx(), def_id);
let instance = ty::Instance::new(def_id, substs);
let c_id = GlobalId {
instance,
promoted: None
};
let constant = cx.tcx.const_eval(param_env.and(cid)).ok();
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, c)) {
let mut ty = cx.tcx.type_of(did);
let mut ty = cx.tcx.type_of(def_id);
if let ty::Adt(adt, _) = ty.sty {
if adt.is_enum() {
ty = adt.repr.discr_type().to_ty(cx.tcx);
Expand Down
13 changes: 7 additions & 6 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::syntax::ast::*;
use crate::syntax::source_map::Span;
use crate::syntax::symbol::LocalInternedString;
use crate::utils::{span_help_and_lint, span_lint};
use crate::utils::{camel_case_from, camel_case_until, in_macro};
use crate::utils::{camel_case, in_macro};

/// **What it does:** Detects enumeration variants that are prefixed or suffixed
/// by the same characters.
Expand Down Expand Up @@ -184,19 +184,19 @@ fn check_variant(
}
}
let first = var2str(&def.variants[0]);
let mut pre = &first[..camel_case_until(&*first)];
let mut post = &first[camel_case_from(&*first)..];
let mut pre = &first[..camel_case::until(&*first)];
let mut post = &first[camel_case::from(&*first)..];
for var in &def.variants {
let name = var2str(var);

let pre_match = partial_match(pre, &name);
pre = &pre[..pre_match];
let pre_camel = camel_case_until(pre);
let pre_camel = camel_case::until(pre);
pre = &pre[..pre_camel];
while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() {
if next.is_lowercase() {
let last = pre.len() - last.len_utf8();
let last_camel = camel_case_until(&pre[..last]);
let last_camel = camel_case::until(&pre[..last]);
pre = &pre[..last_camel];
} else {
break;
Expand All @@ -206,7 +206,7 @@ fn check_variant(
let post_match = partial_rmatch(post, &name);
let post_end = post.len() - post_match;
post = &post[post_end..];
let post_camel = camel_case_from(post);
let post_camel = camel_case::from(post);
post = &post[post_camel..];
}
let (what, value) = match (pre.is_empty(), post.is_empty()) {
Expand Down Expand Up @@ -255,6 +255,7 @@ impl EarlyLintPass for EnumVariantNames {
assert!(last.is_some());
}

#[allow(clippy::similar_names)]
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
let item_name = item.ident.as_str();
let item_name_chars = item_name.chars().count();
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/eq_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ impl LintPass for EqOp {
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
#[allow(clippy::similar_names)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprKind::Binary(op, ref left, ref right) = e.node {
if in_macro(e.span) {
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/excessive_precision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl ExcessivePrecision {
}
}

#[allow(clippy::doc_markdown)]
/// Should we exclude the float because it has a `.0` or `.` suffix
/// Ex 1_000_000_000.0
/// Ex 1_000_000_000.
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/if_let_redundant_pattern_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl LintPass for Pass {
}

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
#[allow(clippy::similar_names)]
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprKind::Match(ref op, ref arms, MatchSource::IfLetDesugar { .. }) = expr.node {
if arms[0].pats.len() == 1 {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn has_is_empty(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
let ty = &walk_ptrs_ty(cx.tables.expr_ty(expr));
match ty.sty {
ty::Dynamic(ref tt, ..) => cx.tcx
.associated_items(tt.principal().expect("trait impl not found").def_id())
.associated_items(tt.principal().def_id())
.any(|item| is_is_empty(cx, &item)),
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),
ty::Adt(id, _) => has_is_empty_impl(cx, id.did),
Expand Down
8 changes: 6 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ extern crate syntax_pos;

use toml;

// Currently, categories "style", "correctness", "complexity" and "perf" are enabled by default,
// as said in the README.md of this repository. If this changes, please update README.md.
macro_rules! declare_clippy_lint {
{ pub $name:tt, style, $description:tt } => {
declare_tool_lint! { pub clippy::$name, Warn, $description, report_in_external_macro: true }
Expand Down Expand Up @@ -428,8 +430,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom);
reg.register_late_lint_pass(box replace_consts::ReplaceConsts);
reg.register_late_lint_pass(box types::UnitArg);
reg.register_late_lint_pass(box double_comparison::DoubleComparisonPass);
reg.register_late_lint_pass(box question_mark::QuestionMarkPass);
reg.register_late_lint_pass(box double_comparison::Pass);
reg.register_late_lint_pass(box question_mark::Pass);
reg.register_late_lint_pass(box suspicious_trait_impl::SuspiciousImpl);
reg.register_early_lint_pass(box multiple_crate_versions::Pass);
reg.register_late_lint_pass(box map_unit_fn::Pass);
Expand Down Expand Up @@ -685,6 +687,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
regex::TRIVIAL_REGEX,
returns::LET_AND_RETURN,
returns::NEEDLESS_RETURN,
returns::UNUSED_UNIT,
serde_api::SERDE_API_MISUSE,
strings::STRING_LIT_AS_BYTES,
suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL,
Expand Down Expand Up @@ -801,6 +804,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
regex::TRIVIAL_REGEX,
returns::LET_AND_RETURN,
returns::NEEDLESS_RETURN,
returns::UNUSED_UNIT,
strings::STRING_LIT_AS_BYTES,
types::FN_TO_NUMERIC_CAST,
types::FN_TO_NUMERIC_CAST_WITH_TRUNCATION,
Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,10 +1952,7 @@ impl<'a, 'tcx> Visitor<'tcx> for IncrementVisitor<'a, 'tcx> {
_ => (),
}
}
} else if is_loop(expr) {
walk_expr(self, expr);
return;
} else if is_conditional(expr) {
} else if is_loop(expr) || is_conditional(expr) {
self.depth += 1;
walk_expr(self, expr);
self.depth -= 1;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/map_unit_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn unit_closure<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'a hir::Expr) -> Op
None
}

/// Builds a name for the let binding variable (var_arg)
/// Builds a name for the let binding variable (`var_arg`)
///
/// `x.field` => `x_field`
/// `y` => `_y`
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/mem_forget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::utils::{match_def_path, opt_def_id, paths, span_lint};
///
/// **Example:**
/// ```rust
/// mem::forget(Rc::new(55)))
/// mem::forget(Rc::new(55))
/// ```
declare_clippy_lint! {
pub MEM_FORGET,
Expand Down
41 changes: 31 additions & 10 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use crate::rustc::hir;
use crate::rustc::hir::def::Def;
use crate::rustc::lint::{in_external_macro, LateContext, LateLintPass, Lint, LintArray, LintContext, LintPass};
use crate::rustc::ty::{self, Ty};
use crate::rustc::ty::{self, Ty, TyKind, Predicate};
use crate::rustc::{declare_tool_lint, lint_array};
use crate::rustc_errors::Applicability;
use crate::syntax::ast;
Expand Down Expand Up @@ -878,6 +878,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
let name = implitem.ident.name;
let parent = cx.tcx.hir.get_parent(implitem.id);
let item = cx.tcx.hir.expect_item(parent);
let def_id = cx.tcx.hir.local_def_id(item.id);
let ty = cx.tcx.type_of(def_id);
if_chain! {
if let hir::ImplItemKind::Method(ref sig, id) = implitem.node;
if let Some(first_arg_ty) = sig.decl.inputs.get(0);
Expand All @@ -899,8 +901,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}

// check conventions w.r.t. conversion method names and predicates
let def_id = cx.tcx.hir.local_def_id(item.id);
let ty = cx.tcx.type_of(def_id);
let is_copy = is_copy(cx, ty);
for &(ref conv, self_kinds) in &CONVENTIONS {
if conv.check(&name.as_str()) {
Expand Down Expand Up @@ -928,16 +928,37 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
break;
}
}
}
}

if let hir::ImplItemKind::Method(_, _) = implitem.node {
let ret_ty = return_ty(cx, implitem.id);

// if return type is impl trait
if let TyKind::Opaque(def_id, _) = ret_ty.sty {

// then one of the associated types must be Self
for predicate in cx.tcx.predicates_of(def_id).predicates.iter() {
match predicate {
(Predicate::Projection(poly_projection_predicate), _) => {
let binder = poly_projection_predicate.ty();
let associated_type = binder.skip_binder();
let associated_type_is_self_type = same_tys(cx, ty, associated_type);

let ret_ty = return_ty(cx, implitem.id);
if name == "new" &&
!ret_ty.walk().any(|t| same_tys(cx, t, ty)) {
span_lint(cx,
NEW_RET_NO_SELF,
implitem.span,
"methods called `new` usually return `Self`");
// if the associated type is self, early return and do not trigger lint
if associated_type_is_self_type { return; }
},
(_, _) => {},
}
}
}

if name == "new" && !same_tys(cx, ret_ty, ty) {
span_lint(cx,
NEW_RET_NO_SELF,
implitem.span,
"methods called `new` usually return `Self`");
}
}
}
}
Expand Down
Loading

0 comments on commit 7da731a

Please sign in to comment.