]> git.lizzy.rs Git - rust.git/log
rust.git
23 months agoavoid some `Symbol` to `String` conversions
Takayuki Maeda [Sat, 16 Jul 2022 19:09:20 +0000 (04:09 +0900)]
avoid some `Symbol` to `String` conversions

23 months agoRollup merge of #99026 - anall:buffix/clippy-9131, r=xFrednet
Matthias Krüger [Fri, 8 Jul 2022 06:00:41 +0000 (08:00 +0200)]
Rollup merge of #99026 - anall:buffix/clippy-9131, r=xFrednet

Add test for and fix rust-lang/rust-clippy#9131

This lint seems to have been broken by #98446 -- but of course, there was no clippy test for this case at the time.

`expr.span.ctxt().outer_expn_data()` now has `MacroKind::Derive` instead of `MacroKind::Attr` for something like:

```
#[derive(Clone, Debug)]
pub struct UnderscoreInStruct {
    _foo: u32,
}
```

---

changelog: none

closes: https://github.com/rust-lang/rust-clippy/issues/9131

23 months agoAuto merge of #98482 - cjgillot:short-struct-span-closure, r=estebank
bors [Fri, 8 Jul 2022 03:05:15 +0000 (03:05 +0000)]
Auto merge of #98482 - cjgillot:short-struct-span-closure, r=estebank

Shorten def_span of closures to just their header

Continuation of https://github.com/rust-lang/rust/pull/93967.

23 months agoAdd test for and fix rust-lang/rust-clippy#9131
Andrea Nall [Thu, 7 Jul 2022 19:30:37 +0000 (19:30 +0000)]
Add test for and fix rust-lang/rust-clippy#9131

This lint seems to have been broken by #98446

23 months agoRollup merge of #98930 - tmiasko:pub-basic-blocks, r=oli-obk
Dylan DPC [Thu, 7 Jul 2022 12:36:53 +0000 (18:06 +0530)]
Rollup merge of #98930 - tmiasko:pub-basic-blocks, r=oli-obk

Make MIR basic blocks field public

This makes it possible to mutably borrow different fields of the MIR
body without resorting to methods like `basic_blocks_local_decls_mut_and_var_debug_info`.

To preserve validity of control flow graph caches in the presence of
modifications, a new struct `BasicBlocks` wraps together basic blocks
and control flow graph caches.

The `BasicBlocks` dereferences to `IndexVec<BasicBlock, BasicBlockData>`.
On the other hand a mutable access requires explicit `as_mut()` call.

23 months agoRollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, r=wesleywiser
Dylan DPC [Thu, 7 Jul 2022 12:36:50 +0000 (18:06 +0530)]
Rollup merge of #98507 - xFrednet:rfc-2383-manual-expectation-magic, r=wesleywiser

Finishing touches for `#[expect]` (RFC 2383)

This PR adds documentation and some functionality to rustc's lint passes, to manually fulfill expectations. This is needed for some lints in Clippy. Hopefully, it should be one of the last things before we can move forward with stabilizing this feature.

As part of this PR, I've also updated `clippy::duplicate_mod` to showcase how this new functionality can be used and to ensure that it works correctly.

---

changelog: [`duplicate_mod`]: Fixed lint attribute interaction

r? `@wesleywiser`

cc: https://github.com/rust-lang/rust/issues/97660, https://github.com/rust-lang/rust/issues/85549

And I guess that's it. Here have a magical unicorn :unicorn:

23 months agoShorten span for closures.
Camille GILLOT [Mon, 27 Jun 2022 05:45:35 +0000 (07:45 +0200)]
Shorten span for closures.

23 months agoMove `predecessors` from Body to BasicBlocks
Tomasz Miąsko [Tue, 5 Jul 2022 00:00:00 +0000 (00:00 +0000)]
Move `predecessors` from Body to BasicBlocks

23 months agoAuto merge of #98827 - aDotInTheVoid:suggest-extern-block, r=nagisa
bors [Thu, 7 Jul 2022 04:18:47 +0000 (04:18 +0000)]
Auto merge of #98827 - aDotInTheVoid:suggest-extern-block, r=nagisa

Suggest using block for `extern "abi" fn` with no body

`@rustbot` modify labels: +A-diagnostics

23 months agoFix `#[expect]` and `#[allow]` for `clippy::duplicate_mod`
xFrednet [Sat, 25 Jun 2022 22:00:47 +0000 (00:00 +0200)]
Fix `#[expect]` and `#[allow]` for `clippy::duplicate_mod`

23 months agofix miri-opt tests
Takayuki Maeda [Wed, 6 Jul 2022 01:47:29 +0000 (10:47 +0900)]
fix miri-opt tests

23 months agoUpdate TypeVisitor paths
Alan Egerton [Fri, 17 Jun 2022 12:15:00 +0000 (13:15 +0100)]
Update TypeVisitor paths

23 months agoRelax constrained generics to TypeVisitable
Alan Egerton [Fri, 17 Jun 2022 12:10:07 +0000 (13:10 +0100)]
Relax constrained generics to TypeVisitable

23 months agoast: Add span to `Extern`
Nixon Enraght-Moony [Sat, 2 Jul 2022 17:25:55 +0000 (18:25 +0100)]
ast: Add span to `Extern`

23 months agoRollup merge of #98639 - camsteffen:no-node-binding, r=compiler-errors
Dylan DPC [Sat, 2 Jul 2022 06:53:38 +0000 (12:23 +0530)]
Rollup merge of #98639 - camsteffen:no-node-binding, r=compiler-errors

Factor out `hir::Node::Binding`

23 months agoShorten def_span for more items.
Camille GILLOT [Sun, 13 Feb 2022 15:27:59 +0000 (16:27 +0100)]
Shorten def_span for more items.

23 months agoFactor out hir::Node::Binding
Cameron Steffen [Tue, 28 Jun 2022 18:15:30 +0000 (13:15 -0500)]
Factor out hir::Node::Binding

2 years agoMerge commit '0cb0f7636851f9fcc57085cf80197a2ef6db098f' into clippyup
Philipp Krones [Thu, 30 Jun 2022 08:50:09 +0000 (10:50 +0200)]
Merge commit '0cb0f7636851f9fcc57085cf80197a2ef6db098f' into clippyup

2 years agoremove last use of MAX_SUGGESTION_HIGHLIGHT_LINES
Maybe Waffle [Sun, 19 Jun 2022 20:25:07 +0000 (00:25 +0400)]
remove last use of MAX_SUGGESTION_HIGHLIGHT_LINES

2 years agoremove `span_lint_and_sugg_for_edges` from clippy utils
Maybe Waffle [Sun, 19 Jun 2022 19:21:14 +0000 (23:21 +0400)]
remove `span_lint_and_sugg_for_edges` from clippy utils

2 years agoRollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se
Matthias Krüger [Sat, 18 Jun 2022 22:17:13 +0000 (00:17 +0200)]
Rollup merge of #98165 - WaffleLapkin:once_things_renamings, r=m-ou-se

once cell renamings

This PR does the renamings proposed in https://github.com/rust-lang/rust/issues/74465#issuecomment-1153703128

- Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`
- Move/rename `lazy::{SyncOnceCell, SyncLazy}` to `sync::{OnceLock, LazyLock}`

(I used `Lazy...` instead of `...Lazy` as it seems to be more consistent, easier to pronounce, etc)

```@rustbot``` label +T-libs-api -T-libs

2 years agoAuto merge of #97892 - klensy:fix-spaces, r=oli-obk
bors [Fri, 17 Jun 2022 17:30:16 +0000 (17:30 +0000)]
Auto merge of #97892 - klensy:fix-spaces, r=oli-obk

diagnostics: remove trailing spaces

Remove few occurrences of trailing spaces and drive by fix of needless alloc of const string.

2 years agoRollup merge of #98191 - TaKO8Ki:remove-rest-of-unnecessary-to-string, r=Dylan-DPC
Dylan DPC [Fri, 17 Jun 2022 10:21:50 +0000 (12:21 +0200)]
Rollup merge of #98191 - TaKO8Ki:remove-rest-of-unnecessary-to-string, r=Dylan-DPC

Remove the rest of unnecessary `to_string`

I removed most of unnecessary `to_string` in #98043. This patch removes the rest of them I missed.

2 years agoRollup merge of #97798 - WaffleLapkin:allow_for_suggestions_that_are_quite_far_away_f...
Dylan DPC [Fri, 17 Jun 2022 10:21:48 +0000 (12:21 +0200)]
Rollup merge of #97798 - WaffleLapkin:allow_for_suggestions_that_are_quite_far_away_from_each_other, r=estebank

Hide irrelevant lines in suggestions to allow for suggestions that are far from each other to be shown

This is an attempt to fix suggestions one part of which is 6 lines or more far from the first. I've noticed "the problem" (of not showing some parts of the suggestion) here: https://github.com/rust-lang/rust/pull/97759#discussion_r889689230.

I'm not sure about the implementation (this big closure is just bad and makes already complicated code even more so), but I want to at least discuss the result.

Here is an example of how this changes the output:

Before:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
5 |
6 |
7 |
8 |
...
```

After:
```text
help: consider enclosing expression in a block
  |
3 ~     'l: { match () { () => break 'l,
4 |
...
31|
32~ } };
  |
```

r? `@estebank`
`@rustbot` label +A-diagnostics +A-suggestion-diagnostics

2 years agoremove the rest of unnecessary `to_string`
Takayuki Maeda [Fri, 17 Jun 2022 09:48:09 +0000 (18:48 +0900)]
remove the rest of unnecessary `to_string`

2 years agoMove/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`
Maybe Waffle [Thu, 16 Jun 2022 15:39:39 +0000 (19:39 +0400)]
Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`

2 years agoMerge commit 'd7b5cbf065b88830ca519adcb73fad4c0d24b1c7' into clippyup
flip1995 [Thu, 16 Jun 2022 15:39:06 +0000 (17:39 +0200)]
Merge commit 'd7b5cbf065b88830ca519adcb73fad4c0d24b1c7' into clippyup

2 years agobless clippy ui tests
Maybe Waffle [Thu, 16 Jun 2022 14:00:32 +0000 (18:00 +0400)]
bless clippy ui tests

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`.