Commit graph

1519 commits

Author SHA1 Message Date
Philipp Hansch
d7ffaab0fb
Merge pull request #2968 from phansch/first_an_ICE_and_then_some_ice_cream
Fix ICE with 'while let Some(..) = x.iter()'
2018-08-01 06:18:34 +01:00
flip1995
74fcf7de4a
single_char_pattern: lint only on the argument span 2018-07-31 12:20:32 +02:00
Philipp Hansch
946340acfe
Fix ICE with 'while let (..) = x.iter()' 2018-07-29 11:00:26 +02:00
Michael Wright
8eeb3feadf Merge branch 'master' into issue2894 2018-07-28 08:41:10 +02:00
Oliver Schneider
b0dabce478
Merge pull request #2963 from commandline/master
Fix regression in print_literal
2018-07-26 10:11:34 +02:00
Thomas Gideon
9b11be72c0 Fix copy-paste error 2018-07-25 18:14:11 -04:00
Thomas Gideon
5446e73de6 And the ones annotating the source file name. 2018-07-25 18:00:19 -04:00
Thomas Gideon
457b76cedf Update line numbers 2018-07-25 17:51:04 -04:00
Thomas Gideon
bf3f976a43 Fix regression in print_literal 2018-07-25 17:31:17 -04:00
Matthias Krüger
2665f10662 fix a bunch of typos found by codespell 2018-07-25 20:02:52 +02:00
Matthias Krüger
cfc9b33f17 Merge branch 'master' into typos 2018-07-25 19:54:45 +02:00
Michael Wright
5e23fcec0b Merge branch 'master' into issue2894 2018-07-25 06:27:36 +02:00
Ryan Cumming
0afa5e1e21 Merge branch 'master' into allow-pass-by-ref-on-ref-return 2018-07-24 19:03:43 +10:00
Ryan Cumming
58459abd0c Allow pass by reference if we return a reference
Currently this code will trigger `trivally_copy_pass_by_ref`:

```
struct OuterStruct {
    field: [u8; 8],
}

fn return_inner(outer: &OuterStruct) -> &[u8] {
    &outer.field
}
```

If we change the `outer` to be pass-by-value it will not live long
enough for us to return the reference. The above example is trivial but
I've hit this in real code that either returns a reference to either the
argument or in to `self`.

This suppresses the `trivally_copy_pass_by_ref` lint if we return a
reference and it has the same lifetime as the argument. This will likely
miss complex cases with multiple lifetimes bounded by each other but it
should cover the majority of cases with little effort.
2018-07-23 18:44:40 +10:00
Oliver Schneider
ff0e5f967f Rewrite the print/write macro checks as a PreExpansionPass 2018-07-23 00:19:07 +02:00
flip1995
ac77a26b8a
Skip useless_attribute lint on allow(unused_imports) on extern crate items with macro_use 2018-07-19 13:59:25 +02:00
Michael Wright
5bb52c4869 Fix use_self regressions 2018-07-17 08:20:49 +02:00
Michael Wright
847e4dcc0d Merge branch 'master' into issue2894 2018-07-17 06:32:39 +02:00
Oliver Schneider
8f61a792f4 Update test output to changes in rustc 2018-07-16 15:43:30 +02:00
csmoe
8e929946fd DeclKind 2018-07-16 11:48:33 +02:00
csmoe
8cf463fe93 StmtKind 2018-07-16 11:48:33 +02:00
csmoe
12ded030b6 TyKind 2018-07-16 11:48:33 +02:00
csmoe
5d4102ee78 BinOpKind 2018-07-16 11:46:37 +02:00
csmoe
1bd17e4fa2 ExprKind 2018-07-16 11:46:37 +02:00
Michael Wright
b90fc5edfa Fix #2894 2018-07-15 10:38:40 +02:00
Manish Goregaokar
184b99de39 Merge branch 'pr-2889' 2018-07-06 23:20:01 -07:00
gnzlbg
14cbdf2607 do not apply lint to executable crate type 2018-07-04 16:39:52 +02:00
gnzlbg
7c4ec40346 add missing_inline lint
When turned on, the lint warns on all exported functions, methods,
trait methods (default impls, impls), that are not `#[inline]`.

Closes #1503.
2018-07-04 13:50:39 +02:00
Oliver Schneider
63041d070b Rustup 2018-07-01 13:36:14 +02:00
Georg Brandl
949f0d9c72 Fix badly mangled lint message for neg-cmp-op-on-partial-ord 2018-06-29 16:55:31 +02:00
Oliver Schneider
656b26ea4f
Merge pull request #2832 from kennytm/non-copy-const
Lint against const items which are interior mutable.
2018-06-28 08:39:54 +02:00
Oliver Schneider
0de3f36a02
Merge pull request #2849 from mikerite/issue_2741
Fix #2741
2018-06-26 11:08:19 +02:00
Michael Wright
4827bdcc1c Merge branch 'master' into issue_2741 2018-06-26 07:46:56 +02:00
flip1995
b2fb01f23b
Use utils::opt_def_id() instead of def_id() to prevent ICE 2018-06-25 22:25:15 +02:00
kennytm
88b7603b16
Lint against const items which are interior mutable. Fix #1560. 2018-06-23 03:35:36 +08:00
flip1995
6224e19b80
Check for arguments before accessing the first arg 2018-06-21 15:46:24 +02:00
Oliver Schneider
25510cfb13
Merge pull request #2790 from shnewto/vectors-to-indexing-slicing-lint
Extend `indexing_slicing` lint
2018-06-21 10:30:40 +02:00
Bruno Kirschner
fedd3ef711 Allows neg_cmp_op_on_partial_ord for external macros (fixes #2856).
The macro always negates the result of the given comparison in its
internal check which automatically triggered the lint. As its an
external macro there was no chance to do anything about it which lead
to a white listing of all external macros to prevent further issues.
2018-06-20 11:58:15 +02:00
Shea Newton
c479b3bc28
Removing lint for constant usize array indexing
This commit removes the logic in this PR that linted out-of-bounds constant `usize` indexing on arrays. That case is already handled by rustc's `const_err` lint. Beyond removing the linting logic, the test file and its associated stderr were updated to verify that const `usize` indexing operations on arrays are no longer handled by this `indexing_slicing` lint.
2018-06-19 21:30:43 +00:00
Shea Newton
e63f5dfedb
Add tests that index with a const value.
In this commit tests were added to ensure that tests with a `const` index behaved as expected.
In order to minimize the changes to the test's corresponding `stderr`, the tests were appended to
the end of the file.
2018-06-19 16:28:10 +00:00
Shea Newton
4ec439bef0
Revisiting indexing_slicing test cases
This commit contains a few changes. In an attempt to clarify which test cases should and should not produce stderr it became clear that some cases were being handled incorrectly. In order to address these test cases, a minor re-factor was made to the linting logic itself.

The re-factor was driven by edge case handling including a need for additional match conditions for `ExprCall` (`&x[0..=4]`) and `ExprBinary` (`x[1 << 3]`). Rather than attempt to account for each potential `Expr*` the code was re-factored into simply "if ranged index" and an "otherwise" conditions.
2018-06-19 16:28:10 +00:00
Shea Newton
8b59542acc
Second pass at addressing changes requested
The changes reflected in this commit (requested in PR #2790) are as follows:

- Extended `INDEXING_SLICING` documentation to include the array type so that it is clearer when indexing operations are allowed.
- Variable `ty` defined identically in multiple scopes was moved to an outer scope so it's only defined once.
- Added a missing return statement to ensure only one lint is triggered by a scenario.
- Prettified match statement with a `let` clause. (I learned something new!)
- Added `&x[5..].iter().map(|x| 2 * x).collect::<Vec<i32>>()` and `&x[2..].iter().map(|x| 2 * x).collect::<Vec<i32>>()` to the test cases. The first _should trigger the lint/stderr_ and the second _should not_.
2018-06-19 16:28:10 +00:00
Shea Newton
a7c0ff3fa6
This commit represents an attempt to address changes requested in the process of reviewing PR #2790.
The changes reflected in this commit are as follows:

- Revised `IndexingSlicingPass` struct name to IndexingSlicing for consistency with the rest of the code base.
- Revised match arm condition to use `(..)` shorthand in favor of `(_, _, _)`.
- Restored a couple telling variable names.
- Calls to `cx.span_lint` were revised to use `utils::span_help_and_lint`.
- Took a stab at refactoring some generalizable calls to `utils::span_help_and_lint` to minimize duplicate code.
- Revised INDEXING_SLICING declaration to pedantic rather than restriction.
- Added `&x[0..].get(..3)` to the test cases.
2018-06-19 16:28:10 +00:00
Shea Newton
5b759efa4c
Rename instances of array_indexing
This commit renames instances of `array_indexing` to `indexing_slicing` and moves the `indexing_slicing` lint to the `clippy_pedantic` group. The justification for this commit's changes are detailed in the previous commit's message.
2018-06-19 16:27:39 +00:00
Shea Newton
7af0c67855
Extend indexing_slicing lint
Hey there clippy team! I've made some assumptions in this PR and I'm not at all certain they'll look like the right approach to you. I'm looking forward to any feedback or revision requests you have, thanks!

    Prior to this commit the `indexing_slicing` lint was limited to indexing/slicing operations on arrays. This meant that the scope of a really useful lint didn't include vectors. In order to include vectors in the `indexing_slicing` lint a few steps were taken.

    The `array_indexing.rs` source file in `clippy_lints` was renamed to `indexing_slicing.rs` to more accurately reflect the lint's new scope. The `OUT_OF_BOUNDS_INDEXING` lint persists through these changes so if we can know that a constant index or slice on an array is in bounds no lint is triggered.

    The `array_indexing` tests in the `tests/ui` directory were also extended and moved to `indexing_slicing.rs` and `indexing_slicing.stderr`.

    The `indexing_slicing` lint was moved to the `clippy_pedantic` lint group.

    A specific "Consider using" string was added to each of the `indexing_slicing` lint reports.

    At least one of the test scenarios might look peculiar and I'll leave it up to y'all to decide if it's palatable. It's the result of indexing the array `x` after `let x = [1, 2, 3, 4];`

    ```
    error: slicing may panic. Consider using `.get(..n)`or `.get_mut(..n)`instead
      --> $DIR/indexing_slicing.rs:23:6
       |
    23 |     &x[0..][..3];
       |      ^^^^^^^^^^^
    ```

    The error string reports only on the second half's range-to, because the range-from is in bounds!

    Again, thanks for taking a look.

    Closes #2536
2018-06-19 16:27:08 +00:00
uHOOCCOOHu
5b57b5fc61
Add notes for test examples. 2018-06-19 23:18:53 +08:00
uHOOCCOOHu
ce1800d599
Check lifetimes in Fn traits in generic bounds.
Add tests.
2018-06-19 21:25:38 +08:00
Oliver Schneider
d761ba78d8
Merge pull request #2837 from fanzier/panicking_unwrap
Implement lint checking for `unwrap`s that will always panic.
2018-06-19 13:30:38 +02:00
Oliver Schneider
4839c790ae
Merge pull request #2844 from illicitonion/default_trait_access
Add default_trait_access lint
2018-06-19 10:10:20 +02:00
Daniel Wagner-Hall
b24d75313e Exclude generated code 2018-06-18 10:29:25 +01:00