]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agobless clippy tests
klensy [Wed, 15 Jun 2022 11:15:54 +0000 (14:15 +0300)]
bless clippy tests

2 years agoRollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011
Yuki Okushi [Wed, 15 Jun 2022 10:37:14 +0000 (19:37 +0900)]
Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011

Make `ExprKind::Closure` a struct variant.

Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`.

r? ``@Aaron1011``

2 years agofix wrong evaluation in clippy
b-naber [Fri, 3 Jun 2022 19:41:01 +0000 (21:41 +0200)]
fix wrong evaluation in clippy

2 years agoaddress review
b-naber [Fri, 3 Jun 2022 18:42:35 +0000 (20:42 +0200)]
address review

2 years agofix clippy test failures
b-naber [Thu, 2 Jun 2022 13:15:01 +0000 (15:15 +0200)]
fix clippy test failures

2 years agoimplement valtrees as the type-system representation for constant values
b-naber [Wed, 16 Feb 2022 09:56:01 +0000 (10:56 +0100)]
implement valtrees as the type-system representation for constant values

2 years agoRename the `ConstS::val` field as `kind`.
Nicholas Nethercote [Fri, 10 Jun 2022 01:18:06 +0000 (11:18 +1000)]
Rename the `ConstS::val` field as `kind`.

And likewise for the `Const::val` method.

Because its type is called `ConstKind`. Also `val` is a confusing name
because `ConstKind` is an enum with seven variants, one of which is
called `Value`. Also, this gives consistency with `TyS` and `PredicateS`
which have `kind` fields.

The commit also renames a few `Const` variables from `val` to `c`, to
avoid confusion with the `ConstKind::Value` variant.

2 years agoremove unnecessary `to_string` and `String::new` for `tool_only_span_suggestion`
Takayuki Maeda [Mon, 13 Jun 2022 07:01:16 +0000 (16:01 +0900)]
remove unnecessary `to_string` and `String::new` for `tool_only_span_suggestion`

2 years agoremove unnecessary `to_string` and `String::new`
Takayuki Maeda [Mon, 13 Jun 2022 06:48:40 +0000 (15:48 +0900)]
remove unnecessary `to_string` and `String::new`

2 years agoMake `ExprKind::Closure` a struct variant.
Camille GILLOT [Sat, 11 Jun 2022 19:25:25 +0000 (21:25 +0200)]
Make `ExprKind::Closure` a struct variant.

2 years agoFolding revamp.
Nicholas Nethercote [Thu, 2 Jun 2022 01:38:15 +0000 (11:38 +1000)]
Folding revamp.

This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.

2 years agoAuto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis
bors [Tue, 7 Jun 2022 05:04:14 +0000 (05:04 +0000)]
Auto merge of #95565 - jackh726:remove-borrowck-mode, r=nikomatsakis

Remove migrate borrowck mode

Closes #58781
Closes #43234

# Stabilization proposal

This PR proposes the stabilization of `#![feature(nll)]` and the removal of `-Z borrowck`. Current borrow checking behavior of item bodies is currently done by first infering regions *lexically* and reporting any errors during HIR type checking. If there *are* any errors, then MIR borrowck (NLL) never occurs. If there *aren't* any errors, then MIR borrowck happens and any errors there would be reported. This PR removes the lexical region check of item bodies entirely and only uses MIR borrowck. Because MIR borrowck could never *not* be run for a compiled program, this should not break any programs. It does, however, change diagnostics significantly and allows a slightly larger set of programs to compile.

Tracking issue: #43234
RFC: https://github.com/rust-lang/rfcs/blob/master/text/2094-nll.md
Version: 1.63 (2022-06-30 => beta, 2022-08-11 => stable).

## Motivation

Over time, the Rust borrow checker has become "smarter" and thus allowed more programs to compile. There have been three different implementations: AST borrowck, MIR borrowck, and polonius (well, in progress). Additionally, there is the "lexical region resolver", which (roughly) solves the constraints generated through HIR typeck. It is not a full borrow checker, but does emit some errors.

The AST borrowck was the original implementation of the borrow checker and was part of the initially stabilized Rust 1.0. In mid 2017, work began to implement the current MIR borrow checker and that effort ompleted by the end of 2017, for the most part. During 2018, efforts were made to migrate away from the AST borrow checker to the MIR borrow checker - eventually culminating into "migrate" mode - where HIR typeck with lexical region resolving following by MIR borrow checking - being active by default in the 2018 edition.

In early 2019, migrate mode was turned on by default in the 2015 edition as well, but with MIR borrowck errors emitted as warnings. By late 2019, these warnings were upgraded to full errors. This was followed by the complete removal of the AST borrow checker.

In the period since, various errors emitted by the MIR borrow checker have been improved to the point that they are mostly the same or better than those emitted by the lexical region resolver.

While there do remain some degradations in errors (tracked under the [NLL-diagnostics tag](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-diagnostics), those are sufficiently small and rare enough that increased flexibility of MIR borrow check-only is now a worthwhile tradeoff.

## What is stabilized

As said previously, this does not fundamentally change the landscape of accepted programs. However, there are a [few](https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3ANLL-fixed-by-NLL) cases where programs can compile under `feature(nll)`, but not otherwise.

There are two notable patterns that are "fixed" by this stabilization. First, the `scoped_threads` feature, which is a continutation of a pre-1.0 API, can sometimes emit a [weird lifetime error](https://github.com/rust-lang/rust/issues/95527) without NLL. Second, actually seen in the standard library. In the `Extend` impl for `HashMap`, there is an implied bound of `K: 'a` that is available with NLL on but not without - this is utilized in the impl.

As mentioned before, there are a large number of diagnostic differences. Most of them are better, but some are worse. None are serious or happen often enough to need to block this PR. The biggest change is the loss of error code for a number of lifetime errors in favor of more general "lifetime may not live long enough" error. While this may *seem* bad, the former error codes were just attempts to somewhat-arbitrarily bin together lifetime errors of the same type; however, on paper, they end up being roughly the same with roughly the same kinds of solutions.

## What isn't stabilized

This PR does not completely remove the lexical region resolver. In the future, it may be possible to remove that (while still keeping HIR typeck) or to remove it together with HIR typeck.

## Tests

Many test outputs get updated by this PR. However, there are number of tests specifically geared towards NLL under `src/test/ui/nll`

## History

* On 2017-07-14, [tracking issue opened](https://github.com/rust-lang/rust/issues/43234)
* On 2017-07-20, [initial empty MIR pass added](https://github.com/rust-lang/rust/pull/43271)
* On 2017-08-29, [RFC opened](https://github.com/rust-lang/rfcs/pull/2094)
* On 2017-11-16, [Integrate MIR type-checker with NLL](https://github.com/rust-lang/rust/pull/45825)
* On 2017-12-20, [NLL feature complete](https://github.com/rust-lang/rust/pull/46862)
* On 2018-07-07, [Don't run AST borrowck on mir mode](https://github.com/rust-lang/rust/pull/52083)
* On 2018-07-27, [Add migrate mode](https://github.com/rust-lang/rust/pull/52681)
* On 2019-04-22, [Enable migrate mode on 2015 edition](https://github.com/rust-lang/rust/pull/59114)
* On 2019-08-26, [Don't downgrade errors on 2015 edition](https://github.com/rust-lang/rust/pull/64221)
* On 2019-08-27, [Remove AST borrowck](https://github.com/rust-lang/rust/pull/64790)

2 years agoRollup merge of #97794 - eltociear:patch-13, r=matthiaskrgr
Matthias Krüger [Mon, 6 Jun 2022 23:13:48 +0000 (01:13 +0200)]
Rollup merge of #97794 - eltociear:patch-13, r=matthiaskrgr

Fix typo in redundant_pattern_match.rs

alway -> always

2 years agoFix typo in redundant_pattern_match.rs
Ikko Ashimine [Mon, 6 Jun 2022 12:16:31 +0000 (21:16 +0900)]
Fix typo in redundant_pattern_match.rs

alway -> always

2 years agoRemove unnecessary clap_derive dependency added in 9ee211af
Philipp Krones [Sat, 4 Jun 2022 12:04:35 +0000 (14:04 +0200)]
Remove unnecessary clap_derive dependency added in 9ee211af

The fixed issue in this commit can be tested without depending on
clap/clap_derive. This updates the test case to do so.

2 years agoMerge commit 'd9ddce8a223cb9916389c039777b6966ea448dc8' into clippyup
Philipp Krones [Sat, 4 Jun 2022 11:34:07 +0000 (13:34 +0200)]
Merge commit 'd9ddce8a223cb9916389c039777b6966ea448dc8' into clippyup

2 years agoFully stabilize NLL
Jack Huey [Fri, 1 Apr 2022 17:13:25 +0000 (13:13 -0400)]
Fully stabilize NLL

2 years agoRollup merge of #97415 - cjgillot:is-late-bound-solo, r=estebank
Dylan DPC [Fri, 3 Jun 2022 15:10:51 +0000 (17:10 +0200)]
Rollup merge of #97415 - cjgillot:is-late-bound-solo, r=estebank

Compute `is_late_bound_map` query separately from lifetime resolution

This query is actually very simple, and is only useful for functions and method.  It can be computed directly by fetching the HIR, with no need to embed it within the lifetime resolution visitor.

Based on https://github.com/rust-lang/rust/pull/96296

2 years agoManipulate lifetimes by LocalDefId for region resolution.
Camille GILLOT [Wed, 27 Apr 2022 20:15:58 +0000 (22:15 +0200)]
Manipulate lifetimes by LocalDefId for region resolution.

2 years agoRollup merge of #97653 - RalfJung:int-to-ptr, r=oli-obk
Dylan DPC [Fri, 3 Jun 2022 09:18:24 +0000 (11:18 +0200)]
Rollup merge of #97653 - RalfJung:int-to-ptr, r=oli-obk

add cast kind of from_exposed_addr (int-to-ptr casts)

This is basically the dual to https://github.com/rust-lang/rust/pull/97582, for int2ptr casts.

Cc `@tmiasko` https://github.com/rust-lang/rust/issues/97649

2 years agoAuto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum
bors [Thu, 2 Jun 2022 18:45:29 +0000 (18:45 +0000)]
Auto merge of #97575 - nnethercote:lazify-SourceFile-lines, r=Mark-Simulacrum

Lazify `SourceFile::lines`.

`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `RefCell` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.

r? `@Mark-Simulacrum`

2 years agoadd cast kind of from_exposed_addr (int-to-ptr casts)
Ralf Jung [Thu, 2 Jun 2022 13:05:37 +0000 (09:05 -0400)]
add cast kind of from_exposed_addr (int-to-ptr casts)

2 years agorename PointerAddress → PointerExposeAddress
Ralf Jung [Wed, 1 Jun 2022 17:24:44 +0000 (13:24 -0400)]
rename PointerAddress → PointerExposeAddress

2 years agoLazify `SourceFile::lines`.
Nicholas Nethercote [Mon, 30 May 2022 05:59:45 +0000 (15:59 +1000)]
Lazify `SourceFile::lines`.

`SourceFile::lines` is a big part of metadata. It's stored in a compressed form
(a difference list) to save disk space. Decoding it is a big fraction of
compile time for very small crates/programs.

This commit introduces a new type `SourceFileLines` which has a `Lines`
form and a `Diffs` form. The latter is used when the metadata is first
read, and it is only decoded into the `Lines` form when line data is
actually needed. This avoids the decoding cost for many files,
especially in `std`. It's a performance win of up to 15% for tiny
crates/programs where metadata decoding is a high part of compilation
costs.

A `Lock` is needed because the methods that access lines data (which can
trigger decoding) take `&self` rather than `&mut self`. To allow for this,
`SourceFile::lines` now takes a `FnMut` that operates on the lines slice rather
than returning the lines slice.

2 years agoAdd a pointer to address cast kind
Tomasz Miąsko [Tue, 31 May 2022 00:00:00 +0000 (00:00 +0000)]
Add a pointer to address cast kind

A pointer to address cast are often special-cased.
Introduce a dedicated cast kind to make them easy distinguishable.

2 years agotry to cache region_scope_tree as a query
Ding Xiang Fei [Wed, 25 May 2022 05:52:32 +0000 (13:52 +0800)]
try to cache region_scope_tree as a query

2 years agoAuto merge of #96098 - JakobDegen:always-return-place, r=oli-obk
bors [Tue, 24 May 2022 07:13:26 +0000 (07:13 +0000)]
Auto merge of #96098 - JakobDegen:always-return-place, r=oli-obk

Refactor call terminator to always include destination place

In #71117 people seemed to agree that call terminators should always have a destination place, even if the call was guaranteed to diverge. This implements that. Unsurprisingly, the diff touches a lot of code, but thankfully I had to do almost nothing interesting. The only interesting thing came up in const prop, where the stack frame having no return place was also used to indicate that the layout could not be computed (or similar). I replaced this with a ZST allocation, which should continue to do the right things.

cc `@RalfJung` `@eddyb` who were involved in the original conversation

r? rust-lang/mir-opt

2 years agoRollup merge of #97289 - compiler-errors:tcxify-clippy, r=Mark-Simulacrum
Yuki Okushi [Tue, 24 May 2022 03:18:31 +0000 (12:18 +0900)]
Rollup merge of #97289 - compiler-errors:tcxify-clippy, r=Mark-Simulacrum

Lifetime variance fixes for clippy

#97287 migrates rustc to a `Ty` type that is invariant over its lifetime `'tcx`, so I need to fix a bunch of places that assume that `Ty<'a>` and `Ty<'b>` can be shortened to some common lifetime.

This is doable, since everything is already `'tcx`, so all this PR does is be a bit more explicit that elided lifetimes are actually `'tcx`.

Split out from #97287 so the clippy team can review independently.

2 years agoRefactor call terminator to always hold a destination place
Jakob Degen [Sat, 16 Apr 2022 13:27:54 +0000 (09:27 -0400)]
Refactor call terminator to always hold a destination place

2 years agoLifetime variance fixes for clippy
Michael Goulet [Mon, 23 May 2022 15:48:17 +0000 (08:48 -0700)]
Lifetime variance fixes for clippy

2 years agoRollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillot
Dylan DPC [Mon, 23 May 2022 05:43:50 +0000 (07:43 +0200)]
Rollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillot

Remove feature: `crate` visibility modifier

FCP completed in #53120.

2 years agoFix clippy explicit_write lint for new writeln implementation
David Tolnay [Mon, 23 May 2022 00:39:44 +0000 (17:39 -0700)]
Fix clippy explicit_write lint for new writeln implementation

2 years agofactor out the rvalue lifetime rule
Ding Xiang Fei [Fri, 1 Apr 2022 13:12:18 +0000 (21:12 +0800)]
factor out the rvalue lifetime rule

remove region_scope_tree from RegionCtxt

Apply suggestions from code review

Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2 years agoMerge crate and restricted visibilities
Jacob Pratt [Sat, 21 May 2022 18:45:14 +0000 (14:45 -0400)]
Merge crate and restricted visibilities

2 years agoRemove feature: `crate` visibility modifier
Jacob Pratt [Sat, 21 May 2022 17:53:26 +0000 (13:53 -0400)]
Remove feature: `crate` visibility modifier

2 years agoFix lint registration
xFrednet [Sat, 21 May 2022 11:50:11 +0000 (13:50 +0200)]
Fix lint registration

2 years agoMerge 'rust-clippy/master' into clippyup
xFrednet [Sat, 21 May 2022 11:24:00 +0000 (13:24 +0200)]
Merge 'rust-clippy/master' into clippyup

2 years agoAuto merge of #96923 - eholk:fix-fake-read, r=nikomatsakis
bors [Sat, 21 May 2022 04:21:38 +0000 (04:21 +0000)]
Auto merge of #96923 - eholk:fix-fake-read, r=nikomatsakis

Drop Tracking: Implement `fake_read` callback

This PR updates drop tracking's use of `ExprUseVisitor` so that we treat `fake_read` events as borrows. Without doing this, we were not handling match expressions correctly, which showed up as a breakage in the `addassign-yield.rs` test. We did not previously notice this because we still had rather large temporary scopes that we held borrows for, which changed in #94309.

This PR also includes a variant of the `addassign-yield.rs` test case to make sure we continue to have correct behavior here with drop tracking.

r? `@nikomatsakis`

2 years agoAuto merge of #96863 - SparrowLii:let, r=michaelwoerister
bors [Wed, 18 May 2022 17:48:46 +0000 (17:48 +0000)]
Auto merge of #96863 - SparrowLii:let, r=michaelwoerister

use `hir::Let` in `hir::Guard::IfLet`

This PR fixes the FIXME about using `hir::Let` in `hir::Guard::IfLet`

2 years agoAuto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor
bors [Tue, 17 May 2022 12:01:12 +0000 (12:01 +0000)]
Auto merge of #97111 - JohnTitor:rollup-x3vjf6u, r=JohnTitor

Rollup of 7 pull requests

Successful merges:

 - #96329 (Add a couple tests for #90887 fixes)
 - #97009 (Allow `unused_macro_rules` in path tests)
 - #97075 (Add regression test for #81804)
 - #97079 (Change `Successors` to `impl Iterator<Item = BasicBlock>`)
 - #97080 (remove the `RelateResultCompare` trait)
 - #97093 (Migrate `maybe_recover_from_bad_type_plus` diagnostic)
 - #97102 (Update function pointer call error message)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

2 years agoRollup merge of #97079 - SparrowLii:successors, r=lcnr
Yuki Okushi [Tue, 17 May 2022 10:01:32 +0000 (19:01 +0900)]
Rollup merge of #97079 - SparrowLii:successors, r=lcnr

Change `Successors` to `impl Iterator<Item = BasicBlock>`

This PR fixes the FIXME in `compiler\rustc_middle\src\mir\mod.rs`.
This can omit several `&`, `*` or `cloned` operations on Successros' generated elements

2 years agoAuto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwco
bors [Tue, 17 May 2022 09:39:26 +0000 (09:39 +0000)]
Auto merge of #97012 - oli-obk:🦀_intrinsics, r=davidtwco

Add a query for checking whether a function is an intrinsic.

work towards #93145

This will reduce churn when we add more ways to declare intrinsics

r? `@scottmcm`

2 years agoAuto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgillot
bors [Tue, 17 May 2022 06:51:45 +0000 (06:51 +0000)]
Auto merge of #96825 - kckeiks:remove-item-like-visitor-trait, r=cjgillot

 Retire `ItemLikeVisitor` trait

Issue #95004
cc `@cjgillot`

2 years agoChange `Successors` to `impl Iterator<Item = BasicBlock>`
SparrowLii [Tue, 17 May 2022 00:41:01 +0000 (08:41 +0800)]
Change `Successors` to `impl Iterator<Item = BasicBlock>`

2 years agoAdd a query for checking whether a function is an intrinsic.
Oli Scherer [Fri, 13 May 2022 13:50:21 +0000 (13:50 +0000)]
Add a query for checking whether a function is an intrinsic.

2 years agoAuto merge of #96883 - jackh726:early-binder-2, r=oli-obk
bors [Sat, 14 May 2022 23:53:11 +0000 (23:53 +0000)]
Auto merge of #96883 - jackh726:early-binder-2, r=oli-obk

Add EarlyBinder

Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L1308). Everything  is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk.

Either way, tracking when we have or haven't already substituted out these in rustc can be helpful.

As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted.

r? `@nikomatsakis`

2 years agoAdd bound_fn_sig
Jack Huey [Sun, 8 May 2022 19:43:18 +0000 (15:43 -0400)]
Add bound_fn_sig

2 years agoAdd bound_type_of
Jack Huey [Sun, 8 May 2022 19:12:56 +0000 (15:12 -0400)]
Add bound_type_of

2 years agoremove TestItemNamesVisitor
Miguel Guarniz [Sat, 7 May 2022 18:51:05 +0000 (14:51 -0400)]
remove TestItemNamesVisitor

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years agoAuto merge of #95562 - lcnr:attr-no-encode, r=davidtwco
bors [Thu, 12 May 2022 12:48:30 +0000 (12:48 +0000)]
Auto merge of #95562 - lcnr:attr-no-encode, r=davidtwco

don't encode only locally used attrs

Part of https://github.com/rust-lang/compiler-team/issues/505.

We now filter builtin attributes before encoding them in the crate metadata in case they should only be used in the local crate. To prevent accidental misuse `get_attrs` now requires the caller to state which attribute they are interested in. For places where that isn't trivially possible, I've added a method `fn get_attrs_unchecked` which I intend to remove in a followup PR.

After this pull request landed, we can then slowly move all attributes to only be used in the local crate while being certain that we don't accidentally try to access them from extern crates.

cc https://github.com/rust-lang/rust/pull/94963#issuecomment-1082924289

2 years agoBless clippy.
Camille GILLOT [Wed, 11 May 2022 16:51:14 +0000 (18:51 +0200)]
Bless clippy.

2 years agoIntroduce EarlyBinder
Jack Huey [Sun, 8 May 2022 05:17:58 +0000 (01:17 -0400)]
Introduce EarlyBinder

2 years agoUpdate clippy to new rake_read signature
Eric Holk [Tue, 10 May 2022 21:20:34 +0000 (14:20 -0700)]
Update clippy to new rake_read signature

2 years agoupdate clippy
lcnr [Tue, 26 Apr 2022 12:04:23 +0000 (14:04 +0200)]
update clippy

2 years agofix clippy
SparrowLii [Mon, 9 May 2022 13:48:57 +0000 (21:48 +0800)]
fix clippy

2 years agoAuto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser
bors [Mon, 9 May 2022 00:02:55 +0000 (00:02 +0000)]
Auto merge of #95542 - xFrednet:rfc-2383-expect-query, r=wesleywiser

Support tool lints with the `#[expect]` attribute (RFC 2383)

This PR fixes the ICE https://github.com/rust-lang/rust/issues/94953 by making the assert for converted expectation IDs conditional.

Additionally, it moves the lint expectation check into a separate query to support rustdoc and other tools. On the way, I've also added some tests to ensure that the attribute works for Clippy and rustdoc lints.

The number of changes comes from the long test file. This may look like a monster PR, this may smell like a monster PR and this may be a monster PR, but it's a harmless monster. :sauropod:

---

Closes: https://github.com/rust-lang/rust/issues/94953
cc: https://github.com/rust-lang/rust/issues/85549

r? `@wesleywiser`

cc: `@rust-lang/rustdoc`

2 years agoAuto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot
bors [Sun, 8 May 2022 14:10:12 +0000 (14:10 +0000)]
Auto merge of #96770 - flip1995:fix-trait-type-in-bounds, r=cjgillot

Track if a where bound comes from a impl Trait desugar

With https://github.com/rust-lang/rust/pull/93803 `impl Trait` function arguments get desugared to hidden where bounds. However, Clippy needs to know if a bound was originally a `impl Trait` or an actual bound. This adds a field to the `WhereBoundPredicate` struct to keep track of this information during AST->HIR lowering.

r? `@cjgillot`

cc `@estebank` (as the reviewer of #93803)

2 years agoTest `expect` attribute for tool lints, clippy edition (RFC 2383)
xFrednet [Thu, 31 Mar 2022 19:49:50 +0000 (21:49 +0200)]
Test `expect` attribute for tool lints, clippy edition (RFC 2383)

2 years agoAuto merge of #94206 - PrestonFrom:significant_drop, r=flip1995
bors [Sun, 8 May 2022 00:57:08 +0000 (00:57 +0000)]
Auto merge of #94206 - PrestonFrom:significant_drop, r=flip1995

Create clippy lint against unexpectedly late drop for temporaries in match scrutinee expressions

A new clippy lint for issue 93883 (https://github.com/rust-lang/rust/issues/93883). Relies on a new trait in `marker` (called `SignificantDrop` to enable linting), which is why this PR is for the rust-lang repo and not the clippy repo.

changelog: new lint [`significant_drop_in_scrutinee`]

2 years agoTrack if a where bound comes from a impl Trait desugar
flip1995 [Thu, 5 May 2022 14:50:11 +0000 (15:50 +0100)]
Track if a where bound comes from a impl Trait desugar

With #93803 `impl Trait` function arguments get desugared to hidden
where bounds. However, Clippy needs to know if a bound was originally a
impl Trait or an actual bound. This adds a field to the
`WhereBoundPredicate` struct to keep track of this information during
HIR lowering.

2 years agoLint for significant drops who may have surprising lifetimes #1
Preston From [Fri, 18 Feb 2022 06:02:22 +0000 (00:02 -0600)]
Lint for significant drops who may have surprising lifetimes #1

author Preston From <prestonfrom@gmail.com> 1645164142 -0600
committer Preston From <prestonfrom@gmail.com> 1650005351 -0600

2 years agoAuto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot
bors [Sat, 7 May 2022 01:59:11 +0000 (01:59 +0000)]
Auto merge of #96531 - kckeiks:remove-item-like-visitor-from-rustc-typeck, r=cjgillot

Remove ItemLikeVisitor impls from rustc_typeck

Issue #95004
cc `@cjgillot`

2 years agoRollup merge of #96557 - nbdd0121:const, r=oli-obk
Guillaume Gomez [Fri, 6 May 2022 18:05:37 +0000 (20:05 +0200)]
Rollup merge of #96557 - nbdd0121:const, r=oli-obk

Allow inline consts to reference generic params

Tracking issue: #76001

The RFC says that inline consts cannot reference to generic parameters (for now), same as array length expressions. And expresses that it's desirable for it to reference in-scope generics, when array length expressions gain that feature as well.

However it is possible to implement this for inline consts before doing this for all anon consts, because inline consts are only used as values and they won't be used in the type system. So we can have:
```rust
fn foo<T>() {
    let x = [4i32; std::mem::size_of::<T>()];   // NOT ALLOWED (for now)
    let x = const { std::mem::size_of::<T>() }; // ALLOWED with this PR!
    let x = [4i32; const { std::mem::size_of::<T>() }];   // NOT ALLOWED (for now)
}
```

This would make inline consts super useful for compile-time checks and assertions:
```rust
fn assert_zst<T>() {
    const { assert!(std::mem::size_of::<T>() == 0) };
}
```

This would create an error during monomorphization when `assert_zst` is instantiated with non-ZST `T`s. A error during mono might sound scary, but this is exactly what a "desugared" inline const would do:
```rust
fn assert_zst<T>() {
    struct F<T>(T);
    impl<T> F<T> {
        const V: () = assert!(std::mem::size_of::<T>() == 0);
    }
    let _ = F::<T>::V;
}
```

It should also be noted that the current inline const implementation can already reference the type params via type inference, so this resolver-level restriction is not any useful either:
```rust
fn foo<T>() -> usize {
    let (_, size): (PhantomData<T>, usize) = const {
        const fn my_size_of<T>() -> (PhantomData<T>, usize) {
            (PhantomData, std::mem::size_of::<T>())
        }
        my_size_of()
    };
    size
}
```

```@rustbot``` label: F-inline_const

2 years agouse def_span and def_kind queries instead of calling tcx.hir() methods
Miguel Guarniz [Fri, 29 Apr 2022 17:11:22 +0000 (13:11 -0400)]
use def_span and def_kind queries instead of calling tcx.hir() methods

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years ago(Partially) Revert "HACK: Move buggy lints to nursery"
flip1995 [Thu, 5 May 2022 14:20:07 +0000 (15:20 +0100)]
(Partially) Revert "HACK: Move buggy lints to nursery"

This reverts commit bb01aca86f66954b80798213711e8eadc4b26902.

Partial: Keep regression tests

2 years agoMerge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup
flip1995 [Thu, 5 May 2022 14:12:52 +0000 (15:12 +0100)]
Merge commit '7c21f91b15b7604f818565646b686d90f99d1baf' into clippyup

2 years agoBless clippy error msg
Gary Guo [Thu, 5 May 2022 13:27:11 +0000 (14:27 +0100)]
Bless clippy error msg

2 years agoAuto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov
bors [Wed, 4 May 2022 21:16:28 +0000 (21:16 +0000)]
Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov

Overhaul `MacArgs`

Motivation:
- Clarify some code that I found hard to understand.
- Eliminate one use of three places where `TokenKind::Interpolated` values are created.

r? `@petrochenkov`

2 years agoOverhaul `MacArgs::Eq`.
Nicholas Nethercote [Thu, 28 Apr 2022 20:52:01 +0000 (06:52 +1000)]
Overhaul `MacArgs::Eq`.

The value in `MacArgs::Eq` is currently represented as a `Token`.
Because of `TokenKind::Interpolated`, `Token` can be either a token or
an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
literal or macro call AST fragment, and then is later lowered to a
literal token. But this is very non-obvious. `Token` is a much more
general type than what is needed.

This commit restricts things, by introducing a new type `MacArgsEqKind`
that is either an AST expression (pre-lowering) or an AST literal
(post-lowering). The downside is that the code is a bit more verbose in
a few places. The benefit is that makes it much clearer what the
possibilities are (though also shorter in some other places). Also, it
removes one use of `TokenKind::Interpolated`, taking us a step closer to
removing that variant, which will let us make `Token` impl `Copy` and
remove many "handle Interpolated" code paths in the parser.

Things to note:
- Error messages have improved. Messages like this:
  ```
  unexpected token: `"bug" + "found"`
  ```
  now say "unexpected expression", which makes more sense. Although
  arbitrary expressions can exist within tokens thanks to
  `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
  know compiler internals.
- In `parse_mac_args_common`, we no longer need to collect tokens for
  the value expression.

2 years agoAuto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco
bors [Tue, 3 May 2022 20:03:54 +0000 (20:03 +0000)]
Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco

Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.

2 years agoMake rustc_parse_format compile on stable
bjorn3 [Fri, 29 Apr 2022 16:48:58 +0000 (18:48 +0200)]
Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may
allow it to be used by rust-analyzer.

2 years agorustc: Panic by default in `DefIdTree::parent`
Vadim Petrochenkov [Mon, 25 Apr 2022 19:08:45 +0000 (22:08 +0300)]
rustc: Panic by default in `DefIdTree::parent`

Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.

2 years agoFix the clippy build
Scott McMurray [Mon, 25 Apr 2022 02:08:23 +0000 (19:08 -0700)]
Fix the clippy build

2 years agoBless tests.
Camille GILLOT [Mon, 14 Mar 2022 14:56:37 +0000 (15:56 +0100)]
Bless tests.

2 years agoStore all generic bounds as where predicates.
Camille GILLOT [Mon, 7 Feb 2022 21:58:30 +0000 (22:58 +0100)]
Store all generic bounds as where predicates.

2 years agoInline WhereClause into Generics.
Camille GILLOT [Sat, 5 Feb 2022 14:48:02 +0000 (15:48 +0100)]
Inline WhereClause into Generics.

2 years agoBox HIR Generics and Impl.
Camille GILLOT [Sat, 5 Feb 2022 14:26:49 +0000 (15:26 +0100)]
Box HIR Generics and Impl.

2 years agoerrors: `span_suggestion` takes `impl ToString`
David Wood [Tue, 26 Apr 2022 05:17:33 +0000 (06:17 +0100)]
errors: `span_suggestion` takes `impl ToString`

Change `span_suggestion` (and variants) to take `impl ToString` rather
than `String` for the suggested code, as this simplifies the
requirements on the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoMake clippy inspector more precise.
Camille GILLOT [Mon, 14 Feb 2022 12:20:47 +0000 (13:20 +0100)]
Make clippy inspector more precise.

2 years agoDrop vis in Item.
Camille GILLOT [Sun, 13 Feb 2022 10:30:48 +0000 (11:30 +0100)]
Drop vis in Item.

2 years agoDrop vis in ImplItem.
Camille GILLOT [Sun, 13 Feb 2022 09:54:07 +0000 (10:54 +0100)]
Drop vis in ImplItem.

2 years agoDrop vis in FieldDef.
Camille GILLOT [Sun, 13 Feb 2022 00:54:13 +0000 (01:54 +0100)]
Drop vis in FieldDef.

2 years agoStop visiting visibility.
Camille GILLOT [Sun, 13 Feb 2022 14:40:08 +0000 (15:40 +0100)]
Stop visiting visibility.

2 years agoRollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Dylan DPC [Tue, 19 Apr 2022 12:43:21 +0000 (14:43 +0200)]
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov

Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.

2 years agoAuto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
bors [Sun, 17 Apr 2022 12:56:19 +0000 (12:56 +0000)]
Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov

Report undeclared lifetimes during late resolution.

First step in https://github.com/rust-lang/rust/pull/91557

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`

2 years agoStop using CRATE_DEF_INDEX.
Camille GILLOT [Fri, 15 Apr 2022 17:27:53 +0000 (19:27 +0200)]
Stop using CRATE_DEF_INDEX.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.

2 years agoBless clippy.
Camille GILLOT [Fri, 1 Apr 2022 17:18:10 +0000 (19:18 +0200)]
Bless clippy.

2 years agoAuto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
bors [Sun, 17 Apr 2022 08:06:53 +0000 (08:06 +0000)]
Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot

Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
cc `@cjgillot`

2 years agoAuto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
bors [Sat, 16 Apr 2022 04:46:01 +0000 (04:46 +0000)]
Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa

Implement sym operands for global_asm!

Tracking issue: #93333

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`

2 years agoRollup merge of #94849 - ouz-a:master4, r=oli-obk
Dylan DPC [Fri, 15 Apr 2022 18:50:44 +0000 (20:50 +0200)]
Rollup merge of #94849 - ouz-a:master4, r=oli-obk

Check var scope if it exist

Fixes #92893.

Added helper function to check the scope of a variable, if it doesn't have a scope call delay_span_bug, which avoids us trying to get a block/scope that doesn't exist.

Had to increase `ROOT_ENTRY_LIMIT` was getting tidy error

2 years agoclippy: Update full path to `CString`
Vadim Petrochenkov [Fri, 15 Apr 2022 13:52:58 +0000 (16:52 +0300)]
clippy: Update full path to `CString`

2 years agoUpdate issue-92893.stderr
ouz-a [Thu, 14 Apr 2022 20:42:15 +0000 (23:42 +0300)]
Update issue-92893.stderr

2 years agoReimplement lowering of sym operands for asm! so that it also works with global_asm!
Amanieu d'Antras [Tue, 1 Mar 2022 00:50:56 +0000 (00:50 +0000)]
Reimplement lowering of sym operands for asm! so that it also works with global_asm!

2 years agoAuto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk
bors [Wed, 13 Apr 2022 21:04:19 +0000 (21:04 +0000)]
Auto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk

errors: lazily load fallback fluent bundle

Addresses (hopefully) https://github.com/rust-lang/rust/pull/95667#issuecomment-1094794087.

Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required.

r? `@ghost` (just for perf initially)

2 years agoAuto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk
bors [Wed, 13 Apr 2022 07:50:56 +0000 (07:50 +0000)]
Auto merge of #94255 - b-naber:use-mir-constant-in-thir, r=oli-obk

Use mir constant in thir instead of ty::Const

This is blocked on https://github.com/rust-lang/rust/pull/94059 (does include its changes, the first two commits in this PR correspond to those changes) and https://github.com/rust-lang/rust/pull/93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`

2 years agoerrors: lazily load fallback fluent bundle
David Wood [Tue, 12 Apr 2022 08:34:40 +0000 (09:34 +0100)]
errors: lazily load fallback fluent bundle

Loading the fallback bundle in compilation sessions that won't go on to
emit any errors unnecessarily degrades compile time performance, so
lazily create the Fluent bundle when it is first required.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoAdd new `Deinit` statement kind
Jakob Degen [Tue, 5 Apr 2022 21:14:59 +0000 (17:14 -0400)]
Add new `Deinit` statement kind

2 years agoAuto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote
bors [Sat, 9 Apr 2022 02:31:24 +0000 (02:31 +0000)]
Auto merge of #95524 - oli-obk:cached_stable_hash_cleanups, r=nnethercote

Cached stable hash cleanups

r? `@nnethercote`

Add a sanity assertion in debug mode to check that the cached hashes are actually the ones we get if we compute the hash each time.

Add a new data structure that bundles all the hash-caching work to make it easier to re-use it for different interned data structures

2 years agoremove CheckVisitor, CollectExternCrateVisitor and ItemLikeVisitor impls
Miguel Guarniz [Thu, 7 Apr 2022 20:47:40 +0000 (16:47 -0400)]
remove CheckVisitor, CollectExternCrateVisitor and ItemLikeVisitor impls

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2 years agoRefactor HIR item-like traversal (part 1)
Miguel Guarniz [Sun, 3 Apr 2022 19:50:33 +0000 (15:50 -0400)]
Refactor HIR item-like traversal (part 1)

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- add par_items(impl Fn(hir::ItemId)) to traverse all items in parallel

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>