]> git.lizzy.rs Git - rust.git/log
rust.git
4 years agorename `Predicate` to `PredicateKind`, introduce alias
Bastian Kauschke [Mon, 11 May 2020 19:09:57 +0000 (21:09 +0200)]
rename `Predicate` to `PredicateKind`, introduce alias

4 years agoAuto merge of #5582 - vtmargaryan:match_wildcard_for_single_variants, r=flip1995
bors [Wed, 20 May 2020 12:51:28 +0000 (12:51 +0000)]
Auto merge of #5582 - vtmargaryan:match_wildcard_for_single_variants, r=flip1995

New lint: `match_wildcard_for_single_variants`

changelog: Added a new lint match_wildcard_for_single_variants to warn on enum matches where a wildcard is used to match a single variant

Closes #5556

4 years agoAuto merge of #5621 - flip1995:rustup, r=phansch
bors [Wed, 20 May 2020 12:09:24 +0000 (12:09 +0000)]
Auto merge of #5621 - flip1995:rustup, r=phansch

Rustup

@oli-obk Do you know, how we can enforce (ui-)tests pass in rust-lang/rust for Clippy? I can open a PR for this, if you tell me what would be necessary for this.

changelog: none

4 years agoFix dogfood fallout
flip1995 [Wed, 20 May 2020 11:32:53 +0000 (13:32 +0200)]
Fix dogfood fallout

4 years agoUpdate test after const_ptr functions are must_use now
flip1995 [Tue, 19 May 2020 14:12:03 +0000 (16:12 +0200)]
Update test after const_ptr functions are must_use now

4 years agoMerge remote-tracking branch 'upstream/master' into rustup3
flip1995 [Wed, 20 May 2020 11:25:05 +0000 (13:25 +0200)]
Merge remote-tracking branch 'upstream/master' into rustup3

4 years agoAuto merge of #69171 - Amanieu:new-asm, r=nagisa,nikomatsakis
bors [Tue, 19 May 2020 18:32:40 +0000 (18:32 +0000)]
Auto merge of #69171 - Amanieu:new-asm, r=nagisa,nikomatsakis

Implement new asm! syntax from RFC 2850

This PR implements the new `asm!` syntax proposed in https://github.com/rust-lang/rfcs/pull/2850.

# Design

A large part of this PR revolves around taking an `asm!` macro invocation and plumbing it through all of the compiler layers down to LLVM codegen. Throughout the various stages, an `InlineAsm` generally consists of 3 components:

- The template string, which is stored as an array of `InlineAsmTemplatePiece`. Each piece represents either a literal or a placeholder for an operand (just like format strings).
```rust
pub enum InlineAsmTemplatePiece {
    String(String),
    Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
}
```

- The list of operands to the `asm!` (`in`, `[late]out`, `in[late]out`, `sym`, `const`). These are represented differently at each stage of lowering, but follow a common pattern:
  - `in`, `out` and `inout` all have an associated register class (`reg`) or explicit register (`"eax"`).
  - `inout` has 2 forms: one with a single expression that is both read from and written to, and one with two separate expressions for the input and output parts.
  - `out` and `inout` have a `late` flag (`lateout` / `inlateout`) to indicate that the register allocator is allowed to reuse an input register for this output.
  - `out` and the split variant of `inout` allow `_` to be specified for an output, which means that the output is discarded. This is used to allocate scratch registers for assembly code.
  - `sym` is a bit special since it only accepts a path expression, which must point to a `static` or a `fn`.

- The options set at the end of the `asm!` macro. The only one that is particularly of interest to rustc is `NORETURN` which makes `asm!` return `!` instead of `()`.
```rust
bitflags::bitflags! {
    pub struct InlineAsmOptions: u8 {
        const PURE = 1 << 0;
        const NOMEM = 1 << 1;
        const READONLY = 1 << 2;
        const PRESERVES_FLAGS = 1 << 3;
        const NORETURN = 1 << 4;
        const NOSTACK = 1 << 5;
    }
}
```

## AST

`InlineAsm` is represented as an expression in the AST:

```rust
pub struct InlineAsm {
    pub template: Vec<InlineAsmTemplatePiece>,
    pub operands: Vec<(InlineAsmOperand, Span)>,
    pub options: InlineAsmOptions,
}

pub enum InlineAsmRegOrRegClass {
    Reg(Symbol),
    RegClass(Symbol),
}

pub enum InlineAsmOperand {
    In {
        reg: InlineAsmRegOrRegClass,
        expr: P<Expr>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Option<P<Expr>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: P<Expr>,
    },
    SplitInOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_expr: P<Expr>,
        out_expr: Option<P<Expr>>,
    },
    Const {
        expr: P<Expr>,
    },
    Sym {
        expr: P<Expr>,
    },
}
```

The `asm!` macro is implemented in librustc_builtin_macros and outputs an `InlineAsm` AST node. The template string is parsed using libfmt_macros, positional and named operands are resolved to explicit operand indicies. Since target information is not available to macro invocations, validation of the registers and register classes is deferred to AST lowering.

## HIR

`InlineAsm` is represented as an expression in the HIR:

```rust
pub struct InlineAsm<'hir> {
    pub template: &'hir [InlineAsmTemplatePiece],
    pub operands: &'hir [InlineAsmOperand<'hir>],
    pub options: InlineAsmOptions,
}

pub enum InlineAsmRegOrRegClass {
    Reg(InlineAsmReg),
    RegClass(InlineAsmRegClass),
}

pub enum InlineAsmOperand<'hir> {
    In {
        reg: InlineAsmRegOrRegClass,
        expr: Expr<'hir>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Option<Expr<'hir>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Expr<'hir>,
    },
    SplitInOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_expr: Expr<'hir>,
        out_expr: Option<Expr<'hir>>,
    },
    Const {
        expr: Expr<'hir>,
    },
    Sym {
        expr: Expr<'hir>,
    },
}
```

AST lowering is where `InlineAsmRegOrRegClass` is converted from `Symbol`s to an actual register or register class. If any modifiers are specified for a template string placeholder, these are validated against the set allowed for that operand type. Finally, explicit registers for inputs and outputs are checked for conflicts (same register used for different operands).

## Type checking

Each register class has a whitelist of types that it may be used with. After the types of all operands have been determined, the `intrinsicck` pass will check that these types are in the whitelist. It also checks that split `inout` operands have compatible types and that `const` operands are integers or floats. Suggestions are emitted where needed if a template modifier should be used for an operand based on the type that was passed into it.

## HAIR

`InlineAsm` is represented as an expression in the HAIR:

```rust
crate enum ExprKind<'tcx> {
    // [..]
    InlineAsm {
        template: &'tcx [InlineAsmTemplatePiece],
        operands: Vec<InlineAsmOperand<'tcx>>,
        options: InlineAsmOptions,
    },
}
crate enum InlineAsmOperand<'tcx> {
    In {
        reg: InlineAsmRegOrRegClass,
        expr: ExprRef<'tcx>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Option<ExprRef<'tcx>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: ExprRef<'tcx>,
    },
    SplitInOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_expr: ExprRef<'tcx>,
        out_expr: Option<ExprRef<'tcx>>,
    },
    Const {
        expr: ExprRef<'tcx>,
    },
    SymFn {
        expr: ExprRef<'tcx>,
    },
    SymStatic {
        expr: ExprRef<'tcx>,
    },
}
```

The only significant change compared to HIR is that `Sym` has been lowered to either a `SymFn` whose `expr` is a `Literal` ZST of the `fn`, or a `SymStatic` whose `expr` is a `StaticRef`.

## MIR

`InlineAsm` is represented as a `Terminator` in the MIR:

```rust
pub enum TerminatorKind<'tcx> {
    // [..]

    /// Block ends with an inline assembly block. This is a terminator since
    /// inline assembly is allowed to diverge.
    InlineAsm {
        /// The template for the inline assembly, with placeholders.
        template: &'tcx [InlineAsmTemplatePiece],

        /// The operands for the inline assembly, as `Operand`s or `Place`s.
        operands: Vec<InlineAsmOperand<'tcx>>,

        /// Miscellaneous options for the inline assembly.
        options: InlineAsmOptions,

        /// Destination block after the inline assembly returns, unless it is
        /// diverging (InlineAsmOptions::NORETURN).
        destination: Option<BasicBlock>,
    },
}

pub enum InlineAsmOperand<'tcx> {
    In {
        reg: InlineAsmRegOrRegClass,
        value: Operand<'tcx>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        place: Option<Place<'tcx>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_value: Operand<'tcx>,
        out_place: Option<Place<'tcx>>,
    },
    Const {
        value: Operand<'tcx>,
    },
    SymFn {
        value: Box<Constant<'tcx>>,
    },
    SymStatic {
        value: Box<Constant<'tcx>>,
    },
}
```

As part of HAIR lowering, `InOut` and `SplitInOut` operands are lowered to a split form with a separate `in_value` and `out_place`.

Semantically, the `InlineAsm` terminator is similar to the `Call` terminator except that it has multiple output places where a `Call` only has a single return place output.

The constant promotion pass is used to ensure that `const` operands are actually constants (using the same logic as `#[rustc_args_required_const]`).

## Codegen

Operands are lowered one more time before being passed to LLVM codegen:

```rust
pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
    In {
        reg: InlineAsmRegOrRegClass,
        value: OperandRef<'tcx, B::Value>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        place: Option<PlaceRef<'tcx, B::Value>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_value: OperandRef<'tcx, B::Value>,
        out_place: Option<PlaceRef<'tcx, B::Value>>,
    },
    Const {
        string: String,
    },
    SymFn {
        instance: Instance<'tcx>,
    },
    SymStatic {
        def_id: DefId,
    },
}
```

The operands are lowered to LLVM operands and constraint codes as follow:
- `out` and the output part of `inout` operands are added first, as required by LLVM. Late output operands have a `=` prefix added to their constraint code, non-late output operands have a `=&` prefix added to their constraint code.
- `in` operands are added normally.
- `inout` operands are tied to the matching output operand.
- `sym` operands are passed as function pointers or pointers, using the `"s"` constraint.
- `const` operands are formatted to a string and directly inserted in the template string.

The template string is converted to LLVM form:
- `$` characters are escaped as `$$`.
- `const` operands are converted to strings and inserted directly.
- Placeholders are formatted as `${X:M}` where `X` is the operand index and `M` is the modifier character. Modifiers are converted from the Rust form to the LLVM form.

The various options are converted to clobber constraints or LLVM attributes, refer to the [RFC](https://github.com/Amanieu/rfcs/blob/inline-asm/text/0000-inline-asm.md#mapping-to-llvm-ir) for more details.

Note that LLVM is sometimes rather picky about what types it accepts for certain constraint codes so we sometimes need to insert conversions to/from a supported type. See the target-specific ISelLowering.cpp files in LLVM for details.

# Adding support for new architectures

Adding inline assembly support to an architecture is mostly a matter of defining the registers and register classes for that architecture. All the definitions for register classes are located in `src/librustc_target/asm/`.

Additionally you will need to implement lowering of these register classes to LLVM constraint codes in `src/librustc_codegen_llvm/asm.rs`.

4 years agoAdd note, that a merge commit after push is necessary
flip1995 [Tue, 19 May 2020 14:36:14 +0000 (16:36 +0200)]
Add note, that a merge commit after push is necessary

4 years agoAdd note that a subtree fix and stack limit increase is required
flip1995 [Tue, 19 May 2020 13:18:16 +0000 (15:18 +0200)]
Add note that a subtree fix and stack limit increase is required

4 years agoAuto merge of #68717 - petrochenkov:stabexpat, r=varkor
bors [Tue, 19 May 2020 03:11:32 +0000 (03:11 +0000)]
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor

Stabilize fn-like proc macros in expression, pattern and statement positions

I.e. all the positions in which stable `macro_rules` macros are supported.

Depends on https://github.com/rust-lang/rust/pull/68716 ("Stabilize `Span::mixed_site`").

cc https://github.com/rust-lang/rust/issues/54727
cc https://github.com/rust-lang/rust/issues/54727#issuecomment-580647446

Stabilization report: https://github.com/rust-lang/rust/pull/68717#issuecomment-623197503.

4 years agoHandle InlineAsm in clippy
Amanieu d'Antras [Wed, 6 May 2020 14:03:53 +0000 (15:03 +0100)]
Handle InlineAsm in clippy

4 years agoAdd to the list of words clippy::doc_markdown ignores
Rahul Butani [Mon, 18 May 2020 03:21:02 +0000 (22:21 -0500)]
Add to the list of words clippy::doc_markdown ignores

4 years agoMerge commit 'e214ea82ad0a751563acf67e1cd9279cf302db3a' into clippyup
flip1995 [Sun, 17 May 2020 15:36:26 +0000 (17:36 +0200)]
Merge commit 'e214ea82ad0a751563acf67e1cd9279cf302db3a' into clippyup

4 years agoAuto merge of #5568 - ThibsG:RenameIdentityConversionLint, r=flip1995
bors [Sun, 17 May 2020 11:29:04 +0000 (11:29 +0000)]
Auto merge of #5568 - ThibsG:RenameIdentityConversionLint, r=flip1995

Rename lint `identity_conversion` to `useless_conversion`

Lint name `identity_conversion` was misleading, so this PR renames it to `useless_conversion`.

As decision has not really came up in the issue comments, this PR will probably need discussion.

fixes #3106

changelog: Rename lint `identity_conversion` to `useless_conversion`

4 years agoAuto merge of #5529 - alex-700:improve-option-and-then-some-lint, r=phansch
bors [Sun, 17 May 2020 10:58:56 +0000 (10:58 +0000)]
Auto merge of #5529 - alex-700:improve-option-and-then-some-lint, r=phansch

Improve `option_and_then_some` lint

fixed #5492

changelog: Improve and generalize `option_and_then_some` and rename it to `bind_instead_of_map`.

4 years agoimprove and generalize `option_and_then_some` lint
Aleksei Latyshev [Sat, 25 Apr 2020 20:33:11 +0000 (23:33 +0300)]
improve and generalize `option_and_then_some` lint

- rename it to bind_instead_of_map

4 years agoAuto merge of #5608 - flip1995:rustup, r=phansch
bors [Sun, 17 May 2020 05:41:39 +0000 (05:41 +0000)]
Auto merge of #5608 - flip1995:rustup, r=phansch

Rustup with git subtree

The commits from the last rustup #5587, are again included in this rustup, since I rebased the rustup. Lesson learned: never rebase, only merge when working with git subtree.

changelog: none

4 years agoBetter explain remotes in the sync process.
Philipp Krones [Sat, 16 May 2020 23:38:01 +0000 (01:38 +0200)]
Better explain remotes in the sync process.

4 years agoRun fmt
flip1995 [Sat, 16 May 2020 23:18:43 +0000 (01:18 +0200)]
Run fmt

4 years agoRe-remove util/dev
flip1995 [Sat, 16 May 2020 23:14:28 +0000 (01:14 +0200)]
Re-remove util/dev

Maybe someday, git subtree will do it right

4 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Sat, 16 May 2020 23:13:02 +0000 (01:13 +0200)]
Merge remote-tracking branch 'upstream/master' into rustup

4 years agosimplify multispan_sugg interface
Aleksei Latyshev [Sat, 25 Apr 2020 17:52:00 +0000 (20:52 +0300)]
simplify multispan_sugg interface

- add `multispan_sugg_with_applicability`
- not it gets `&str` instead of `String`, like in `diag.multispan_suggestion`

4 years agoRename lint `identity_conversion` to `useless_conversion`
ThibsG [Mon, 4 May 2020 15:09:02 +0000 (17:09 +0200)]
Rename lint `identity_conversion` to `useless_conversion`

4 years agoAuto merge of #5563 - ThibsG:MergeLints, r=flip1995
bors [Sat, 16 May 2020 20:17:11 +0000 (20:17 +0000)]
Auto merge of #5563 - ThibsG:MergeLints, r=flip1995

Merge some lints together

This PR merges following lints:

- `block_in_if_condition_expr` and `block_in_if_condition_stmt` → `blocks_in_if_conditions`
- `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` → `map_unwrap`
- `option_unwrap_used` and `result_unwrap_used` → `unwrap_used`
- `option_expect_used` and `result_expect_used` → `expect_used`
- `wrong_pub_self_convention` into `wrong_self_convention`
- `for_loop_over_option` and `for_loop_over_result` → `for_loops_over_fallibles`

Lints that have already been merged since the issue was created:
- [x] `new_without_default` and `new_without_default_derive` → `new_without_default`

Need more discussion:
- `string_add` and `string_add_assign`: do we agree to merge them or not? Is there something more to do? → **not merge finally**
- `identity_op` and `modulo_one` → `useless_arithmetic`: seems outdated, since `modulo_arithmetic` has been created.

fixes #1078

changelog: Merging some lints together:
- `block_in_if_condition_expr` and `block_in_if_condition_stmt` → `blocks_in_if_conditions`
- `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` → `map_unwrap_or`
- `option_unwrap_used` and `result_unwrap_used` → `unwrap_used`
- `option_expect_used` and `result_expect_used` → `expect_used`
- `for_loop_over_option` and `for_loop_over_result` → `for_loops_over_fallibles`

4 years agoRollup merge of #72047 - Julian-Wollersberger:literal_error_reporting_cleanup, r...
Ralf Jung [Sat, 16 May 2020 17:46:31 +0000 (19:46 +0200)]
Rollup merge of #72047 - Julian-Wollersberger:literal_error_reporting_cleanup, r=petrochenkov

Literal error reporting cleanup

While doing some performance work, I noticed some code duplication in `librustc_parser/lexer/mod.rs`, so I cleaned it up.

This PR is probably best reviewed commit by commit.

I'm not sure what the API stability practices for `librustc_lexer` are. Four public methods in `unescape.rs` can be removed, but two are used by clippy, so I left them in for now.
I could open a PR for Rust-Analyzer when this one lands.

But how do I open a PR for clippy? (Git submodules are frustrating to work with)

4 years agoAuto merge of #5596 - ebroto:issue_5212, r=phansch
bors [Sat, 16 May 2020 08:49:15 +0000 (08:49 +0000)]
Auto merge of #5596 - ebroto:issue_5212, r=phansch

Fix comparison_chain false positive

changelog: comparison_chain: fix false positives when the binary operation is the same.

Fixes #5212

4 years agoAuto merge of #5602 - ebroto:issue_3430, r=phansch
bors [Sat, 16 May 2020 08:33:47 +0000 (08:33 +0000)]
Auto merge of #5602 - ebroto:issue_3430, r=phansch

identity_op: allow `1 << 0`

I went for accepting `1 << 0` verbatim instead of something more general as it seems to be what everyone in the issue thread needed.

changelog: identity_op: allow `1 << 0` as it's a common pattern in bit manipulation code.

Fixes #3430

4 years agoRollup merge of #72090 - RalfJung:rustc_driver-exit-code, r=oli-obk
Dylan DPC [Sat, 16 May 2020 00:37:23 +0000 (02:37 +0200)]
Rollup merge of #72090 - RalfJung:rustc_driver-exit-code, r=oli-obk

rustc_driver: factor out computing the exit code

In a recent Miri PR I [added a convenience wrapper](https://github.com/rust-lang/miri/pull/1405/files#diff-c3d602c5c8035a16699ce9c015bfeceaR125) around `catch_fatal_errors` and `run_compiler` that @oli-obk suggested I could upstream. However, after seeing what could be shared between `rustc_driver::main`, clippy and Miri, really the only thing I found is computing the exit code -- so that's what this PR does.

What prevents using the Miri convenience function in `rustc_driver::main` and clippy is that they do extra work inside `catch_fatal_errors`, and while I could abstract that away, clippy actually *computes the callbacks* inside there, and I fond no good way to abstract that and thus gave up. Maybe the clippy thing could be moved out, I am not sure if it ever can actually raise a `FatalErrorMarker` -- someone more knowledgeable in clippy would have to do that.

4 years agoRollup merge of #71948 - csmoe:issue-61076, r=oli-obk
Dylan DPC [Sat, 16 May 2020 00:37:21 +0000 (02:37 +0200)]
Rollup merge of #71948 - csmoe:issue-61076, r=oli-obk

Suggest to await future before ? operator

Closes https://github.com/rust-lang/rust/issues/71811
cc #61076

4 years agoAuto merge of #5599 - dtolnay:letif, r=flip1995
bors [Fri, 15 May 2020 21:55:43 +0000 (21:55 +0000)]
Auto merge of #5599 - dtolnay:letif, r=flip1995

Downgrade useless_let_if_seq to nursery

I feel that this lint has the wrong balance of incorrect suggestions for a default-enabled lint.

The immediate code I faced was something like:

```rust
fn main() {
    let mut good = do1();
    if !do2() {
        good = false;
    }
    if good {
        println!("good");
    }
}

fn do1() -> bool { println!("1"); false }
fn do2() -> bool { println!("2"); false }
```

On this code Clippy calls it unidiomatic and suggests the following diff, which has different behavior in a way that I don't necessarily want.

```diff
- let mut good = do1();
- if !do2() {
-     good = false;
- }
+ let good = if !do2() {
+     false
+ } else {
+     do1()
+ };
```

On exploring issues filed about this lint, I have found that other users have also struggled with inappropriate suggestions (https://github.com/rust-lang/rust-clippy/issues/4124, https://github.com/rust-lang/rust-clippy/issues/3043, https://github.com/rust-lang/rust-clippy/issues/2918, https://github.com/rust-lang/rust-clippy/issues/2176) and suggestions that make the code worse (https://github.com/rust-lang/rust-clippy/issues/3769, https://github.com/rust-lang/rust-clippy/issues/2749). Overall I believe that this lint is still at nursery quality for now and should not be enabled.

---

changelog: Remove useless_let_if_seq from default set of enabled lints

4 years agoAdd more test cases for match_wildcard_for_single_variants
Vardan Margaryan [Fri, 15 May 2020 21:19:30 +0000 (00:19 +0300)]
Add more test cases for match_wildcard_for_single_variants

4 years agoFix check for missing enum variants from match expressions
Vardan Margaryan [Fri, 15 May 2020 21:06:52 +0000 (00:06 +0300)]
Fix check for missing enum variants from match expressions

TupleStruct matches are checked for exhaustiveness

4 years agoRevert "Fix cases of match_wildcard_for_single_variants lint when it is spanned on...
Vardan Margaryan [Fri, 15 May 2020 19:33:37 +0000 (22:33 +0300)]
Revert "Fix cases of match_wildcard_for_single_variants lint when it is spanned on Option"

This reverts commit 494830797744c09d6de3b2b2452ab185d2204005.

4 years agoidentity_op: allow `1 << 0`
Eduardo Broto [Fri, 15 May 2020 19:17:37 +0000 (21:17 +0200)]
identity_op: allow `1 << 0`

4 years agoFix CHANGELOG.md and lint names plural
ThibsG [Fri, 15 May 2020 16:20:07 +0000 (18:20 +0200)]
Fix CHANGELOG.md and lint names plural

4 years agoAuto merge of #5592 - ebroto:extend_unused_unit, r=flip1995
bors [Fri, 15 May 2020 14:47:11 +0000 (14:47 +0000)]
Auto merge of #5592 - ebroto:extend_unused_unit, r=flip1995

unused_unit: lint also in type parameters and where clauses

changelog: unused_unit now also lints in type parameters and where clauses

Fixes #5585

4 years agoimplement type_implments_trait query
csmoe [Thu, 14 May 2020 15:07:46 +0000 (23:07 +0800)]
implement type_implments_trait query

4 years agoRename lint `map_unwrap` to `map_unwrap_or` and register lints as renamed
ThibsG [Sun, 3 May 2020 17:58:27 +0000 (19:58 +0200)]
Rename lint `map_unwrap` to `map_unwrap_or` and register lints as renamed

4 years agoFix example code of wildcard_enum_match_arm lint
Vardan Margaryan [Thu, 14 May 2020 19:41:05 +0000 (22:41 +0300)]
Fix example code of wildcard_enum_match_arm lint

4 years agoApply suggestions from PR review
Vardan Margaryan [Thu, 14 May 2020 19:40:33 +0000 (22:40 +0300)]
Apply suggestions from PR review

4 years agoFix cases of match_wildcard_for_single_variants lint when it is spanned on Option
Vardan Margaryan [Sun, 10 May 2020 15:34:29 +0000 (18:34 +0300)]
Fix cases of match_wildcard_for_single_variants lint when it is spanned on Option

4 years agoFix trivial cases of new match_wildcard_for_single_variants lint
Vardan Margaryan [Sun, 10 May 2020 15:33:12 +0000 (18:33 +0300)]
Fix trivial cases of new match_wildcard_for_single_variants lint

4 years agoAdd the redundant_wildcard_enum_match lint
Vardan Margaryan [Sat, 9 May 2020 21:08:41 +0000 (00:08 +0300)]
Add the redundant_wildcard_enum_match lint

4 years agoDowngrade useless_let_if_seq to nursery
David Tolnay [Thu, 14 May 2020 16:57:36 +0000 (09:57 -0700)]
Downgrade useless_let_if_seq to nursery

4 years agoMerge `for_loop_over_option` and `for_loop_over_result` lints into `for_loop_over_fal...
ThibsG [Sun, 3 May 2020 13:16:00 +0000 (15:16 +0200)]
Merge `for_loop_over_option` and `for_loop_over_result` lints into `for_loop_over_fallible` lint

4 years agoMerge `option_expect_used` and `result_expect_used` lints into `expect_used` lint
ThibsG [Sun, 3 May 2020 11:32:17 +0000 (13:32 +0200)]
Merge `option_expect_used` and `result_expect_used` lints into `expect_used` lint

4 years agoMerge `option_unwrap_used` and `result_unwrap_used` lints into `unwrap_used` lint
ThibsG [Sun, 3 May 2020 11:11:18 +0000 (13:11 +0200)]
Merge `option_unwrap_used` and `result_unwrap_used` lints into `unwrap_used` lint

4 years agoMerge `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_e...
ThibsG [Sun, 3 May 2020 10:28:40 +0000 (12:28 +0200)]
Merge `option_map_unwrap_or`, `option_map_unwrap_or_else` and `result_map_unwrap_or_else` lints into `map_unwrap` lint

4 years agoMerge `block_in_if_condition_expr` and `block_in_if_condition_stmt` lints into `block...
ThibsG [Sun, 3 May 2020 09:20:51 +0000 (11:20 +0200)]
Merge `block_in_if_condition_expr` and `block_in_if_condition_stmt` lints into `block_in_if_condition` lint

4 years agoAuto merge of #5583 - ebroto:reversed_empty_ranges, r=yaahc,flip1995
bors [Thu, 14 May 2020 12:59:24 +0000 (12:59 +0000)]
Auto merge of #5583 - ebroto:reversed_empty_ranges, r=yaahc,flip1995

Reversed empty ranges

This lint checks range expressions with inverted limits which result in empty ranges. This includes also the ranges used to index slices.

The lint reverse_range_loop was covering iteration of reversed ranges in a for loop, which is a subset of what this new lint covers, so it has been removed. I'm not sure if that's the best choice. It would be doable to check in the new lint that we are not in the arguments of a for loop; I went for removing it because the logic was too similar to keep them separated.

changelog: Added reversed_empty_ranges lint that checks for ranges where the limits have been inverted, resulting in empty ranges. Removed reverse_range_loop which was covering a subset of the new lint.

Closes #4192
Closes #96

4 years agoAuto merge of #5590 - ebroto:issue_5579, r=phansch
bors [Thu, 14 May 2020 05:34:54 +0000 (05:34 +0000)]
Auto merge of #5590 - ebroto:issue_5579, r=phansch

Fix ICE caused in unwrap module

changelog: Fix ICE in unwrap module with unexpected number of parameters for method of Option/Result

Fixes #5579

4 years agoFix comparison_chain false positive
Eduardo Broto [Wed, 13 May 2020 22:26:09 +0000 (00:26 +0200)]
Fix comparison_chain false positive

4 years agoAvoid running doctest that is expected to panic
Eduardo Broto [Wed, 13 May 2020 19:07:13 +0000 (21:07 +0200)]
Avoid running doctest that is expected to panic

4 years agoMove test for issue 5579 under tests/ui/crashes
Eduardo Broto [Wed, 13 May 2020 18:47:44 +0000 (20:47 +0200)]
Move test for issue 5579 under tests/ui/crashes

4 years agoFix ICE caused in unwrap module
Eduardo Broto [Tue, 12 May 2020 20:05:56 +0000 (22:05 +0200)]
Fix ICE caused in unwrap module

4 years agoRe-add old tests for empty range loops
Eduardo Broto [Mon, 11 May 2020 21:48:48 +0000 (23:48 +0200)]
Re-add old tests for empty range loops

4 years agoRemove reverse_range_loop lint
Eduardo Broto [Sun, 10 May 2020 22:53:31 +0000 (00:53 +0200)]
Remove reverse_range_loop lint

4 years agoNew lint: reversed_empty_ranges
Eduardo Broto [Sun, 10 May 2020 22:52:33 +0000 (00:52 +0200)]
New lint: reversed_empty_ranges

4 years agounused_unit: lint also in type parameters and where clauses
Eduardo Broto [Tue, 12 May 2020 23:04:16 +0000 (01:04 +0200)]
unused_unit: lint also in type parameters and where clauses

4 years agoReplace some usages of the old `unescape_` functions in AST, clippy and tests.
Julian Wollersberger [Wed, 13 May 2020 08:03:49 +0000 (10:03 +0200)]
Replace some usages of the old `unescape_` functions in AST, clippy and tests.

4 years agoAuto merge of #5587 - flip1995:rustup, r=phansch
bors [Wed, 13 May 2020 05:55:10 +0000 (05:55 +0000)]
Auto merge of #5587 - flip1995:rustup, r=phansch

Rustup

Done with

```bash
git subtree push -P src/tools/clippy git@github.com:flip1995/rust-clippy rustup
```

from https://github.com/flip1995/rust/tree/clippyup

A rebase was required to get rid of empty merge commits, that somehow were not empty? :thinking:

changelog: none

4 years agoUpdate failing test
flip1995 [Mon, 11 May 2020 19:40:33 +0000 (21:40 +0200)]
Update failing test

4 years agoRun cargo dev fmt
flip1995 [Mon, 11 May 2020 19:31:01 +0000 (21:31 +0200)]
Run cargo dev fmt

4 years agoFix fallout
flip1995 [Mon, 11 May 2020 19:28:14 +0000 (21:28 +0200)]
Fix fallout

Re-remove util/dev file

4 years agoFix clippy.
Camille GILLOT [Fri, 8 May 2020 11:57:01 +0000 (13:57 +0200)]
Fix clippy.

4 years agoFix nit and cargo.lock
Jack Huey [Thu, 7 May 2020 21:46:31 +0000 (17:46 -0400)]
Fix nit and cargo.lock

4 years agoMerge commit '43a1777b89cf6791f9e20878b4e5e3ae907867a5' into clippyup
flip1995 [Mon, 11 May 2020 18:23:47 +0000 (20:23 +0200)]
Merge commit '43a1777b89cf6791f9e20878b4e5e3ae907867a5' into clippyup

4 years agorustc_driver: factor out computing the exit code
Ralf Jung [Sun, 10 May 2020 21:36:41 +0000 (23:36 +0200)]
rustc_driver: factor out computing the exit code

4 years agoAuto merge of #5564 - MrAwesome:master, r=flip1995
bors [Sat, 9 May 2020 18:43:28 +0000 (18:43 +0000)]
Auto merge of #5564 - MrAwesome:master, r=flip1995

Allow `use super::*;` glob imports

changelog: Allow super::* glob imports

fixes #5554
fixes #5569

A first pass at #5554 - this allows all `use super::*` to pass, which may or may not be desirable. The original issue was around allowing test modules to import their entire parent modules - I'm happy to modify this to do that instead, may just need some guidance on how to implement that (I played around a bit with #[cfg(test)] but from what I can gather, clippy itself isn't in test mode when running, even if the code in question is being checked for the test target).

4 years agoMove is_test_module check to top of function
Glenn Hope [Sat, 9 May 2020 17:16:47 +0000 (10:16 -0700)]
Move is_test_module check to top of function

4 years agoCheck is_macro inside check_exceptions, update references to fix test
Glenn Hope [Sat, 9 May 2020 17:14:29 +0000 (10:14 -0700)]
Check is_macro inside check_exceptions, update references to fix test

4 years agoFix test from auto-formatter fix
Glenn Hope [Sat, 9 May 2020 15:33:35 +0000 (08:33 -0700)]
Fix test from auto-formatter fix

4 years agoRemove check for Fn, reflect this in test cases, make test cases more robust/explicit
Glenn Hope [Sat, 9 May 2020 15:04:07 +0000 (08:04 -0700)]
Remove check for Fn, reflect this in test cases, make test cases more robust/explicit

4 years agoRemove unnecessary field, check for Mod/Fn ItemKind
Glenn Hope [Sat, 9 May 2020 01:22:27 +0000 (18:22 -0700)]
Remove unnecessary field, check for Mod/Fn ItemKind

4 years agoAlso have flag disable macro check
Glenn Hope [Thu, 7 May 2020 21:48:27 +0000 (14:48 -0700)]
Also have flag disable macro check

4 years agoAdd check for "test" in parent name. Include flag for disabling wildcard import excep...
Glenn Hope [Thu, 7 May 2020 21:41:54 +0000 (14:41 -0700)]
Add check for "test" in parent name. Include flag for disabling wildcard import exceptions

4 years agoCheck if the parent module name contains "test"
Glenn Hope [Thu, 7 May 2020 15:06:30 +0000 (08:06 -0700)]
Check if the parent module name contains "test"

4 years agoRun `cargo dev fmt`
Glenn Hope [Sun, 3 May 2020 18:18:10 +0000 (11:18 -0700)]
Run `cargo dev fmt`

4 years agoAllow 'use super::*;' imports
Glenn Hope [Sun, 3 May 2020 17:56:25 +0000 (10:56 -0700)]
Allow 'use super::*;' imports

4 years agoAuto merge of #5580 - matthiaskrgr:regex_dep, r=flip1995
bors [Sat, 9 May 2020 12:41:19 +0000 (12:41 +0000)]
Auto merge of #5580 - matthiaskrgr:regex_dep, r=flip1995

deps: remove unused regex dependency from root crate

changelog: none

4 years agoRollup merge of #71555 - cjgillot:nameless, r=matthewjasper
Ralf Jung [Sat, 9 May 2020 11:36:39 +0000 (13:36 +0200)]
Rollup merge of #71555 - cjgillot:nameless, r=matthewjasper

Remove ast::{Ident, Name} reexports.

The reexport of `Symbol` into `Name` confused me.

4 years agodeps: remove unused regex dependency from root crate
Matthias Krüger [Fri, 8 May 2020 23:27:30 +0000 (01:27 +0200)]
deps: remove unused regex dependency from root crate

4 years agoFix clippy.
Camille GILLOT [Fri, 8 May 2020 11:57:01 +0000 (13:57 +0200)]
Fix clippy.

4 years agoAuto merge of #5541 - DarkEld3r:patch-1, r=flip1995
bors [Fri, 8 May 2020 10:34:50 +0000 (10:34 +0000)]
Auto merge of #5541 - DarkEld3r:patch-1, r=flip1995

Extend example for the `unneeded_field_pattern` lint

Current example is incorrect (or pseudo-code) because a struct name is omitted. I have used the code from the tests instead. Perhaps this example can be made less verbose, but I think it is more convenient to see a "real" code as an example.

---

changelog: extend example for the `unneeded_field_pattern` lint

4 years agoAuto merge of #5576 - ebroto:manual_async_fn, r=flip1995
bors [Fri, 8 May 2020 01:50:28 +0000 (01:50 +0000)]
Auto merge of #5576 - ebroto:manual_async_fn, r=flip1995

Add the manual_async_fn lint

changelog: Added the `manual_async_fn` lint to warn on functions that can be simplified using async syntax

Closes #5503

4 years agoFix nit and cargo.lock
Jack Huey [Thu, 7 May 2020 21:46:31 +0000 (17:46 -0400)]
Fix nit and cargo.lock

4 years agoApply suggestions from PR review
Eduardo Broto [Thu, 7 May 2020 20:40:28 +0000 (22:40 +0200)]
Apply suggestions from PR review

4 years agoFix doc comment in lint declaration
Eduardo Broto [Thu, 7 May 2020 20:03:38 +0000 (22:03 +0200)]
Fix doc comment in lint declaration

4 years agoAdd the manual_async_fn lint
Eduardo Broto [Thu, 7 May 2020 19:41:23 +0000 (21:41 +0200)]
Add the manual_async_fn lint

4 years agoAuto merge of #5566 - oli-obk:sync-from-rustc, r=flip1995
bors [Wed, 6 May 2020 09:49:00 +0000 (09:49 +0000)]
Auto merge of #5566 - oli-obk:sync-from-rustc, r=flip1995

Update to rustc changes

changelog: none

So, turns out `git subtree push` dies in various interesting ways, but the source cause is that the rustc repo looks like

```
--- A --- B --- C ---
     \--- D ---/
```

where `B` is the commit where I added clippy to rustc and `D` is an arbitrary other PR and `C` is the master branch (or an earlier commit in it). When we now do `git subtree push`, it doesn't stop looking for things to merge at `B` as it needs to look at `D`, too, but then the bad thing happens, and it doesn't stop at `A` either, and just goes on looking at the entire history of rustc in a recursive bash script. That recursion then quickly runs into a stack overflow. While we can increase the stack size via `ulimit -s 60000`, that just means I was waiting for 30 minutes looking at `git subtree push` counting up the number of commits it has looked at. I aborted that, as a process that needs 30 mins for a push is not reasonable.

This PR cheats by just doing a `cp -r ../rustc/src/tools/clippy/* .` inside my clippy checkout and committing all changes. I'm working on getting us a better workflow, but until then, this workaround will work nicely. Note that this requires a `git subrepo pull` to have occurred in the `rustc` checkout. It's not necessary to merge that pull in order to update clippy, it's just necessary in order to not revert code in the clippy repo that hasn't been synced yet to the rustc repo.

4 years agoUpdate ui tests
Oliver Scherer [Tue, 5 May 2020 13:11:59 +0000 (15:11 +0200)]
Update ui tests

4 years agoUpdate to rustc changes
Oliver Scherer [Mon, 4 May 2020 13:13:07 +0000 (15:13 +0200)]
Update to rustc changes

4 years agoUpdate clippy lint
Dylan MacKenzie [Sun, 3 May 2020 18:41:03 +0000 (11:41 -0700)]
Update clippy lint

4 years agoStabilize fn-like proc macros in expression, pattern and statement positions
Vadim Petrochenkov [Fri, 31 Jan 2020 22:02:31 +0000 (01:02 +0300)]
Stabilize fn-like proc macros in expression, pattern and statement positions

4 years agoApply suggestions from code review
Philipp Krones [Sun, 3 May 2020 14:47:57 +0000 (16:47 +0200)]
Apply suggestions from code review

Co-authored-by: Phil Hansch <dev@phansch.net>
4 years agoUpdate contributing section about syncing Clippy
flip1995 [Sun, 3 May 2020 13:59:57 +0000 (15:59 +0200)]
Update contributing section about syncing Clippy

4 years agoAuto merge of #5560 - CrazyRoka:fix-match-on-vector-full-range, r=phansch,flip1995
bors [Sat, 2 May 2020 16:13:02 +0000 (16:13 +0000)]
Auto merge of #5560 - CrazyRoka:fix-match-on-vector-full-range, r=phansch,flip1995

Fix match on vec items: match on vec[..]

- Added new tests
- Fixed false positive when matching on full range, which will never panic

Closes #5551
changelog: fix match_on_vec_items when matching full range

4 years agoAuto merge of #5558 - ThibsG:FixUnwrapInArgs, r=flip1995
bors [Sat, 2 May 2020 15:59:18 +0000 (15:59 +0000)]
Auto merge of #5558 - ThibsG:FixUnwrapInArgs, r=flip1995

Fix `unnecessary_unwrap` lint when checks are done in parameters

Fixes a false positive in `unnecessary_unwrap` lint when checks are done in macro parameters.

FIxes #5174

changelog: Fixes a false positive in `unnecessary_unwrap` lint when checks are done in macro parameters.

4 years agoAuto merge of #5559 - alex-700:fix-while-let-on-iterator-fp, r=flip1995
bors [Sat, 2 May 2020 15:30:58 +0000 (15:30 +0000)]
Auto merge of #5559 - alex-700:fix-while-let-on-iterator-fp, r=flip1995

Fix FP on while-let-on-iterator

- fix `is_refutable` for slice patterns
- fix `is_refutable` for bindings
- add some TODO-s for cases, which can not be fixed easily

fixes #3780

changelog: fix FP on while-let-on-iterator for arrays and bindings

4 years agoChanged RANGE_FULL constant in utils
CrazyRoka [Sat, 2 May 2020 14:36:26 +0000 (17:36 +0300)]
Changed RANGE_FULL constant in utils