]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agoRollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper
Yuki Okushi [Thu, 17 Dec 2020 02:43:55 +0000 (11:43 +0900)]
Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper

Implement if-let match guards

Implements rust-lang/rfcs#2294 (tracking issue: #51114).

I probably should do a few more things before this can be merged:
- [x] Add tests (added basic tests, more advanced tests could be done in the future?)
- [x] Add lint for exhaustive if-let guard (comparable to normal if-let statements)
- [x] Fix clippy

However since this is a nightly feature maybe it's fine to land this and do those steps in follow-up PRs.

Thanks a lot `@matthewjasper` :heart: for helping me with lowering to MIR! Would you be interested in reviewing this?
r? `@ghost` for now

3 years agoAuto merge of #78399 - vn-ki:gsgdt-graphviz, r=oli-obk
bors [Tue, 15 Dec 2020 22:00:02 +0000 (22:00 +0000)]
Auto merge of #78399 - vn-ki:gsgdt-graphviz, r=oli-obk

make MIR graphviz generation use gsgdt

gsgdt [https://crates.io/crates/gsgdt] is a crate which provides an
interface for stringly typed graphs. It also provides generation of
graphviz dot format from said graph.

This is the first in a series of PRs on moving graphviz code out of rustc into normal crates and then implementating graph diffing on top of these crates.

r? `@oli-obk`

3 years agoConvenience funcs for `some_option.unwrap_or(...)`
Rich Kadel [Mon, 14 Dec 2020 21:12:15 +0000 (13:12 -0800)]
Convenience funcs for `some_option.unwrap_or(...)`

This ensures consistent handling of default values for options that are
None if not specified on the command line.

3 years agoImprove warnings on incompatible options involving -Zinstrument-coverage
Rich Kadel [Mon, 14 Dec 2020 08:25:29 +0000 (00:25 -0800)]
Improve warnings on incompatible options involving -Zinstrument-coverage

Adds checks for:

* `no_core` attribute
* explicitly-enabled `legacy` symbol mangling
* mir_opt_level > 1 (which enables inlining)

I removed code from the `Inline` MIR pass that forcibly disabled
inlining if `-Zinstrument-coverage` was set. The default `mir_opt_level`
does not enable inlining anyway. But if the level is explicitly set and
is greater than 1, I issue a warning.

The new warnings show up in tests, which is much better for diagnosing
potential option conflicts in these cases.

3 years agoMove binder for dyn to each list item
Jack Huey [Fri, 11 Dec 2020 20:02:46 +0000 (15:02 -0500)]
Move binder for dyn to each list item

3 years agoRetain assembly operands span when lowering AST to HIR
Tomasz Miąsko [Fri, 27 Nov 2020 00:00:00 +0000 (00:00 +0000)]
Retain assembly operands span when lowering AST to HIR

3 years agoMerge commit 'c1664c50b27a51f7a78c93ba65558e7c33eabee6' into clippyup
flip1995 [Sun, 6 Dec 2020 14:01:03 +0000 (15:01 +0100)]
Merge commit 'c1664c50b27a51f7a78c93ba65558e7c33eabee6' into clippyup

3 years agoHandle `Guard::IfLet` in clippy
LeSeulArtichaut [Sun, 15 Nov 2020 21:51:02 +0000 (22:51 +0100)]
Handle `Guard::IfLet` in clippy

3 years agoImplement lowering of if-let guards to MIR
LeSeulArtichaut [Fri, 13 Nov 2020 17:27:27 +0000 (18:27 +0100)]
Implement lowering of if-let guards to MIR

3 years agofix clippy test
Vishnunarayan K I [Sat, 5 Dec 2020 14:51:21 +0000 (20:21 +0530)]
fix clippy test

3 years agoAuto merge of #79329 - camelid:int-lit-suffix-error, r=davidtwco
bors [Mon, 30 Nov 2020 01:42:14 +0000 (01:42 +0000)]
Auto merge of #79329 - camelid:int-lit-suffix-error, r=davidtwco

Update error to reflect that integer literals can have float suffixes

For example, `1` is parsed as an integer literal, but it can be turned
into a float with the suffix `f32`. Now the error calls them "numeric
literals" and notes that you can add a float suffix since they can be
either integers or floats.

3 years agoUpdate tests to remove old numeric constants
bstrie [Sat, 24 Oct 2020 23:21:40 +0000 (19:21 -0400)]
Update tests to remove old numeric constants

Part of #68490.

Care has been taken to leave the old consts where appropriate, for testing backcompat regressions, module shadowing, etc. The intrinsics docs were accidentally referring to some methods on f64 as std::f64, which I changed due to being contrary with how we normally disambiguate the shadow module from the primitive. In one other place I changed std::u8 to std::ops since it was just testing path handling in macros.

For places which have legitimate uses of the old consts, deprecated attributes have been optimistically inserted. Although currently unnecessary, they exist to emphasize to any future deprecation effort the necessity of these specific symbols and prevent them from being accidentally removed.

3 years agoUpdate error to reflect that integer literals can have float suffixes
Camelid [Sun, 22 Nov 2020 22:29:46 +0000 (14:29 -0800)]
Update error to reflect that integer literals can have float suffixes

For example, `1` is parsed as an integer literal, but it can be turned
into a float with the suffix `f32`. Now the error calls them "numeric
literals" and notes that you can add a float suffix since they can be
either integers or floats.

3 years agoAuto merge of #79318 - cjgillot:fitem, r=lcnr
bors [Fri, 27 Nov 2020 13:45:22 +0000 (13:45 +0000)]
Auto merge of #79318 - cjgillot:fitem, r=lcnr

Store HIR ForeignItem in a side table

In a similar fashion to Item, ImplItem and TraitItem.

3 years agoRemove ForeignMod struct.
Camille GILLOT [Wed, 11 Nov 2020 21:40:09 +0000 (22:40 +0100)]
Remove ForeignMod struct.

3 years agoAuto merge of #77671 - flip1995:lint_list_always_plugins, r=oli-obk,Manishearth
bors [Thu, 26 Nov 2020 18:51:45 +0000 (18:51 +0000)]
Auto merge of #77671 - flip1995:lint_list_always_plugins, r=oli-obk,Manishearth

Always print lints from plugins, if they're available

Currently you can get a list of lints and lint groups by running `rustc
-Whelp`. This prints an additional line at the end:
```
Compiler plugins can provide additional lints and lint groups. To see a listing of these, re-run `rustc -W help` with a crate filename.
```

Clippy is such a "compiler plugin", that provides additional lints.
Running `clippy-driver -Whelp` (`rustc` wrapper) still only prints the
rustc lints with the above message at the end. But when running
`clippy-driver -Whelp main.rs`, where `main.rs` is any rust file, it
also prints Clippy lints. I don't think this is a good approach from a
UX perspective: Why is a random file necessary to print a help message?

This PR changes this behavior: Whenever a compiler callback
registers lints, it is assumed that these lints come from a plugin and
are printed without having to specify a Rust source file.

Fixes rust-lang/rust-clippy#6122

cc `@Manishearth` `@ebroto` for the Clippy changes.

3 years agoMove lev_distance to rustc_ast, make non-generic
Arlie Davis [Thu, 12 Nov 2020 19:24:10 +0000 (11:24 -0800)]
Move lev_distance to rustc_ast, make non-generic

rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing unnecessarily
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated at nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.

3 years agoclippy: Remove now obsolete lintlist module
flip1995 [Wed, 7 Oct 2020 14:05:13 +0000 (16:05 +0200)]
clippy: Remove now obsolete lintlist module

Also stop updating the lintlist module in clippy_dev update_lints

3 years agoclippy: Let rustc handle describing lints
flip1995 [Wed, 7 Oct 2020 14:04:22 +0000 (16:04 +0200)]
clippy: Let rustc handle describing lints

3 years agoAuto merge of #79228 - flip1995:clippyup, r=oli-obk
bors [Tue, 24 Nov 2020 06:56:02 +0000 (06:56 +0000)]
Auto merge of #79228 - flip1995:clippyup, r=oli-obk

Update Clippy

Biweekly Clippy update

r? `@Manishearth`

3 years agoAuto merge of #78343 - camelid:macros-qualify-panic, r=m-ou-se
bors [Mon, 23 Nov 2020 22:05:28 +0000 (22:05 +0000)]
Auto merge of #78343 - camelid:macros-qualify-panic, r=m-ou-se

Qualify `panic!` as `core::panic!` in non-built-in `core` macros

Fixes #78333.

-----

Otherwise code like this

    #![no_implicit_prelude]

    fn main() {
        ::std::todo!();
        ::std::unimplemented!();
    }

will fail to compile, which is unfortunate and presumably unintended.

This changes many invocations of `panic!` in a `macro_rules!` definition
to invocations of `$crate::panic!`, which makes the invocations hygienic.

Note that this does not make the built-in macro `assert!` hygienic.

3 years agoQualify `panic!` as `core::panic!` in non-built-in `core` macros
Camelid [Sun, 25 Oct 2020 01:35:46 +0000 (18:35 -0700)]
Qualify `panic!` as `core::panic!` in non-built-in `core` macros

Otherwise code like this

    #![no_implicit_prelude]

    fn main() {
        ::std::todo!();
        ::std::unimplemented!();
    }

will fail to compile, which is unfortunate and presumably unintended.

This changes many invocations of `panic!` in a `macro_rules!` definition
to invocations of `$crate::panic!`, which makes the invocations hygienic.

Note that this does not make the built-in macro `assert!` hygienic.

3 years agoAuto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrum
bors [Mon, 23 Nov 2020 19:01:19 +0000 (19:01 +0000)]
Auto merge of #78439 - lzutao:rm-clouldabi, r=Mark-Simulacrum

Drop support for all cloudabi targets

`cloudabi` is a tier-3 target, and [it is no longer being maintained upstream][no].

This PR drops supports for cloudabi targets. Those targets are:
* aarch64-unknown-cloudabi
* armv7-unknown-cloudabi
* i686-unknown-cloudabi
* x86_64-unknown-cloudabi

Since this drops supports for a target, I'd like somebody to tag `relnotes` label to this PR.

Some other issues:
* The tidy exception for `cloudabi` crate is still remained because
  * `parking_lot v0.9.0` and `parking_lot v0.10.2` depends on `cloudabi v0.0.3`.
  * `parking_lot v0.11.0` depends on `cloudabi v0.1.0`.

[no]: https://github.com/NuxiNL/cloudabi#note-this-project-is-unmaintained

3 years agoFix ICE in utils::implements_trait
flip1995 [Mon, 23 Nov 2020 12:52:27 +0000 (13:52 +0100)]
Fix ICE in utils::implements_trait

This only happend when debug_assertions were enabled in rustc

3 years agoMerge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
flip1995 [Mon, 23 Nov 2020 12:51:04 +0000 (13:51 +0100)]
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup

3 years agoDrop support for cloudabi targets
Lzu Tao [Tue, 27 Oct 2020 13:10:31 +0000 (13:10 +0000)]
Drop support for cloudabi targets

3 years agoThread `Constness` through selection
Jonas Schievink [Sun, 22 Nov 2020 01:13:53 +0000 (02:13 +0100)]
Thread `Constness` through selection

3 years agoClippy: Match on assert!() expansions without an inner block.
Mara Bos [Thu, 19 Nov 2020 18:47:25 +0000 (19:47 +0100)]
Clippy: Match on assert!() expansions without an inner block.

3 years agoRemove the clippy::panic-params lint.
Mara Bos [Thu, 19 Nov 2020 17:13:32 +0000 (18:13 +0100)]
Remove the clippy::panic-params lint.

Rustc itself now warns for all cases that triggered this lint.

3 years agoRollup merge of #79145 - camelid:clippy-fix-panics, r=flip1995
Mara Bos [Wed, 18 Nov 2020 14:46:36 +0000 (15:46 +0100)]
Rollup merge of #79145 - camelid:clippy-fix-panics, r=flip1995

Fix handling of panic calls

This should make Clippy more resilient and will unblock #78343.

This PR is made against rust-lang/rust to avoid the need for a subtree
sync at ``@flip1995's`` suggestion in rust-lang/rust-clippy#6310.

r? ``@flip1995``
cc ``@m-ou-se``

3 years agoFix handling of panic calls
Camelid [Tue, 17 Nov 2020 20:16:15 +0000 (12:16 -0800)]
Fix handling of panic calls

This should make Clippy more resilient and will unblock #78343.

This PR is made against rust-lang/rust to avoid the need for a subtree
sync at @flip1995's suggestion in rust-lang/rust-clippy#6310.

3 years agoAuto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk
bors [Tue, 17 Nov 2020 12:24:34 +0000 (12:24 +0000)]
Auto merge of #78779 - LeSeulArtichaut:ty-visitor-return, r=oli-obk

Introduce `TypeVisitor::BreakTy`

Implements MCP rust-lang/compiler-team#383.
r? `@ghost`
cc `@lcnr` `@oli-obk`

~~Blocked on FCP in rust-lang/compiler-team#383.~~

3 years agoclippy: fold by value
Bastian Kauschke [Sat, 24 Oct 2020 00:21:27 +0000 (02:21 +0200)]
clippy: fold by value

3 years agoRollup merge of #79016 - fanzier:underscore-expressions, r=petrochenkov
Jonas Schievink [Sun, 15 Nov 2020 12:39:48 +0000 (13:39 +0100)]
Rollup merge of #79016 - fanzier:underscore-expressions, r=petrochenkov

Make `_` an expression, to discard values in destructuring assignments

This is the third and final step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the third and final part of #71156, which was split up to allow for easier review.

With this PR, an underscore `_` is parsed as an expression but is allowed *only* on the left-hand side of a destructuring assignment. There it simply discards a value, similarly to the wildcard `_` in patterns. For instance,
```rust
(a, _) = (1, 2)
```
will simply assign 1 to `a` and discard the 2. Note that for consistency,
```
_ = foo
```
is also allowed and equivalent to just `foo`.

Thanks to ````@varkor```` who helped with the implementation, particularly around pre-expansion gating.

r? ````@petrochenkov````

3 years agoSet the default `BreakTy` to `!`
LeSeulArtichaut [Sat, 14 Nov 2020 20:46:39 +0000 (21:46 +0100)]
Set the default `BreakTy` to `!`

3 years agoIntroduce `TypeVisitor::BreakTy`
LeSeulArtichaut [Thu, 5 Nov 2020 16:30:39 +0000 (17:30 +0100)]
Introduce `TypeVisitor::BreakTy`

3 years agoAuto merge of #78809 - vn-ki:fix-issue-76064, r=oli-obk
bors [Sat, 14 Nov 2020 18:03:17 +0000 (18:03 +0000)]
Auto merge of #78809 - vn-ki:fix-issue-76064, r=oli-obk

add error_occured field to ConstQualifs,

fix #76064

I wasn't sure what `in_return_place` actually did and not sure why it returns `ConstQualifs` while it's sibling functions return `bool`. So I tried to make as minimal changes to the structure as possible. Please point out whether I have to refactor it or not.

r? `@oli-obk`
cc `@RalfJung`

3 years agoAdd underscore expressions for destructuring assignments
Fabian Zaiser [Wed, 11 Nov 2020 13:15:15 +0000 (13:15 +0000)]
Add underscore expressions for destructuring assignments

Co-authored-by: varkor <github@varkor.com>
3 years agoupdate clippy test ouput
Vishnunarayan K I [Fri, 13 Nov 2020 11:41:13 +0000 (17:11 +0530)]
update clippy test ouput

3 years agoRollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=petrochenkov
Mara Bos [Thu, 12 Nov 2020 18:46:09 +0000 (19:46 +0100)]
Rollup merge of #78836 - fanzier:struct-and-slice-destructuring, r=petrochenkov

Implement destructuring assignment for structs and slices

This is the second step towards implementing destructuring assignment (RFC: rust-lang/rfcs#2909, tracking issue: #71126). This PR is the second part of #71156, which was split up to allow for easier review.

Note that the first PR (#78748) is not merged yet, so it is included as the first commit in this one. I thought this would allow the review to start earlier because I have some time this weekend to respond to reviews. If ``@petrochenkov`` prefers to wait until the first PR is merged, I totally understand, of course.

This PR implements destructuring assignment for (tuple) structs and slices. In order to do this, the following *parser change* was necessary: struct expressions are not required to have a base expression, i.e. `Struct { a: 1, .. }` becomes legal (in order to act like a struct pattern).

Unfortunately, this PR slightly regresses the diagnostics implemented in #77283. However, it is only a missing help message in `src/test/ui/issues/issue-77218.rs`. Other instances of this diagnostic are not affected. Since I don't exactly understand how this help message works and how to fix it yet, I was hoping it's OK to regress this temporarily and fix it in a follow-up PR.

Thanks to ``@varkor`` who helped with the implementation, particularly around the struct rest changes.

r? ``@petrochenkov``

3 years agoAuto merge of #78782 - petrochenkov:nodoctok, r=Aaron1011
bors [Thu, 12 Nov 2020 00:33:55 +0000 (00:33 +0000)]
Auto merge of #78782 - petrochenkov:nodoctok, r=Aaron1011

Do not collect tokens for doc comments

Doc comment is a single token and AST has all the information to re-create it precisely.
Doc comments are also responsible for majority of calls to `collect_tokens` (with `num_calls == 1` and `num_calls == 0`, cc https://github.com/rust-lang/rust/pull/78736).

(I also moved token collection into `fn parse_attribute` to deduplicate code a bit.)

r? `@Aaron1011`

3 years agoImplement destructuring assignment for structs and slices
Fabian Zaiser [Sat, 7 Nov 2020 14:28:55 +0000 (14:28 +0000)]
Implement destructuring assignment for structs and slices

Co-authored-by: varkor <github@varkor.com>
3 years agoFix typo in comment
Ikko Ashimine [Wed, 11 Nov 2020 11:23:08 +0000 (20:23 +0900)]
Fix typo in comment

occurences -> occurrences

3 years agoRollup merge of #78710 - petrochenkov:macvisit, r=davidtwco
Dylan DPC [Mon, 9 Nov 2020 18:06:55 +0000 (19:06 +0100)]
Rollup merge of #78710 - petrochenkov:macvisit, r=davidtwco

rustc_ast: Do not panic by default when visiting macro calls

Panicking by default made sense when we didn't have HIR or MIR and everything worked on AST, but now all AST visitors run early and majority of them have to deal with macro calls, often by ignoring them.

The second commit renames `visit_mac` to `visit_mac_call`, the corresponding structures were renamed earlier in https://github.com/rust-lang/rust/pull/69589.

3 years agoDo not collect tokens for doc comments
Vadim Petrochenkov [Thu, 5 Nov 2020 17:27:48 +0000 (20:27 +0300)]
Do not collect tokens for doc comments

3 years agoMerge commit 'b20d4c155d2fe3a8391f86dcf9a8c49e17188703' into clippyup
flip1995 [Thu, 5 Nov 2020 13:29:48 +0000 (14:29 +0100)]
Merge commit 'b20d4c155d2fe3a8391f86dcf9a8c49e17188703' into clippyup

3 years agoAuto merge of #78662 - sexxi-goose:add_expr_id_to_delegate, r=nikomatsakis
bors [Wed, 4 Nov 2020 22:45:15 +0000 (22:45 +0000)]
Auto merge of #78662 - sexxi-goose:add_expr_id_to_delegate, r=nikomatsakis

Provide diagnostic suggestion in ExprUseVisitor Delegate

The [Delegate trait](https://github.com/rust-lang/rust/blob/981346fc07dd5ef414c5b1b21999f7604cece006/compiler/rustc_typeck/src/expr_use_visitor.rs#L28-L38) currently use `PlaceWithHirId` which is composed of Hir `Place` and the
corresponding expression id.

Even though this is an accurate way of expressing how a Place is used,
it can cause confusion during diagnostics.

Eg:

```
let arr : [String; 5];

let [a, ...]     =   arr;
 ^^^ E1 ^^^      =  ^^E2^^
 ```

 Here `arr` is moved because of the binding created E1. However, when we
 point to E1 in diagnostics with the message `arr` was moved, it can be
 confusing.  Rather we would like to report E2 to the user.

Closes: https://github.com/rust-lang/project-rfc-2229/issues/20
r? `@ghost`

3 years agos/Scalar::Raw/Scalar::Int
oli [Sun, 1 Nov 2020 16:57:03 +0000 (16:57 +0000)]
s/Scalar::Raw/Scalar::Int

3 years agoSplit the "raw integer bytes" part out of `Scalar`
Oliver Scherer [Sat, 26 Sep 2020 13:15:35 +0000 (15:15 +0200)]
Split the "raw integer bytes" part out of `Scalar`

3 years agorustc_ast: `visit_mac` -> `visit_mac_call`
Vadim Petrochenkov [Tue, 3 Nov 2020 17:34:57 +0000 (20:34 +0300)]
rustc_ast: `visit_mac` -> `visit_mac_call`

3 years agorustc_ast: Do not panic by default when visiting macro calls
Vadim Petrochenkov [Tue, 3 Nov 2020 17:26:17 +0000 (20:26 +0300)]
rustc_ast: Do not panic by default when visiting macro calls

3 years agoProvide diagnostic suggestion in ExprUseVisitor Delegate
Dhruv Jauhar [Sun, 1 Nov 2020 07:15:22 +0000 (02:15 -0500)]
Provide diagnostic suggestion in ExprUseVisitor Delegate

The [Delegate
trait](https://github.com/rust-lang/rust/blob/981346fc07dd5ef414c5b1b21999f7604cece006/compiler/rustc_typeck/src/expr_use_visitor.rs#L28-L38)
currently use `PlaceWithHirId` which is composed of Hir `Place` and the
corresponding expression id.

Even though this is an accurate way of expressing how a Place is used,
it can cause confusion during diagnostics.

Eg:

```
let arr : [String; 5];

let [a, ...]     =   arr;
 ^^^ E1 ^^^      =  ^^E2^^
 ```

 Here `arr` is moved because of the binding created E1. However, when we
 point to E1 in diagnostics with the message `arr` was moved, it can be
 confusing.  Rather we would like to report E2 to the user.

Closes: https://github.com/rust-lang/project-rfc-2229/issues/20
3 years agoAuto merge of #75534 - Aaron1011:feature/new-future-breakage, r=pnkfelix
bors [Sun, 1 Nov 2020 16:52:28 +0000 (16:52 +0000)]
Auto merge of #75534 - Aaron1011:feature/new-future-breakage, r=pnkfelix

Implement rustc side of report-future-incompat

cc https://github.com/rust-lang/rust/issues/71249

This is an alternative to `@pnkfelix's` initial implementation in https://github.com/pnkfelix/rust/commits/prototype-rustc-side-of-report-future-incompat (mainly because I started working before seeing that branch :smile: ).

My approach outputs the entire original `Diagnostic`, in a way that is compatible with incremental compilation. This is not yet integrated with compiletest, but can be used manually by passing `-Z emit-future-incompat-report` to `rustc`.

Several changes are made to support this feature:
* The `librustc_session/lint` module is moved to a new crate `librustc_lint_defs` (name bikesheddable). This allows accessing lint definitions from `librustc_errors`.
* The `Lint` struct is extended with an `Option<FutureBreakage>`. When present, it indicates that we should display a lint in the future-compat report. `FutureBreakage` contains additional information that we may want to display in the report (currently, a `date` field indicating when the crate will stop compiling).
* A new variant `rustc_error::Level::Allow` is added. This is used when constructing a diagnostic for a future-breakage lint that is marked as allowed (via `#[allow]` or `--cap-lints`). This allows us to capture any future-breakage diagnostics in one place, while still discarding them before they are passed to the `Emitter`.
* `DiagnosticId::Lint` is extended with a `has_future_breakage` field, indicating whether or not the `Lint` has future breakage information (and should therefore show up in the report).
* `Session` is given access to the `LintStore` via a new `SessionLintStore` trait (since `librustc_session` cannot directly reference `LintStore` without a cyclic dependency). We use this to turn a string `DiagnosticId::Lint` back into a `Lint`, to retrieve the `FutureBreakage` data.

Currently, `FutureBreakage.date` is always set to `None`. However, this could potentially be interpreted by Cargo in the future.

I've enabled the future-breakage report for the `ARRAY_INTO_ITER` lint, which can be used to test out this PR. The intent is to use the field to allow Cargo to determine the date of future breakage (as described in [RFC 2834](https://github.com/rust-lang/rfcs/blob/master/text/2834-cargo-report-future-incompat.md)) without needing to parse the diagnostic itself.

cc `@pnkfelix`

3 years agoUpdate Clippy path to `Lint`
Aaron Hill [Sat, 31 Oct 2020 01:41:16 +0000 (21:41 -0400)]
Update Clippy path to `Lint`

3 years agoRemove implicit `Continue` type
LeSeulArtichaut [Sun, 25 Oct 2020 10:50:56 +0000 (11:50 +0100)]
Remove implicit `Continue` type

3 years agoUse `ControlFlow::is{break,continue}`
LeSeulArtichaut [Thu, 22 Oct 2020 08:20:24 +0000 (10:20 +0200)]
Use `ControlFlow::is{break,continue}`

3 years agoTypeVisitor: use `ControlFlow` in clippy
LeSeulArtichaut [Wed, 21 Oct 2020 12:27:32 +0000 (14:27 +0200)]
TypeVisitor: use `ControlFlow` in clippy

3 years agoMerge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup
Eduardo Broto [Wed, 28 Oct 2020 22:36:07 +0000 (23:36 +0100)]
Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup

3 years agoRemove lint from clippy
Nathan Whitaker [Tue, 22 Sep 2020 16:23:22 +0000 (12:23 -0400)]
Remove lint from clippy

3 years agoRollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov
Yuki Okushi [Sun, 25 Oct 2020 09:43:49 +0000 (18:43 +0900)]
Rollup merge of #78326 - Aaron1011:fix/min-stmt-lints, r=petrochenkov

Split out statement attributes changes from #78306

This is the same as PR https://github.com/rust-lang/rust/pull/78306, but `unused_doc_comments` is modified to explicitly ignore statement items (which preserves the current behavior).

This shouldn't have any user-visible effects, so it can be landed without lang team discussion.

---------
When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306

3 years agoFix inconsistencies in handling of inert attributes on statements
Aaron Hill [Fri, 23 Oct 2020 22:17:00 +0000 (18:17 -0400)]
Fix inconsistencies in handling of inert attributes on statements

When the 'early' and 'late' visitors visit an attribute target, they
activate any lint attributes (e.g. `#[allow]`) that apply to it.
This can affect warnings emitted on sibiling attributes. For example,
the following code does not produce an `unused_attributes` for
`#[inline]`, since the sibiling `#[allow(unused_attributes)]` suppressed
the warning.

```rust
trait Foo {
    #[allow(unused_attributes)] #[inline] fn first();
    #[inline] #[allow(unused_attributes)] fn second();
}
```

However, we do not do this for statements - instead, the lint attributes
only become active when we visit the struct nested inside `StmtKind`
(e.g. `Item`).

Currently, this is difficult to observe due to another issue - the
`HasAttrs` impl for `StmtKind` ignores attributes for `StmtKind::Item`.
As a result, the `unused_doc_comments` lint will never see attributes on
item statements.

This commit makes two interrelated fixes to the handling of inert
(non-proc-macro) attributes on statements:

* The `HasAttr` impl for `StmtKind` now returns attributes for
  `StmtKind::Item`, treating it just like every other `StmtKind`
  variant. The only place relying on the old behavior was macro
  which has been updated to explicitly ignore attributes on item
  statements. This allows the `unused_doc_comments` lint to fire for
  item statements.
* The `early` and `late` lint visitors now activate lint attributes when
  invoking the callback for `Stmt`. This ensures that a lint
  attribute (e.g. `#[allow(unused_doc_comments)]`) can be applied to
  sibiling attributes on an item statement.

For now, the `unused_doc_comments` lint is explicitly disabled on item
statements, which preserves the current behavior. The exact locatiosn
where this lint should fire are being discussed in PR #78306

3 years agoRemove duplicate import of `Target`
Eduardo Broto [Fri, 23 Oct 2020 21:45:37 +0000 (23:45 +0200)]
Remove duplicate import of `Target`

3 years agoMerge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup
Eduardo Broto [Fri, 23 Oct 2020 20:16:59 +0000 (22:16 +0200)]
Merge commit 'bf1c6f9871f430e284b17aa44059e0d0395e28a6' into clippyup

3 years agoFix clippy tests
varkor [Thu, 22 Oct 2020 12:23:14 +0000 (13:23 +0100)]
Fix clippy tests

3 years agoRollup merge of #77851 - exrook:split-btreemap, r=dtolnay
Yuki Okushi [Sat, 17 Oct 2020 19:11:07 +0000 (04:11 +0900)]
Rollup merge of #77851 - exrook:split-btreemap, r=dtolnay

BTreeMap: refactor Entry out of map.rs into its own file

btree/map.rs is approaching the 3000 line mark, splitting out the entry
code buys about 500 lines of headroom.

I've created this PR because the changes I've made in #77438 will push `map.rs` over the 3000 line limit and cause tidy to complain.

I picked `Entry` to factor out because it feels less tightly coupled to the rest of `BTreeMap` than the various iterator implementations.

Related: #60302

3 years agoAppease the almightly lord clippy, hallowed be thy name
Jacob Hughes [Sat, 17 Oct 2020 17:45:40 +0000 (13:45 -0400)]
Appease the almightly lord clippy, hallowed be thy name

3 years agoHandle ExprKind::ConstBlock on clippy
Santiago Pastorino [Tue, 6 Oct 2020 21:51:31 +0000 (18:51 -0300)]
Handle ExprKind::ConstBlock on clippy

3 years agoRollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_of_the_query_sta...
Dylan DPC [Fri, 16 Oct 2020 00:10:09 +0000 (02:10 +0200)]
Rollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_of_the_query_stack, r=oli-obk

ICEs should always print the top of the query stack

see #76920

3 years agoRemove rustc_session::config::Config
est31 [Wed, 14 Oct 2020 16:42:13 +0000 (18:42 +0200)]
Remove rustc_session::config::Config

The wrapper type led to tons of target.target
across the compiler. Its ptr_width field isn't
required any more, as target_pointer_width
is already present in parsed form.

3 years agofix stderr file of clippy/custom_ice_message test
hosseind88 [Wed, 14 Oct 2020 14:49:26 +0000 (18:19 +0330)]
fix stderr file of clippy/custom_ice_message test

3 years agoAuto merge of #77796 - jonas-schievink:switchint-refactor, r=oli-obk
bors [Tue, 13 Oct 2020 00:57:03 +0000 (00:57 +0000)]
Auto merge of #77796 - jonas-schievink:switchint-refactor, r=oli-obk

Refactor how SwitchInt stores jump targets

Closes https://github.com/rust-lang/rust/issues/65693

3 years agoAuto merge of #77649 - dash2507:replace_run_compiler, r=matthewjasper
bors [Sun, 11 Oct 2020 01:26:06 +0000 (01:26 +0000)]
Auto merge of #77649 - dash2507:replace_run_compiler, r=matthewjasper

Replace run_compiler with RunCompiler builder pattern

Fixes #77286. Replaces rustc_driver:run_compiler with RunCompiler builder pattern.

3 years agoRefactor how SwitchInt stores jump targets
Jonas Schievink [Sat, 10 Oct 2020 15:36:04 +0000 (17:36 +0200)]
Refactor how SwitchInt stores jump targets

3 years agorebase with master
hosseind75 [Tue, 29 Sep 2020 14:44:07 +0000 (18:14 +0330)]
rebase with master

3 years agoadd new line
hosseind75 [Mon, 28 Sep 2020 18:37:31 +0000 (22:07 +0330)]
add new line

3 years agofix clippy custom_ice_message test
hosseind75 [Fri, 25 Sep 2020 16:25:32 +0000 (19:55 +0330)]
fix clippy custom_ice_message test

3 years agorun full query stack print just when RUST_BACKTRACE is set
hosseind75 [Sat, 19 Sep 2020 14:07:58 +0000 (18:37 +0430)]
run full query stack print just when RUST_BACKTRACE is set

3 years agoICEs should print the top of the query stack
hosseind75 [Sat, 19 Sep 2020 13:21:24 +0000 (17:51 +0430)]
ICEs should print the top of the query stack

3 years agoMerge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup
flip1995 [Fri, 9 Oct 2020 10:45:29 +0000 (12:45 +0200)]
Merge commit '2f6439ae6a6803d030cceb3ee14c9150e91b328b' into clippyup

3 years agoReplace run_compiler with RunCompiler builder pattern.
Darshan Kathiriya [Wed, 7 Oct 2020 12:09:59 +0000 (09:09 -0300)]
Replace run_compiler with RunCompiler builder pattern.
RunCompiler::new takes non-optional params, and optional
params can be set using set_*field_name* method.
finally `run` will forward all fields to `run_compiler`.

3 years agoFix tools
Matthew Jasper [Tue, 30 Jun 2020 21:41:57 +0000 (22:41 +0100)]
Fix tools

3 years agoRollup merge of #77560 - rschoon:fix-litkind-rc-bytebuf, r=lcnr
Yuki Okushi [Tue, 6 Oct 2020 07:26:11 +0000 (16:26 +0900)]
Rollup merge of #77560 - rschoon:fix-litkind-rc-bytebuf, r=lcnr

Fix LitKind's byte buffer to use refcounted slice

While working on adding a new lint for clippy (see https://github.com/rust-lang/rust-clippy/pull/6044) for avoiding shared ownership of "mutable buffer" types (such as using `Rc<Vec<T>>` instead of `Rc<[T]>`), I noticed a type exported from rustc_ast and used by clippy gets caught by the lint. This PR fixes the exported type.

This PR includes the actual change to clippy too, but I will open a PR directly against clippy for that part (although it will currently fail to build there).

3 years agoRollup merge of #77534 - Mark-Simulacrum:issue-70819-disallow-override-forbid-in...
Yuki Okushi [Tue, 6 Oct 2020 07:26:04 +0000 (16:26 +0900)]
Rollup merge of #77534 - Mark-Simulacrum:issue-70819-disallow-override-forbid-in-same-scope, r=petrochenkov

Disallow overriding forbid in same scope

Rebased #73379.

Fixes #70819.

3 years agoclippy: `(Body, DefId)` -> `Body`
Dylan MacKenzie [Sun, 4 Oct 2020 22:23:20 +0000 (15:23 -0700)]
clippy: `(Body, DefId)` -> `Body`

3 years agoChange clippy's Constant back to refcount clone byte strings
Robin Schoonover [Sun, 4 Oct 2020 21:53:37 +0000 (15:53 -0600)]
Change clippy's Constant back to refcount clone byte strings

3 years agoPrevent forbid from being ignored if overriden at the same level.
Felix S. Klock II [Mon, 15 Jun 2020 18:17:35 +0000 (14:17 -0400)]
Prevent forbid from being ignored if overriden at the same level.

That is, this changes `#[forbid(foo)] #[allow(foo)]` from allowing foo to
forbidding foo.

3 years agoDeprecate clippy lint
Michael Howell [Fri, 2 Oct 2020 18:34:14 +0000 (11:34 -0700)]
Deprecate clippy lint

3 years agoRollup merge of #76474 - bjorn3:driver_selected_codegen, r=oli-obk
Ralf Jung [Mon, 28 Sep 2020 16:39:40 +0000 (18:39 +0200)]
Rollup merge of #76474 - bjorn3:driver_selected_codegen, r=oli-obk

Add option to pass a custom codegen backend from a driver

This allows the driver to pass information to the codegen backend. For example the headcrab debugger may in the future want to use cg_clif to JIT code to be injected in the debuggee. This would PR make it possible to tell cg_clif which symbol can be found at which address and to tell it to inject the JITed code into the right process.

This PR may also help with https://github.com/rust-lang/miri/pull/1540 by allowing miri to provide a codegen backend that only emits metadata and doesn't perform any codegen.

cc @nbaksalyar (headcrab)
cc @RalfJung (miri)

3 years agoAdd option to pass a custom codegen backend from a driver
bjorn3 [Tue, 8 Sep 2020 11:44:41 +0000 (13:44 +0200)]
Add option to pass a custom codegen backend from a driver

3 years agoRemove all unstable feature support in the `missing_const_for_fn` lint
Oliver Scherer [Sat, 26 Sep 2020 14:23:56 +0000 (16:23 +0200)]
Remove all unstable feature support in the `missing_const_for_fn` lint

3 years agoMove `qualify_min_const_fn` out of rustc into clippy
Oliver Scherer [Sat, 26 Sep 2020 14:08:24 +0000 (16:08 +0200)]
Move `qualify_min_const_fn` out of rustc into clippy

3 years agoAuto merge of #77144 - flip1995:clippyup, r=Manishearth
bors [Fri, 25 Sep 2020 06:23:55 +0000 (06:23 +0000)]
Auto merge of #77144 - flip1995:clippyup, r=Manishearth

Update Clippy

Bi-weekly Clippy update.

This includes a `Cargo.lock` update (d445493479711389f4dea3a0f433041077ba2088), so probably needs `rollup=never`.

r? `@Manishearth`

3 years agoRollup merge of #76724 - ecstatic-morse:dataflow-pass-names, r=lcnr
Jonas Schievink [Fri, 25 Sep 2020 00:29:31 +0000 (02:29 +0200)]
Rollup merge of #76724 - ecstatic-morse:dataflow-pass-names, r=lcnr

Allow a unique name to be assigned to dataflow graphviz output

Previously, if the same analysis were invoked multiple times in a single compilation session, the graphviz output for later runs would overwrite that of previous runs. Allow callers to add a unique identifier to each run so this can be avoided.

3 years agoMerge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup
flip1995 [Thu, 24 Sep 2020 12:49:22 +0000 (14:49 +0200)]
Merge commit 'e636b88aa180e8cab9e28802aac90adbc984234d' into clippyup

3 years agoRemove `can_suggest` from Clippy.
Christiaan Dirkx [Sun, 20 Sep 2020 22:00:33 +0000 (00:00 +0200)]
Remove `can_suggest` from Clippy.

Removes `can_suggest` from as it is no longer used.
Reverts rust-clippy#5724.

3 years agoUpdate Clippy testcases
Christiaan Dirkx [Sun, 20 Sep 2020 21:59:34 +0000 (23:59 +0200)]
Update Clippy testcases

Update the test `redundant_pattern_matching`: check if `is_some` and `is_none` are suggested within const contexts.

3 years agoAuto merge of #76136 - CDirkx:const-result, r=dtolnay
bors [Sun, 20 Sep 2020 13:07:11 +0000 (13:07 +0000)]
Auto merge of #76136 - CDirkx:const-result, r=dtolnay

Stabilize some Result methods as const

Stabilize the following methods of Result as const:
 - `is_ok`
 - `is_err`
 - `as_ref`

A test is also included, analogous to the test for `const_option`.

These methods are currently const under the unstable feature `const_result` (tracking issue: #67520).
I believe these methods to be eligible for stabilization because of the stabilization of #49146 (Allow if and match in constants) and the trivial implementations, see also: [PR#75463](https://github.com/rust-lang/rust/pull/75463) and [PR#76135](https://github.com/rust-lang/rust/pull/76135).

Note: these methods are the only methods currently under the `const_result` feature, thus this PR results in the removal of the feature.

Related: #76225

3 years agoUpdate src/tools/clippy/clippy_lints/src/matches.rs
CDirkx [Sun, 20 Sep 2020 10:21:23 +0000 (12:21 +0200)]
Update src/tools/clippy/clippy_lints/src/matches.rs

Co-authored-by: Ralf Jung <post@ralfj.de>
3 years agoRemove `can_suggest` check for `is_ok` and `is_err`.
Christiaan Dirkx [Sun, 20 Sep 2020 08:46:30 +0000 (10:46 +0200)]
Remove `can_suggest` check for `is_ok` and `is_err`.

`is_ok` and `is_err` are stabilized as const and can thus always be suggested.

3 years agoUpdate Clippy testcases
Christiaan Dirkx [Sun, 20 Sep 2020 01:32:36 +0000 (03:32 +0200)]
Update Clippy testcases

Update the test `redundant_pattern_matching`: check if `is_ok` and `is_err` are suggested within const contexts.
Also removes the `redundant_pattern_matching_const_result` test, as it is no longer needed.