Commit graph

2362 commits

Author SHA1 Message Date
ljedrz
c1b65ec363 fix line format 2019-02-26 11:21:07 +01:00
ljedrz
7bc2e1d60d fix: replace wrong id 2019-02-25 11:06:46 +01:00
ljedrz
8dac8a6ba4 HirIdify some lints 2019-02-24 20:49:43 +01:00
bors
5833e4d26e Auto merge of #3810 - phansch:refactor/extract_module, r=flip1995
Extract diagnostics module and document some functions

This moves the lint building functions from `utils/mod.rs` to their own
`utils/diagnostics.rs` file. Also adds documentation for three of them.
2019-02-24 15:35:01 +00:00
bors
1ce961f083 Auto merge of #3790 - ljedrz:HirIdify_intravisit, r=phansch
partially HirIdify lints

Enables https://github.com/rust-lang/rust/pull/58232 (a part of https://github.com/rust-lang/rust/pull/57578).
2019-02-24 14:32:55 +00:00
ljedrz
601cbc6d84 fix formatting 2019-02-24 15:16:16 +01:00
Philipp Hansch
7d883cddbc
Extract diagnostics module and document some functions
This moves the lint building functions from `utils/mod.rs` to their own
`utils/diagnostics.rs` file. Also adds documentation for three of them.
2019-02-24 14:11:05 +01:00
Philipp Hansch
ff1b1a7c9f
Document some span_lint_* util functions 2019-02-24 09:49:17 +01:00
bors
a5c16e5892 Auto merge of #3789 - bzzzzzz:needless_range_loop_bugfix, r=oli-obk
Make needless_range_loop not applicable to structures without iter method

Fixes https://github.com/rust-lang/rust-clippy/issues/3788

Now we will start lint indexed structure only if it has known iter or iter_mut method implemented.
2019-02-21 09:36:13 +00:00
bzzzz
7767b3a081 Fixed formatting and typo 2019-02-20 10:12:24 -08:00
bors
027dde92e2 Auto merge of #3781 - uniphil:write_with_newline_false_positive, r=oli-obk
Don't check [print/write]_with_newline on raw strings

Some tests for #3778 and some maybe-not-the-greatest code that passes those tests!

I didn't run `fmt` because a) it doesn't seem to install on nightly for me, and b) on stable it wanted to apply formatting to over 90 files. Happy to make any tweaks though!

I suspect this contribution may require more than just tweaks. I'm still sort of new to rust so it may not be idiomatic, and the specific approach I took feels a little heavy-handed and brittle. I'm happy to make changes with some guidance, or equally happy if this gives a starting place for someone else to do it better :)
2019-02-20 16:37:32 +00:00
ljedrz
1fac380886 partially HirIdify lints 2019-02-20 13:16:16 +01:00
bors
d5d8d7bca5 Auto merge of #3779 - mikerite:fix-3704, r=phansch
Improve `iter_cloned_collect` suggestions

Fixes #3704
2019-02-20 09:21:18 +00:00
bzzzz
f9c6682827 Make needless_range_loop not applicable to structures without iter method 2019-02-20 00:10:25 -08:00
bors
075c212849 Auto merge of #3776 - notriddle:drop-bounds, r=oli-obk
Add a lint to warn on `T: Drop` bounds

**What it does:** Checks for generics with `std::ops::Drop` as bounds.

**Why is this bad?** `Drop` bounds do not really accomplish anything.
A type may have compiler-generated drop glue without implementing the
`Drop` trait itself. The `Drop` trait also only has one method,
`Drop::drop`, and that function is by fiat not callable in user code.
So there is really no use case for using `Drop` in trait bounds.

**Known problems:** None.

**Example:**
```rust
fn foo<T: Drop>() {}
```

Fixes #3773
2019-02-19 09:46:29 +00:00
Manish Goregaokar
68476e1d13 Rustup to rustc 1.34.0-nightly (32471f7ea 2019-02-19) 2019-02-19 13:04:43 +05:30
Michael Howell
bc4c3b6ff1 Add more descriptive details 2019-02-18 19:37:08 -07:00
phil
ef72b2cac0 Check {print,write}_with_newline for literal newline
Both regular strings and raw strings can contain literal newlines. This commit
extends the lint to also warn about terminating strings with these.

Behaviour handling for raw strings is also moved into `check_newlines` by
passing in the `is_raw` boolean from `check_tts` as
[suggested](https://github.com/rust-lang/rust-clippy/pull/3781#pullrequestreview-204663732)
2019-02-18 19:22:20 -05:00
Daniel Wagner-Hall
4009a44118 Fix Binding for rustc update 2019-02-18 23:16:53 +00:00
Daniel Wagner-Hall
bcefd688c9 Restore tests
Also, fix existing test
2019-02-18 22:56:43 +00:00
Daniel Wagner-Hall
422c9a0fa2 wildcard_enum_match_arm gives suggestions
And is also more robust
2019-02-18 22:56:43 +00:00
phil
3fa3bd8e94 Don't fail for raw string ending in \n
Pass tests for #3778, {print,write}_with_newline false positive

This change guards the lint from checking newlines with a sort of complicated
check to see if it's a raw string. Raw strings shouldn't be newline-checked,
since r"\n" is literally \-n, not a newline. I think it's ok not to check for
_literal_ newlines at the end of raw strings, but maybe that's debatable.

I... don't think this code is that great. I wanted to write the check after
`check_tts`, but that was too late -- raw string type info is lost (or I
couldn't find it). Putting it inside `check_tts` feels heavy-duty and the check
itself feels like a brittle reach possibly into places it shouldn't.

Maybe someone can fix this up :)
2019-02-18 11:39:40 -05:00
Eduardo Pinho
8994466bfe
Format transmute_from_int_to_float docs 2019-02-18 15:09:34 +00:00
Eduardo Pinho
74ac35bcab
Update why transmute_int_to_float is bad
Fix #3550
2019-02-18 14:14:54 +00:00
Michael Wright
9185c8d996 Format 2019-02-18 08:32:53 +02:00
Michael Howell
2df14c3701 Add a lint to warn on T: Drop bounds
**What it does:** Checks for generics with `std::ops::Drop` as bounds.

**Why is this bad?** `Drop` bounds do not really accomplish anything.
A type may have compiler-generated drop glue without implementing the
`Drop` trait itself. The `Drop` trait also only has one method,
`Drop::drop`, and that function is by fiat not callable in user code.
So there is really no use case for using `Drop` in trait bounds.

**Known problems:** None.

**Example:**
```rust
fn foo<T: Drop>() {}
```
2019-02-17 22:53:08 -07:00
Michael Wright
6e7a813ed2 Improve iter_cloned_collect suggestions
Fixes #3704
2019-02-18 07:30:50 +02:00
Timo
99eccaa120
Add a semicolon as suggested 2019-02-17 22:14:38 -05:00
Timo
508b41ecef
Fix typo in documentation for float_cmp_const lint 2019-02-17 21:06:29 -05:00
flip1995
f204b7ec76
Fix ICE #3717
Restore the old `TypeckTables` in visit_body after walking the body
2019-02-17 01:50:13 +01:00
flip1995
10811d5d89
Fix breakage from rust-lang/rust#58296 2019-02-14 14:01:43 +01:00
Michael Wright
533dd360d7 Fix breakage due to rust-lang/rust#58167 2019-02-14 08:55:50 +02:00
flip1995
5a3cd31c9e
Rustup
cc rust-lang/rust#58137
2019-02-13 22:08:17 +01:00
bors
db13e6fa34 Auto merge of #3756 - g-bartoszek:redundant-closure-for-methods, r=oli-obk
Redundant closure for methods

fixes  #3469
2019-02-12 13:31:44 +00:00
bors
ed3287605d Auto merge of #3757 - mikerite:fix-2542, r=oli-obk
Fix `needless_range_loop` bad suggestion

Detect if the index variable is used inside a closure.

Fixes #2542
2019-02-12 10:27:18 +00:00
bors
2066368583 Auto merge of #3758 - phansch:document_macro, r=flip1995
Document `declare_clippy_lint` macro

Split up from my work on updating CONTRIBUTING.md, which is slowly
making progress.

cc #2666
2019-02-11 23:52:52 +00:00
Philipp Hansch
a14247b500
Update comment regarding crate level cfg_attr 2019-02-11 22:32:54 +01:00
Philipp Hansch
7d3983216f
Document some more core functions 2019-02-11 08:34:37 +01:00
Philipp Hansch
a27022e0dc
Document declare_clippy_lint macro
Split up from my work on updating CONTRIBUTING.md, which is slowly
making progress.

cc #2666
2019-02-11 08:34:37 +01:00
Michael Wright
217965e855 Fix needless_range_loop bad suggestion
Detect if the index variable is used inside a closure.

Fixes #2542
2019-02-11 07:03:12 +02:00
bors
2755d12fa6 Auto merge of #3744 - phansch:fix3144, r=oli-obk
Fix ICE in needless_pass_by_value lint

If I understand it correctly, we were first creating a type with a
`RegionKind::ReErased` region and then deleted it again in
`util::implements_trait` with:

    cx.tcx.erase_regions(&ty);

causing the type query to fail.

It looks like using `ReEmpty` works around that deletion.

Fixes #3144
2019-02-10 13:39:46 +00:00
bors
af43950143 Auto merge of #3740 - flip1995:const_assert_macro, r=oli-obk
Macro check for assertion_on_constants lint

The `assertion_on_constants` lint currently has following output for this code [Playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6f2c9df6fc50baf847212d3b5136ee97):
```rust
macro_rules! assert_const {
    ($len:expr) => {
        assert!($len > 0);
    }
}

fn main() {
    assert_const!(3);
    assert_const!(-1);
}
```
```
warning: assert!(const: true) will be optimized out by the compiler
 --> src/main.rs:3:9
  |
3 |         assert!($len > 0);
  |         ^^^^^^^^^^^^^^^^^^
...
8 |     assert_const!(3);
  |     ---------------- in this macro invocation
  |
  = note: #[warn(clippy::assertions_on_constants)] on by default
  = help: remove it
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants

warning: assert!(const: false) should probably be replaced
 --> src/main.rs:3:9
  |
3 |         assert!($len > 0);
  |         ^^^^^^^^^^^^^^^^^^
...
9 |     assert_const!(-1);
  |     ----------------- in this macro invocation
  |
  = help: use panic!() or unreachable!()
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
```

This is contradictory. This lint should not trigger if the `assert!` is in a macro itself.
2019-02-10 12:47:16 +00:00
Grzegorz
16881390e1 removing redundant closures in the whole project 2019-02-10 13:35:44 +01:00
Grzegorz
b38c587b98 redundant closure implemented for closures containing method calls 2019-02-10 12:58:51 +01:00
bors
5725726345 Auto merge of #3751 - h-michael:opt-def-id, r=phansch
Use Hir::Def opt_def_id

related with: https://github.com/rust-lang/rust-clippy/pull/3750#issuecomment-462010225

Using `def.opt_def_id` in `opt_def_id` before replacing all all at once.
2019-02-09 12:01:45 +00:00
Hirokazu Hata
71dfbe2072 Use Hir::Def opt_def_id 2019-02-09 13:28:21 +09:00
bors
77435f9938 Auto merge of #3748 - phansch:uitest, r=oli-obk
Add a uitest subcommand to simplify UI test invocation

This makes running single tests a lot easier.

It's now

`TESTNAME=xxx cargo uitest`

instead of

`TESTNAME=xxx cargo test --test compile-test`
2019-02-09 04:09:25 +00:00
Hirokazu Hata
66f8fa320b Add new Def type ConstParam 2019-02-09 11:42:13 +09:00
Philipp Hansch
f934f98111
Add a uitest subcommand to simplify UI test invocation
This allows to run

`TESTNAME=xxx cargo uitest`

instead of

`TESTNAME=xxx cargo test --test-compile-test`
2019-02-08 08:09:37 +01:00
bors
e176324fc5 Auto merge of #3665 - jsgf:master, r=oli-obk
Start making clippy easier to invoke in non-cargo contexts

Clippy (clippy-driver) currently has a couple of strong but unnecessary couplings with cargo. This series:
1. makes detection of check builds more robust, and
2. make clippy-driver use the --sysroot specified on the command line as its internal sysroot.
2019-02-06 15:43:07 +00:00