]> git.lizzy.rs Git - rust.git/log
rust.git
3 years agounix ExitStatus: Add tracking issue to new methods
Ian Jackson [Mon, 4 Jan 2021 17:37:34 +0000 (17:37 +0000)]
unix ExitStatus: Add tracking issue to new methods

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agoReplace `Ie` with `In other words`
Ian Jackson [Sun, 13 Dec 2020 11:03:37 +0000 (11:03 +0000)]
Replace `Ie` with `In other words`

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
3 years agoReplace `Ie` with `In other words`
Ian Jackson [Sun, 13 Dec 2020 11:03:17 +0000 (11:03 +0000)]
Replace `Ie` with `In other words`

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
3 years agounix ExitStatus: Provide .continued()
Ian Jackson [Sat, 12 Dec 2020 21:52:17 +0000 (21:52 +0000)]
unix ExitStatus: Provide .continued()

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agounix ExitStatus: Provide .stopped_signal()
Ian Jackson [Sat, 12 Dec 2020 21:47:47 +0000 (21:47 +0000)]
unix ExitStatus: Provide .stopped_signal()

Necessary to handle WIFSTOPPED.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agounix ExitStatus: Provide .core_dumped
Ian Jackson [Sat, 12 Dec 2020 21:44:13 +0000 (21:44 +0000)]
unix ExitStatus: Provide .core_dumped

This is essential for proper reporting of child process status on Unix.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agounix ExitStatus: Provide .into_raw()
Ian Jackson [Sat, 12 Dec 2020 21:41:55 +0000 (21:41 +0000)]
unix ExitStatus: Provide .into_raw()

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agounix ExitStatus: Clarify docs for .signal()
Ian Jackson [Sat, 12 Dec 2020 21:37:34 +0000 (21:37 +0000)]
unix ExitStatus: Clarify docs for .signal()

We need to be clear that this never returns WSTOPSIG.  That is, if
WIFSTOPPED, the return value is None.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agounix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED
Ian Jackson [Sat, 12 Dec 2020 21:31:54 +0000 (21:31 +0000)]
unix ExitStatus: Do not treat WIFSTOPPED as WIFSIGNALED

A unix wait status can contain, at least, exit statuses, termination
signals, and stop signals.

WTERMSIG is only valid if WIFSIGNALED.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html

It will not be easy to experience this bug with `Command`, because
that doesn't pass WUNTRACED.  But you could make an ExitStatus
containing, say, a WIFSTOPPED, from a call to one of the libc wait
functions.

(In the WIFSTOPPED case, there is WSTOPSIG.  But a stop signal is
encoded differently to a termination signal, so WTERMSIG and WSTOPSIG
are by no means the same.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
3 years agoUpdate code to account for extern ABI requirement
Mark Rousskov [Tue, 1 Sep 2020 21:28:11 +0000 (17:28 -0400)]
Update code to account for extern ABI requirement

3 years agoLint on extern in item declaration position
Mark Rousskov [Tue, 1 Sep 2020 21:21:54 +0000 (17:21 -0400)]
Lint on extern in item declaration position

3 years agoUpdate tests for extern block linting
Mark Rousskov [Tue, 1 Sep 2020 21:12:52 +0000 (17:12 -0400)]
Update tests for extern block linting

3 years agoIntroduce missing ABI lint on extern blocks
Mark Rousskov [Tue, 1 Sep 2020 21:12:38 +0000 (17:12 -0400)]
Introduce missing ABI lint on extern blocks

3 years agoMove help link to error index
1000teslas [Wed, 13 Jan 2021 12:37:49 +0000 (23:37 +1100)]
Move help link to error index

3 years agoFix -Cpasses=list and llvm version print with -vV
bjorn3 [Wed, 13 Jan 2021 11:15:42 +0000 (12:15 +0100)]
Fix -Cpasses=list and llvm version print with -vV

3 years agoAuto merge of #80824 - cuviper:heap-clones, r=kennytm
bors [Wed, 13 Jan 2021 11:11:34 +0000 (11:11 +0000)]
Auto merge of #80824 - cuviper:heap-clones, r=kennytm

Try to avoid locals when cloning into Box/Rc/Arc

For generic `T: Clone`, we can allocate an uninitialized box beforehand,
which gives the optimizer a chance to create the clone directly in the
heap. For `T: Copy`, we can go further and do a simple memory copy,
regardless of optimization level.

The same applies to `Rc`/`Arc::make_mut` when they must clone the data.

3 years agoFixed incorrect doc comment
trevor arjeski [Wed, 13 Jan 2021 10:49:46 +0000 (13:49 +0300)]
Fixed incorrect doc comment

">" is right alignment, not left

3 years agoAuto merge of #77858 - ijackson:split-inclusive, r=KodrAus
bors [Wed, 13 Jan 2021 07:38:58 +0000 (07:38 +0000)]
Auto merge of #77858 - ijackson:split-inclusive, r=KodrAus

Stabilize split_inclusive

### Contents of this MR

This stabilises:

 * `slice::split_inclusive`
 * `slice::split_inclusive_mut`
 * `str::split_inclusive`

Closes #72360.

### A possible concern

The proliferation of `split_*` methods is not particularly pretty.  The existence of `split_inclusive` seems to invite the addition of `rsplit_inclusive`, `splitn_inclusive`, etc.  We could instead have a more general API, along these kinds of lines maybe:
```
   pub fn split_generic('a,P,H>(&'a self, pat: P, how: H) -> ...
       where P: Pattern
       where H: SplitHow;

   pub fn split_generic_mut('a,P,H>(&'a mut self, pat: P, how: H) -> ...
       where P: Pattern
       where H: SplitHow;

   trait SplitHow {
       fn reverse(&self) -> bool;
       fn inclusive -> bool;
       fn limit(&self) -> Option<usize>;
   }

   pub struct SplitFwd;
   ...
   pub struct SplitRevInclN(pub usize);
```
But maybe that is worse.

### Let us defer that? ###

This seems like a can of worms.  I think we can defer opening it now; if and when we have something more general, these two methods can become convenience aliases.  But I thought I would mention it so the lang API team can consider it and have an opinion.

3 years agodeprecate atomic::spin_loop_hint in favour of hint::spin_loop
Ashley Mannix [Wed, 13 Jan 2021 04:39:19 +0000 (14:39 +1000)]
deprecate atomic::spin_loop_hint in favour of hint::spin_loop

3 years agoInclude `..` suggestion if fields are all wildcards
Camelid [Wed, 13 Jan 2021 04:39:51 +0000 (20:39 -0800)]
Include `..` suggestion if fields are all wildcards

3 years agoUpdate books
Eric Huss [Wed, 13 Jan 2021 04:42:46 +0000 (20:42 -0800)]
Update books

3 years agoremove unstable deprecated Vec::remove_item
Ashley Mannix [Wed, 13 Jan 2021 05:14:11 +0000 (15:14 +1000)]
remove unstable deprecated Vec::remove_item

3 years agoUse better ICE message when no MIR is available
Camelid [Wed, 13 Jan 2021 04:52:06 +0000 (20:52 -0800)]
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

3 years agoAuto merge of #80960 - Dylan-DPC:rollup-89tri8x, r=Dylan-DPC
bors [Wed, 13 Jan 2021 04:29:45 +0000 (04:29 +0000)]
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

3 years agobump split_inclusive stabilization to 1.51.0
Ashley Mannix [Wed, 13 Jan 2021 03:51:37 +0000 (13:51 +1000)]
bump split_inclusive stabilization to 1.51.0

3 years agobump split_inclusive stabilization to 1.51.0
Ashley Mannix [Wed, 13 Jan 2021 03:50:39 +0000 (13:50 +1000)]
bump split_inclusive stabilization to 1.51.0

3 years agobump split_inclusive stabilization to 1.51.0
Ashley Mannix [Wed, 13 Jan 2021 03:49:34 +0000 (13:49 +1000)]
bump split_inclusive stabilization to 1.51.0

3 years agobump split_inclusive stabilization to 1.51.0
Ashley Mannix [Wed, 13 Jan 2021 03:48:36 +0000 (13:48 +1000)]
bump split_inclusive stabilization to 1.51.0

3 years agoUpdate cargo
Eric Huss [Wed, 13 Jan 2021 03:46:42 +0000 (19:46 -0800)]
Update cargo

3 years agoAlways show suggestions in their own subwindows
Camelid [Wed, 13 Jan 2021 03:06:20 +0000 (19:06 -0800)]
Always show suggestions in their own subwindows

3 years agoAdd a test case with lots of whitespace
Camelid [Wed, 13 Jan 2021 00:47:04 +0000 (16:47 -0800)]
Add a test case with lots of whitespace

3 years agoOnly suggest `..` if more than one field is missing
Camelid [Sun, 20 Dec 2020 22:43:07 +0000 (14:43 -0800)]
Only suggest `..` if more than one field is missing

3 years agoSpecialize `..` help message for all fields vs. the rest
Camelid [Sat, 19 Dec 2020 04:17:09 +0000 (20:17 -0800)]
Specialize `..` help message for all fields vs. the rest

3 years agoPluralize 'parenthesis' correctly
Camelid [Sat, 19 Dec 2020 03:56:14 +0000 (19:56 -0800)]
Pluralize 'parenthesis' correctly

It's 'parentheses', not 'parenthesis', when you have more than one.

3 years agoSuggest `Variant(..)` if all of the mentioned fields are `_`
Camelid [Sat, 19 Dec 2020 03:51:39 +0000 (19:51 -0800)]
Suggest `Variant(..)` if all of the mentioned fields are `_`

3 years agoSimplify code
Camelid [Sat, 19 Dec 2020 01:09:53 +0000 (17:09 -0800)]
Simplify code

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
3 years agoSuggest `_` and `..` if a pattern has too few fields
Camelid [Sun, 13 Dec 2020 22:13:52 +0000 (14:13 -0800)]
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);

3 years agoRollup merge of #80935 - pierwill:rustc_middle-levelandsource, r=petrochenkov
Dylan DPC [Wed, 13 Jan 2021 02:20:27 +0000 (03:20 +0100)]
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)).

3 years agoRollup merge of #80924 - teryror:issue-80893-fix, r=jyn514
Dylan DPC [Wed, 13 Jan 2021 02:20:25 +0000 (03:20 +0100)]
Rollup merge of #80924 - teryror:issue-80893-fix, r=jyn514

Fix rustdoc --test-builder argument parsing

My suggested fix to issue #80893. I can actually hook Miri in there now.

I also fixed what I believe to be a typo in the option's help text.

3 years agoRollup merge of #80922 - spastorino:revert-inline-always-in-debug, r=wesleywiser
Dylan DPC [Wed, 13 Jan 2021 02:20:23 +0000 (03:20 +0100)]
Rollup merge of #80922 - spastorino:revert-inline-always-in-debug, r=wesleywiser

Revert "Auto merge of #76896 - spastorino:codegen-inline-fns2

This reverts commit ddf2cc7f8eb34f1a63b491d6a52e3e8208393c09, reversing
changes made to 937f629535f38c655267f1ed21ce6830f592f5df.

As `@alexcrichton` pointed out in https://github.com/rust-lang/rust/issues/80916 there's a problem with the taken approach.

3 years agoRollup merge of #80859 - jsgf:fix-pretty-remap, r=davidtwco
Dylan DPC [Wed, 13 Jan 2021 02:20:21 +0000 (03:20 +0100)]
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

3 years agoRollup merge of #80796 - cuviper:llvm-11.0.1, r=nikic
Dylan DPC [Wed, 13 Jan 2021 02:20:19 +0000 (03:20 +0100)]
Rollup merge of #80796 - cuviper:llvm-11.0.1, r=nikic

Update to LLVM 11.0.1

This updates to a new LLVM branch, rebased on the upstream `llvmorg-11.0.1`. All our patches applied cleanly except the fortanix unwind changes, which just needed a small adjustment in cmake files.

r? `@nikic`
Fixes https://github.com/rust-lang/rust/issues/73722

3 years agoRollup merge of #80736 - KodrAus:feat/lazy-resolve, r=dtolnay
Dylan DPC [Wed, 13 Jan 2021 02:20:17 +0000 (03:20 +0100)]
Rollup merge of #80736 - KodrAus:feat/lazy-resolve, r=dtolnay

use Once instead of Mutex to manage capture resolution

For #78299

This allows us to return borrows of the captured backtrace frames that are tied to a borrow of the Backtrace itself, instead of to some short-lived Mutex guard.

We could alternatively share `&Mutex<Capture>`s and lock on-demand, but then we could potentially forget to call `resolve()` before working with the capture. It also makes it semantically clearer what synchronization is needed on the capture.

cc `@seanchen1991` `@rust-lang/project-error-handling`

3 years agoRollup merge of #80662 - rxrbln:master, r=estebank
Dylan DPC [Wed, 13 Jan 2021 02:20:15 +0000 (03:20 +0100)]
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.

3 years agoRollup merge of #80232 - bugadani:roundtrip, r=estebank
Dylan DPC [Wed, 13 Jan 2021 02:20:13 +0000 (03:20 +0100)]
Rollup merge of #80232 - bugadani:roundtrip, r=estebank

Remove redundant def_id lookups

Simplify `DefId -> LocalDefId -> HirId -> LocalDefId -> DefId` chains.

3 years agoRollup merge of #79588 - estebank:issue-79187, r=oli-obk
Dylan DPC [Wed, 13 Jan 2021 02:20:11 +0000 (03:20 +0100)]
Rollup merge of #79588 - estebank:issue-79187, r=oli-obk

Provide more information for HRTB lifetime errors involving closures

3 years agoRollup merge of #78901 - arora-aman:fix_closure_coerce, r=estebank
Dylan DPC [Wed, 13 Jan 2021 02:20:09 +0000 (03:20 +0100)]
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`

3 years agoAuto merge of #79322 - jyn514:refactor-impl, r=estebank
bors [Wed, 13 Jan 2021 01:40:41 +0000 (01:40 +0000)]
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?

3 years agoSeparate out a `hir::Impl` struct
Joshua Nelson [Sun, 22 Nov 2020 22:46:21 +0000 (17:46 -0500)]
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.

3 years agoSkip promoted mir of struct constructors & enum constructors
Tomasz Miąsko [Wed, 13 Jan 2021 00:00:00 +0000 (00:00 +0000)]
Skip promoted mir of struct constructors & enum constructors

3 years agoConsistently avoid constructing optimized MIR when not doing codegen
Tomasz Miąsko [Tue, 12 Jan 2021 00:00:00 +0000 (00:00 +0000)]
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.

3 years agoAuto merge of #79670 - Nadrieril:uninhabited-query, r=estebank
bors [Tue, 12 Jan 2021 22:58:42 +0000 (22:58 +0000)]
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

3 years agoProvide more information for HRTB lifetime errors involving closures
Esteban Küber [Tue, 1 Dec 2020 08:10:13 +0000 (00:10 -0800)]
Provide more information for HRTB lifetime errors involving closures

3 years agoMake `DefIdForest` cheaper to clone
Nadrieril [Thu, 3 Dec 2020 01:52:24 +0000 (01:52 +0000)]
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.

3 years agomove WriteCloneIntoRaw into alloc::alloc
Josh Stone [Tue, 12 Jan 2021 20:24:28 +0000 (12:24 -0800)]
move WriteCloneIntoRaw into alloc::alloc

3 years agoBless profiler run make tests
Matthew Jasper [Tue, 12 Jan 2021 20:22:09 +0000 (20:22 +0000)]
Bless profiler run make tests

3 years agoReorder MIR encoding checks
Tomasz Miąsko [Tue, 5 Jan 2021 00:00:00 +0000 (00:00 +0000)]
Reorder MIR encoding checks

Start from least expensive checks when deciding whether to encode MIR or not.

No functional changes intended.

3 years agoAuto merge of #80009 - jumbatm:issue79581-overeager-clashing-extern-decl, r=alexcrichton
bors [Tue, 12 Jan 2021 20:13:50 +0000 (20:13 +0000)]
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`

3 years agoTurn type inhabitedness into a query
Nadrieril [Thu, 3 Dec 2020 00:25:04 +0000 (00:25 +0000)]
Turn type inhabitedness into a query

3 years agoAdd tests for uninhabited types
Nadrieril [Wed, 2 Dec 2020 23:11:29 +0000 (23:11 +0000)]
Add tests for uninhabited types

3 years agoDeduplicate some tests using revisions
Nadrieril [Wed, 2 Dec 2020 20:24:20 +0000 (20:24 +0000)]
Deduplicate some tests using revisions

3 years agoPrevent potential bug resulting from changing crate_hash query name
Tyson Nottingham [Mon, 11 Jan 2021 21:31:43 +0000 (13:31 -0800)]
Prevent potential bug resulting from changing crate_hash query name

3 years agoReturn to defining crate_hash similarly to other query providers
Tyson Nottingham [Wed, 6 Jan 2021 20:41:36 +0000 (12:41 -0800)]
Return to defining crate_hash similarly to other query providers

3 years agoRemove DepKind::CrateMetadata and pre-allocation of DepNodes
Tyson Nottingham [Fri, 1 Jan 2021 22:06:17 +0000 (14:06 -0800)]
Remove DepKind::CrateMetadata and pre-allocation of DepNodes

Remove much of the special-case handling around crate metadata
dependency tracking by replacing `DepKind::CrateMetadata` and the
pre-allocation of corresponding `DepNodes` with on-demand invocation
of the `crate_hash` query.

3 years agoAuto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelix
bors [Tue, 12 Jan 2021 17:26:56 +0000 (17:26 +0000)]
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).

3 years agoSimplify regression test
Tristan Dannenberg [Tue, 12 Jan 2021 17:18:10 +0000 (18:18 +0100)]
Simplify regression test

Co-authored-by: Joshua Nelson <joshua@yottadb.com>
3 years agoUpdate help message and add regression test
Tristan Dannenberg [Tue, 12 Jan 2021 16:29:47 +0000 (17:29 +0100)]
Update help message and add regression test

3 years agoFix rustdoc --test-builder argument parsing
Tristan Dannenberg [Mon, 11 Jan 2021 19:35:58 +0000 (20:35 +0100)]
Fix rustdoc --test-builder argument parsing

3 years agoCoverage computation needs access to the MIR, too
oli [Tue, 12 Jan 2021 15:12:03 +0000 (15:12 +0000)]
Coverage computation needs access to the MIR, too

3 years agoAuto merge of #80517 - wabain:issue-77880-infer-error-try-conversion-msg, r=davidtwco
bors [Tue, 12 Jan 2021 14:42:37 +0000 (14:42 +0000)]
Auto merge of #80517 - wabain:issue-77880-infer-error-try-conversion-msg, r=davidtwco

Enhance type inference errors involving the `?` operator

This patch adds a special-cased note on type inference errors when the error span points to a `?` return. It also makes the primary label for such errors "cannot infer type of `?` error" in cases where before we would have only said "cannot infer type".

One beneficiary of this change is async blocks, where we can't explicitly annotate the return type and so may not generate any other help (#77880); this lets us at least print the error type we're converting from and anything we know about the type we can't fully infer. More generally, it signposts that an implicit conversion is happening that may have impeded type inference the user was expecting. We already do something similar for [mismatched type errors](https://github.com/rust-lang/rust/blob/2987785df3d46d5ff144a5c67fbb8f5cca798d78/src/test/ui/try-block/try-block-bad-type.stderr#L7).

The check for a relevant `?` operator is built into the existing HIR traversal which looks for places that could be annotated to resolve the error. That means we could identify `?` uses anywhere in the function that output the type we can't infer, but this patch just sticks to adding the note if the primary span given for the error has the operator; if there are other expressions where the type occurs and one of them is selected for the error instead, it's more likely that the `?` operator's implicit conversion isn't the sole cause of the inference failure and that adding an additional diagnostic would just be noise. I added a ui test for one such case.

The data about the `?` conversion is passed around in a `UseDiagnostic` enum that in theory could be used to add more of this kind of note in the future. It was also just easier to pass around than something with a more specific name. There are some follow-up refactoring commits for the code that generates the error label, which was already pretty involved and made a bit more complicated by this change.

3 years agoAuto merge of #80499 - matthiaskrgr:red_clos, r=estebank
bors [Tue, 12 Jan 2021 11:20:47 +0000 (11:20 +0000)]
Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank

remove redundant closures (clippy::redundant_closure)

3 years agoAuto merge of #80939 - JohnTitor:rollup-pymns4q, r=JohnTitor
bors [Tue, 12 Jan 2021 08:38:47 +0000 (08:38 +0000)]
Auto merge of #80939 - JohnTitor:rollup-pymns4q, r=JohnTitor

Rollup of 8 pull requests

Successful merges:

 - #79757 (Replace tabs earlier in diagnostics)
 - #80600 (Add `MaybeUninit` method `array_assume_init`)
 - #80880 (Move some tests to more reasonable directories)
 - #80897 (driver: Use `atty` instead of rolling our own)
 - #80898 (Add another test case for #79808)
 - #80917 (core/slice: remove doc comment about scoped borrow)
 - #80927 (Replace a simple `if let` with the `matches` macro)
 - #80930 (fix typo in trait method mutability mismatch help)

Failed merges:

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

3 years agoRollup merge of #80930 - euclio:trait-method-mutability-help, r=estebank
Yuki Okushi [Tue, 12 Jan 2021 07:13:35 +0000 (16:13 +0900)]
Rollup merge of #80930 - euclio:trait-method-mutability-help, r=estebank

fix typo in trait method mutability mismatch help

3 years agoRollup merge of #80927 - LingMan:matches, r=estebank
Yuki Okushi [Tue, 12 Jan 2021 07:13:33 +0000 (16:13 +0900)]
Rollup merge of #80927 - LingMan:matches, r=estebank

Replace a simple `if let` with the `matches` macro

`@rustbot` modify labels +C-cleanup +T-compiler

3 years agoRollup merge of #80917 - epilys:patch-1, r=jyn514
Yuki Okushi [Tue, 12 Jan 2021 07:13:31 +0000 (16:13 +0900)]
Rollup merge of #80917 - epilys:patch-1, r=jyn514

core/slice: remove doc comment about scoped borrow

There's no need to scope the borrow in the doc example due to NLL.

[Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20v%20%3D%20%5B1%2C%200%2C%203%2C%200%2C%205%2C%206%5D%3B%0A%0A%20%20%20%20let%20(left%2C%20right)%20%3D%20v.split_at_mut(2)%3B%0A%20%20%20%20assert_eq!(left%2C%20%5B1%2C%200%5D)%3B%0A%20%20%20%20assert_eq!(right%2C%20%5B3%2C%200%2C%205%2C%206%5D)%3B%0A%20%20%20%20left%5B1%5D%20%3D%202%3B%0A%20%20%20%20right%5B1%5D%20%3D%204%3B%0A%0A%20%20%20%20assert_eq!(v%2C%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%206%5D)%3B%0A%7D%0A) where changed code compiles

3 years agoRollup merge of #80898 - JohnTitor:vecdeque-another-case, r=lcnr
Yuki Okushi [Tue, 12 Jan 2021 07:13:29 +0000 (16:13 +0900)]
Rollup merge of #80898 - JohnTitor:vecdeque-another-case, r=lcnr

Add another test case for #79808

Taken from #80293.
Closes #80293

r? `@lcnr`

3 years agoRollup merge of #80897 - camelid:atty, r=jyn514
Yuki Okushi [Tue, 12 Jan 2021 07:13:28 +0000 (16:13 +0900)]
Rollup merge of #80897 - camelid:atty, r=jyn514

driver: Use `atty` instead of rolling our own

Fixes #80888.

Rationale:

- `atty` is widely used in the Rust ecosystem
- We already use it (in `rustc_errors` and other places)
- We shouldn't be rolling our own TTY detector when there's a
  widely-used, well-tested package that we can use

3 years agoRollup merge of #80880 - c410-f3r:tests-tests-tests, r=petrochenkov
Yuki Okushi [Tue, 12 Jan 2021 07:13:26 +0000 (16:13 +0900)]
Rollup merge of #80880 - c410-f3r:tests-tests-tests, r=petrochenkov

Move some tests to more reasonable directories

The idea is to move `issues`/`ui` tests in small batches

r? `@petrochenkov`

3 years agoRollup merge of #80600 - CoffeeBlend:maybe_uninit_array_assume_init, r=dtolnay
Yuki Okushi [Tue, 12 Jan 2021 07:13:24 +0000 (16:13 +0900)]
Rollup merge of #80600 - CoffeeBlend:maybe_uninit_array_assume_init, r=dtolnay

Add `MaybeUninit` method `array_assume_init`

When initialising an array element-by-element, the conversion to the initialised array is done through `mem::transmute`, which is both ugly and does not work with const generics (see #61956). This PR proposes the associated method `array_assume_init`, matching the style of `slice_assume_init_*`:

```rust
unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T; N];
```

Example:
```rust
let mut array: [MaybeUninit<i32>; 3] = MaybeUninit::uninit_array();
array[0].write(0);
array[1].write(1);
array[2].write(2);

// SAFETY: Now safe as we initialised all elements
let array: [i32; 3] = unsafe {
     MaybeUninit::array_assume_init(array)
};
```

Things I'm unsure about:
* Should this be a method of array instead?
* Should the function be const?

3 years agoRollup merge of #79757 - jryans:long-line-tab-handling-early-expand, r=estebank
Yuki Okushi [Tue, 12 Jan 2021 07:13:15 +0000 (16:13 +0900)]
Rollup merge of #79757 - jryans:long-line-tab-handling-early-expand, r=estebank

Replace tabs earlier in diagnostics

This replaces tabs earlier in the diagnostics emitting process, which allows various margin calculations to ignore the existence of tabs. It does add a string copy for the source lines that are emitted.

Fixes https://github.com/rust-lang/rust/issues/78438

r? `@estebank`

3 years agoAuto merge of #80463 - tgnottingham:incr_comp_serial_mem_usage, r=oli-obk
bors [Tue, 12 Jan 2021 05:51:40 +0000 (05:51 +0000)]
Auto merge of #80463 - tgnottingham:incr_comp_serial_mem_usage, r=oli-obk

Serialize incr comp structures to file via fixed-size buffer

Reduce a large memory spike that happens during serialization by writing
the incr comp structures to file by way of a fixed-size buffer, rather
than an unbounded vector.

Effort was made to keep the instruction count close to that of the
previous implementation. However, buffered writing to a file inherently
has more overhead than writing to a vector, because each write may
result in a handleable error. To reduce this overhead, arrangements are
made so that each LEB128-encoded integer can be written to the buffer
with only one capacity and error check. Higher-level optimizations in
which entire composite structures can be written with one capacity and
error check are possible, but would require much more work.

The performance is mostly on par with the previous implementation, with
small to moderate instruction count regressions. The memory reduction is
significant, however, so it seems like a worth-while trade-off.

3 years agodriver: Use `atty` instead of rolling our own
Camelid [Mon, 11 Jan 2021 02:07:05 +0000 (18:07 -0800)]
driver: Use `atty` instead of rolling our own

Rationale:

- `atty` is widely used in the Rust ecosystem
- We already use it (in `rustc_errors` and other places)
- We shouldn't be rolling our own TTY detector when there's a
  widely-used, well-tested package that we can use

3 years agoAdd docs on performance
Camelid [Tue, 12 Jan 2021 03:17:13 +0000 (19:17 -0800)]
Add docs on performance

3 years agoUpdate src/test/ui/async-await/issues/issue-78938-async-block.stderr
1000teslas [Tue, 12 Jan 2021 03:12:12 +0000 (14:12 +1100)]
Update src/test/ui/async-await/issues/issue-78938-async-block.stderr

Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
3 years agoAuto merge of #76580 - rokob:iss76011, r=estebank
bors [Tue, 12 Jan 2021 02:56:51 +0000 (02:56 +0000)]
Auto merge of #76580 - rokob:iss76011, r=estebank

Suggest async {} for async || {}

Fixes #76011

This adds support for adding help diagnostics to the feature gating checks and
then uses it for the async_closure gate to add the extra bit of help
information as described in the issue.

3 years agoRename `rustc_middle::lint::LevelSource` to `LevelAndSource`
pierwill [Tue, 12 Jan 2021 02:02:09 +0000 (18:02 -0800)]
Rename `rustc_middle::lint::LevelSource` to `LevelAndSource`

3 years agoMove directly when Rc/Arc::make_mut splits from Weak
Josh Stone [Tue, 12 Jan 2021 01:32:21 +0000 (17:32 -0800)]
Move directly when Rc/Arc::make_mut splits from Weak

When only other `Weak` references remain, we can directly move the data
into the new unique allocation as a plain memory copy.

3 years agoSpecialize Rc/Arc::make_mut clones to try to avoid locals
Josh Stone [Fri, 8 Jan 2021 21:02:27 +0000 (13:02 -0800)]
Specialize Rc/Arc::make_mut clones to try to avoid locals

As we did with `Box`, we can allocate an uninitialized `Rc` or `Arc`
beforehand, giving the optimizer a chance to skip the local value for
regular clones, or avoid any local altogether for `T: Copy`.

3 years agoSpecialize Box clones to try to avoid locals
Josh Stone [Fri, 8 Jan 2021 21:02:23 +0000 (13:02 -0800)]
Specialize Box clones to try to avoid locals

For generic `T: Clone`, we can allocate an uninitialized box beforehand,
which gives the optimizer a chance to create the clone directly in the
heap. For `T: Copy`, we can go further and do a simple memory copy,
regardless of optimization level.

3 years agoReplace a simple `if let` with the `matches` macro
LingMan [Mon, 11 Jan 2021 21:22:04 +0000 (22:22 +0100)]
Replace a simple `if let` with the `matches` macro

3 years agoFix implementation
CoffeeBlend [Tue, 12 Jan 2021 00:39:10 +0000 (01:39 +0100)]
Fix implementation

3 years agofix typo in trait method mutability mismatch help
Andy Russell [Tue, 12 Jan 2021 00:27:38 +0000 (19:27 -0500)]
fix typo in trait method mutability mismatch help

3 years agoAuto merge of #80928 - JohnTitor:rollup-sgerm3j, r=JohnTitor
bors [Tue, 12 Jan 2021 00:14:46 +0000 (00:14 +0000)]
Auto merge of #80928 - JohnTitor:rollup-sgerm3j, r=JohnTitor

Rollup of 9 pull requests

Successful merges:

 - #79997 (Emit a reactor for cdylib target on wasi)
 - #79998 (Use correct ABI for wasm32 by default)
 - #80042 (Split a func into cold/hot parts, reducing binary size)
 - #80324 (Explain method-call move errors in loops)
 - #80864 (std/core docs: fix wrong link in PartialEq)
 - #80870 (resolve: Simplify built-in macro table)
 - #80885 (rustdoc: Resolve `&str` as `str`)
 - #80904 (Fix small typo)
 - #80923 (Merge different function exits)

Failed merges:

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

3 years agodifferentiate functions in extern-compare-with-return-type.rs
Josh Stone [Mon, 11 Jan 2021 23:13:26 +0000 (15:13 -0800)]
differentiate functions in extern-compare-with-return-type.rs

3 years agoRollup merge of #80923 - LingMan:exits, r=varkor
Yuki Okushi [Mon, 11 Jan 2021 22:59:18 +0000 (07:59 +0900)]
Rollup merge of #80923 - LingMan:exits, r=varkor

Merge different function exits

`@rustbot` modify labels +C-cleanup +T-compiler

3 years agoRollup merge of #80904 - camelid:fix-small-typo, r=jonas-schievink
Yuki Okushi [Mon, 11 Jan 2021 22:59:16 +0000 (07:59 +0900)]
Rollup merge of #80904 - camelid:fix-small-typo, r=jonas-schievink

Fix small typo

transmutting -> transmuting

3 years agoRollup merge of #80885 - camelid:intra-doc-str-ref, r=jyn514
Yuki Okushi [Mon, 11 Jan 2021 22:59:15 +0000 (07:59 +0900)]
Rollup merge of #80885 - camelid:intra-doc-str-ref, r=jyn514

rustdoc: Resolve `&str` as `str`

People almost always are referring to `&str`, not `str`, so this will
save a manual link resolve in many cases.

Note that we already accept `&` (resolves to `reference`) in intra-doc
links, so this shouldn't cause breakage.

r? `@jyn514`

3 years agoRollup merge of #80870 - petrochenkov:bmactable, r=oli-obk
Yuki Okushi [Mon, 11 Jan 2021 22:59:13 +0000 (07:59 +0900)]
Rollup merge of #80870 - petrochenkov:bmactable, r=oli-obk

resolve: Simplify built-in macro table

We don't use full `SyntaxExtension`s from the table, only `SyntaxExtensionKind`s, and `Ident` in `register_builtin_macro` always had dummy span. This PR removes unnecessary data from the table and related function signatures.

Noticed when reviewing #80850.

3 years agoRollup merge of #80864 - ericseppanen:master, r=jyn514
Yuki Okushi [Mon, 11 Jan 2021 22:59:11 +0000 (07:59 +0900)]
Rollup merge of #80864 - ericseppanen:master, r=jyn514

std/core docs: fix wrong link in PartialEq

PartialEq doc was attempting to link to ``[`Eq`]`` but instead we got a link to `` `eq` ``. Disambiguate with `trait@Eq`.

You can see the bad link [here](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html) (Second sentence, "floating point types implement PartialEq but not Eq").

3 years agoRollup merge of #80324 - Aaron1011:loop-move-fn-self, r=oli-obk
Yuki Okushi [Mon, 11 Jan 2021 22:59:10 +0000 (07:59 +0900)]
Rollup merge of #80324 - Aaron1011:loop-move-fn-self, r=oli-obk

Explain method-call move errors in loops

PR #73708 added a more detailed explanation of move errors that occur
due to a call to a method that takes `self`. This PR extends that logic
to work when a move error occurs due to a method call in the previous
iteration of a loop.