Commit graph

3087 commits

Author SHA1 Message Date
bors dcf622eb70 Auto merge of #80993 - Aaron1011:collect-set-tokens, r=petrochenkov
Set tokens on AST node in `collect_tokens`

A new `HasTokens` trait is introduced, which is used to move logic from
the callers of `collect_tokens` into the body of `collect_tokens`.

In addition to reducing duplication, this paves the way for PR #80689,
which needs to perform additional logic during token collection.
2021-01-15 05:36:48 +00:00
bors e38fb306b7 Auto merge of #81018 - m-ou-se:rollup-7202dc7, r=m-ou-se
Rollup of 17 pull requests

Successful merges:

 - #79982 (Add missing methods to unix ExitStatusExt)
 - #80017 (Suggest `_` and `..` if a pattern has too few fields)
 - #80169 (Recommend panic::resume_unwind instead of panicking.)
 - #80217 (Add a `std::io::read_to_string` function)
 - #80444 (Add as_ref and as_mut methods for Bound)
 - #80567 (Add Iterator::intersperse_with)
 - #80829 (Get rid of `DepConstructor`)
 - #80895 (Fix handling of malicious Readers in read_to_end)
 - #80966 (Deprecate atomic::spin_loop_hint in favour of hint::spin_loop)
 - #80969 (Use better ICE message when no MIR is available)
 - #80972 (Remove unstable deprecated Vec::remove_item)
 - #80973 (Update books)
 - #80980 (Fixed incorrect doc comment)
 - #80981 (Fix -Cpasses=list and llvm version print with -vV)
 - #80985 (Fix stabilisation version of slice_strip)
 - #80990 (llvm: Remove the unused context from CreateDebugLocation)
 - #80991 (Fix formatting specifiers doc links)

Failed merges:

 - #80944 (Use Option::map_or instead of `.map(..).unwrap_or(..)`)

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-14 20:21:20 +00:00
Mara Bos 494cb3cc7c
Rollup merge of #80990 - cuviper:unused-debug-context, r=nagisa
llvm: Remove the unused context from CreateDebugLocation

This went unused in commit 88d874de63, part of #68965.
2021-01-14 18:00:29 +00:00
Mara Bos ce3bc76a86
Rollup merge of #80981 - bjorn3:bjorn3-patch-1, r=jonas-schievink
Fix -Cpasses=list and llvm version print with -vV

cc https://github.com/rust-lang/rust/pull/77975#issuecomment-759362933
2021-01-14 18:00:25 +00:00
Mara Bos 90cc815829
Rollup merge of #80969 - camelid:monomorph-ice-msg, r=nagisa
Use better ICE message when no MIR is available

The ICE message is somewhat confusing and overly specific - the issue is
that there's no MIR available.

This should make debugging these ICEs easier since the error tells you
what's actually wrong, not what it was trying to do when it failed.

cc https://github.com/rust-lang/rust/pull/80952#issuecomment-759198841
cc `````@jyn514`````
2021-01-14 18:00:16 +00:00
Mara Bos 9e9aba87af
Rollup merge of #80829 - jyn514:dep-constructor, r=michaelwoerister
Get rid of `DepConstructor`

This removes fully 235 unused functions.

Follow-up to https://github.com/rust-lang/rust/pull/80325#discussion_r548491999.

r? ``@michaelwoerister``
cc ``@cjgillot``
2021-01-14 18:00:09 +00:00
Mara Bos d3b31065e3
Rollup merge of #80017 - camelid:sugg-rest-pattern, r=estebank
Suggest `_` and `..` if a pattern has too few fields

Fixes #80010.
2021-01-14 17:59:55 +00:00
bors 4275ef6c9d Auto merge of #79689 - Vooblin:patch1, r=tmandry
Update tests of "unused_lifetimes" lint for async functions and corresponding source code

Before this PR the following code would cause an error:
```
#![deny(unused_lifetimes)]
async fn f<'a>(_: &'a i32) {}
fn main() {}
```
It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused.

Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now.

This PR connected to issues #78522, #77217
2021-01-14 17:27:15 +00:00
bors d03fe84169 Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
Reintroduce hir::ExprKind::If

Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications.

The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome.

- [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051)
- [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d)
- [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5)
- [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691)
- [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95)
- [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-14 14:41:58 +00:00
Aaron Hill a961e6785c
Set tokens on AST node in collect_tokens
A new `HasTokens` trait is introduced, which is used to move logic from
the callers of `collect_tokens` into the body of `collect_tokens`.

In addition to reducing duplication, this paves the way for PR #80689,
which needs to perform additional logic during token collection.
2021-01-13 22:10:36 -05:00
Tomasz Miąsko ea4cbff264 Encode optimized MIR of generators when emitting metadata 2021-01-14 00:00:00 +00:00
bors 180fdffa17 Auto merge of #80654 - Aaron1011:fix/dummy-span-ctxt, r=wesleywiser
Properly handle `SyntaxContext` of dummy spans in incr comp

Fixes #80336

Due to macro expansion, we may end up with spans with an invalid
location and non-root `SyntaxContext`. This commits preserves the
`SyntaxContext` of such spans in the incremental cache, and ensures
that we always hash the `SyntaxContext` when computing the `Fingerprint`
of a `Span`

Previously, we would discard the `SyntaxContext` during serialization to
the incremental cache, causing the span's `Fingerprint` to change across
compilation sessions.
2021-01-13 23:24:31 +00:00
bors a62a76047e Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-13 20:35:58 +00:00
Aaron Hill 482a67d20f
Properly handle SyntaxContext of dummy spans in incr comp
Fixes #80336

Due to macro expansion, we may end up with spans with an invalid
location and non-root `SyntaxContext`. This commits preserves the
`SyntaxContext` of such spans in the incremental cache, and ensures
that we always hash the `SyntaxContext` when computing the `Fingerprint`
of a `Span`

Previously, we would discard the `SyntaxContext` during serialization to
the incremental cache, causing the span's `Fingerprint` to change across
compilation sessions.
2021-01-13 15:20:29 -05:00
Josh Stone 0342fd16ff Remove the unused context from CreateDebugLocation
This went unused in commit 88d874de63, part of #68965.
2021-01-13 11:55:49 -08:00
bors 9bc8b00b4a Auto merge of #80718 - tmiasko:skip-opt-mir, r=oli-obk
Consistently avoid constructing optimized MIR when not doing codegen

The optimized MIR for closures is being encoded unconditionally, while
being unnecessary for cargo check. This turns out to be especially
costly with MIR inlining enabled, since it triggers computation of
optimized MIR for all callees that are being examined for inlining
purposes https://github.com/rust-lang/rust/pull/77307#issuecomment-751915450.

Skip encoding of optimized MIR for closures, enum constructors, struct
constructors, and trait fns when not doing codegen, like it is already
done for other items since 49433.
2021-01-13 17:48:41 +00:00
Mark Rousskov 4614671cae Update code to account for extern ABI requirement 2021-01-13 07:49:45 -05:00
Mark Rousskov 920b5ee722 Lint on extern in item declaration position 2021-01-13 07:49:16 -05:00
Mark Rousskov 8a3edb1d66 Update tests for extern block linting 2021-01-13 07:49:16 -05:00
Mark Rousskov c4a8d7f86a Introduce missing ABI lint on extern blocks 2021-01-13 07:49:16 -05:00
bjorn3 64c1b0d614
Fix -Cpasses=list and llvm version print with -vV 2021-01-13 12:15:42 +01:00
Camelid e8c87935e0 Include .. suggestion if fields are all wildcards 2021-01-12 21:20:26 -08:00
Camelid c3f7429fb4 Use better ICE message when no MIR is available
The ICE message is somewhat confusing and overly specific - the issue is
that there's no MIR available.

This should make debugging these ICEs easier since the error tells you
what's actually wrong, not what it was trying to do when it failed.

cc https://github.com/rust-lang/rust/pull/80952#issuecomment-759198841
2021-01-12 20:54:35 -08:00
bors fc93e4719c Auto merge of #80960 - Dylan-DPC:rollup-89tri8x, r=Dylan-DPC
Rollup of 10 pull requests

Successful merges:

 - #78901 (diagnostics: Note capturing closures can't be coerced to fns)
 - #79588 (Provide more information for HRTB lifetime errors involving closures)
 - #80232 (Remove redundant def_id lookups)
 - #80662 (Added support for i386-unknown-linux-gnu and i486-unknown-linux-gnu)
 - #80736 (use Once instead of Mutex to manage capture resolution)
 - #80796 (Update to LLVM 11.0.1)
 - #80859 (Fix --pretty=expanded with --remap-path-prefix)
 - #80922 (Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2)
 - #80924 (Fix rustdoc --test-builder argument parsing)
 - #80935 (Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-13 04:29:45 +00:00
Camelid d7307a71f5 Always show suggestions in their own subwindows 2021-01-12 19:25:51 -08:00
Camelid 9959d6deed Only suggest .. if more than one field is missing 2021-01-12 19:25:51 -08:00
Camelid fe82cc38a0 Specialize .. help message for all fields vs. the rest 2021-01-12 19:25:50 -08:00
Camelid a5e8e6ec2d Pluralize 'parenthesis' correctly
It's 'parentheses', not 'parenthesis', when you have more than one.
2021-01-12 19:25:50 -08:00
Camelid f3d9df54ee Suggest Variant(..) if all of the mentioned fields are _ 2021-01-12 19:25:50 -08:00
Camelid 5fe61a79cc Simplify code
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2021-01-12 19:25:50 -08:00
Camelid 16692ab66a Suggest _ and .. if a pattern has too few fields
For example, this code:

    struct S(i32, f32);

    let S(x) = S(0, 1.0);

will make the compiler suggest either:

    let S(x, _) = S(0, 1.0);

or:

    let S(x, ..) = S(0, 1.0);
2021-01-12 19:25:49 -08:00
Dylan DPC 5b90fe1c30
Rollup merge of #80935 - pierwill:rustc_middle-levelandsource, r=petrochenkov
Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`

This continues work in https://github.com/rust-lang/rust/pull/80274 to improve code readability.

This naming follows a pattern seen elsewhere in the compiler (e.g. [`rustc_middle::ty::TypeAndMut`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeAndMut.html)).
2021-01-13 03:20:27 +01:00
Dylan DPC d64e703e4f
Rollup merge of #80922 - spastorino:revert-inline-always-in-debug, r=wesleywiser
Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2

This reverts commit ddf2cc7f8e, reversing
changes made to 937f629535.

As `@alexcrichton` pointed out in https://github.com/rust-lang/rust/issues/80916 there's a problem with the taken approach.
2021-01-13 03:20:23 +01:00
Dylan DPC 7ce8246a23
Rollup merge of #80859 - jsgf:fix-pretty-remap, r=davidtwco
Fix --pretty=expanded with --remap-path-prefix

Per https://github.com/rust-lang/rust/issues/80832, using
--pretty=expanded and --remap-path-prefix results in an ICE.

This is becasue the session source files table is stored in remapped
form, whereas --pretty-expanded looks up unremapped files. This remaps
the path prefixes before lookup.

~~There don't appear to be any existing tests for --pretty=expanded; I'll look into
adding some.~~ Never mind, found the pretty tests.

Fixes #80832
2021-01-13 03:20:21 +01:00
Dylan DPC 492cb39825
Rollup merge of #80662 - rxrbln:master, r=estebank
Added support for i386-unknown-linux-gnu and i486-unknown-linux-gnu

Support for both can be useful when creating new firmware, boot loaders,
or embedded operating systems.
2021-01-13 03:20:15 +01:00
Dylan DPC ac7267a5e7
Rollup merge of #80232 - bugadani:roundtrip, r=estebank
Remove redundant def_id lookups

Simplify `DefId -> LocalDefId -> HirId -> LocalDefId -> DefId` chains.
2021-01-13 03:20:13 +01:00
Dylan DPC 11bca6b07f
Rollup merge of #79588 - estebank:issue-79187, r=oli-obk
Provide more information for HRTB lifetime errors involving closures
2021-01-13 03:20:11 +01:00
Dylan DPC 45ba015357
Rollup merge of #78901 - arora-aman:fix_closure_coerce, r=estebank
diagnostics: Note capturing closures can't be coerced to fns

Fixes #72457, fixes #71895

r? `@estebank`
2021-01-13 03:20:09 +01:00
bors 150d1fee04 Auto merge of #79322 - jyn514:refactor-impl, r=estebank
Separate out a `hir::Impl` struct

This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.

See `rustc_save_analysis::dump_visitor::process_impl` or `rustdoc::clean::clean_impl` for a good example of how this makes `impl`s easier to work with.

r? `@petrochenkov` maybe?
2021-01-13 01:40:41 +00:00
Joshua Nelson a8ff647deb Separate out a hir::Impl struct
This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
2021-01-12 20:32:33 -05:00
Tomasz Miąsko 16857317a6 Skip promoted mir of struct constructors & enum constructors 2021-01-13 00:33:36 +01:00
Tomasz Miąsko a6dd7b5056 Consistently avoid constructing optimized MIR when not doing codegen
The optimized MIR for closures is being encoded unconditionally, while
being unnecessary for cargo check. This turns out to be especially
costly with MIR inlining enabled, since it triggers computation of
optimized MIR for all callees that are being examined for inlining
purposes.

Skip encoding of optimized MIR for closures, enum constructors, struct
constructors, and trait fns when not doing codegen, like it is already
done for other items since 49433.
2021-01-13 00:33:36 +01:00
bors 058a710165 Auto merge of #79670 - Nadrieril:uninhabited-query, r=estebank
Turn type inhabitedness into a query to fix `exhaustive_patterns` perf

We measured in https://github.com/rust-lang/rust/pull/79394 that enabling the [`exhaustive_patterns` feature](https://github.com/rust-lang/rust/issues/51085) causes significant perf degradation. It was conjectured that the culprit is type inhabitedness checking, and [I hypothesized](https://github.com/rust-lang/rust/pull/79394#issuecomment-733861149) that turning this computation into a query would solve most of the problem.

This PR turns `tcx.is_ty_uninhabited_from` into a query, and I measured a 25% perf gain on the benchmark that stress-tests `exhaustiveness_patterns`. This more than compensates for the 30% perf hit I measured [when creating it](https://github.com/rust-lang/rustc-perf/pull/801). We'll have to measure enabling the feature again, but I suspect this fixes the perf regression entirely.
I'd like a perf run on this PR obviously.
I made small atomic commits to help reviewing. The first one is just me discovering the "revisions" feature of the testing framework.

I believe there's a push to move things out of `rustc_middle` because it's huge. I guess `inhabitedness/mod.rs` could be moved out, but it's quite small. `DefIdForest` might be movable somewhere too. I don't know what the policy is for that.

Ping `@camelid` since you were interested in following along
`@rustbot` modify labels: +A-exhaustiveness-checking
2021-01-12 22:58:42 +00:00
Esteban Küber a8a974245e Provide more information for HRTB lifetime errors involving closures 2021-01-12 13:53:13 -08:00
Nadrieril e608d8f4e5 Make DefIdForest cheaper to clone
Since `DefIdForest` contains 0 or 1 elements the large majority of the
time, by allocating only in the >1 case we avoid almost all allocations,
compared to `Arc<SmallVec<[DefId;1]>>`. This shaves off 0.2% on the
benchmark that stresses uninhabitedness checking.
2021-01-12 20:31:58 +00:00
Tomasz Miąsko 1bf3949398 Reorder MIR encoding checks
Start from least expensive checks when deciding whether to encode MIR or not.

No functional changes intended.
2021-01-12 21:18:39 +01:00
bors 7a9b552cb1 Auto merge of #80009 - jumbatm:issue79581-overeager-clashing-extern-decl, r=alexcrichton
Use tcx.symbol_name when determining clashing extern declarations.

Fixes #79581.

r? `@alexcrichton`
2021-01-12 20:13:50 +00:00
Nadrieril 8598c9f6e5 Turn type inhabitedness into a query 2021-01-12 19:59:11 +00:00
bors 704e47f78b Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelix
Make CTFE able to check for UB...

... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md

To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions.

This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-12 17:26:56 +00:00
oli 53e3a23572 Coverage computation needs access to the MIR, too 2021-01-12 15:12:03 +00:00