]> git.lizzy.rs Git - rust.git/log
rust.git
4 years agoRollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung
Mazdak Farrokhzad [Sat, 21 Mar 2020 04:33:18 +0000 (05:33 +0100)]
Rollup merge of #70038 - DutchGhost:const-forget-tests, r=RalfJung

Remove the call that makes miri fail

Fixes the concern raised in https://github.com/rust-lang/rust/pull/69645/files#r392884274

cc @RalfJung

4 years agoRollup merge of #69997 - WaffleLapkin:option_zip, r=LukasKalbertodt
Mazdak Farrokhzad [Sat, 21 Mar 2020 04:33:16 +0000 (05:33 +0100)]
Rollup merge of #69997 - WaffleLapkin:option_zip, r=LukasKalbertodt

add `Option::{zip,zip_with}` methods under "option_zip" gate

This PR introduces 2 methods - `Option::zip` and `Option::zip_with` with
respective signatures:
- zip: `(Option<T>, Option<U>) -> Option<(T, U)>`
- zip_with: `(Option<T>, Option<U>, (T, U) -> R) -> Option<R>`
Both are under the feature gate "option_zip".

I'm not sure about the name "zip", maybe we can find a better name for this.
(I would prefer `union` for example, but this is a keyword :( )

--------------------------------------------------------------------------------

Recently in a russian rust begginers telegram chat a newbie asked (translated):
> Are there any methods for these conversions:
>
> 1. `(Option<A>, Option<B>) -> Option<(A, B)>`
> 2. `Vec<Option<T>> -> Option<Vec<T>>`
>
> ?

While second (2.) is clearly `vec.into_iter().collect::<Option<Vec<_>>()`, the
first one isn't that clear.

I couldn't find anything similar in the `core` and I've come to this solution:
```rust
let tuple: (Option<A>, Option<B>) = ...;
let res: Option<(A, B)> = tuple.0.and_then(|a| tuple.1.map(|b| (a, b)));
```

However this solution isn't "nice" (same for just `match`/`if let`), so I thought
that this functionality should be in `core`.

4 years agoRollup merge of #69033 - jonas-schievink:resume-with-context, r=tmandry
Mazdak Farrokhzad [Sat, 21 Mar 2020 04:33:15 +0000 (05:33 +0100)]
Rollup merge of #69033 - jonas-schievink:resume-with-context, r=tmandry

Use generator resume arguments in the async/await lowering

This removes the TLS requirement from async/await and enables it in `#![no_std]` crates.

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

I'm not confident the HIR lowering is completely correct, there seem to be quite a few undocumented invariants in there. The `async-std` and tokio test suites are passing with these changes though.

4 years agoRollup merge of #65097 - tmiasko:arc, r=Amanieu
Mazdak Farrokhzad [Sat, 21 Mar 2020 04:33:13 +0000 (05:33 +0100)]
Rollup merge of #65097 - tmiasko:arc, r=Amanieu

Make std::sync::Arc compatible with ThreadSanitizer

The memory fences used previously in Arc implementation are not properly
understood by thread sanitizer as synchronization primitives. This had
unfortunate effect where running any non-trivial program compiled with
`-Z sanitizer=thread` would result in numerous false positives.

Replace acquire fences with acquire loads to address the issue.

Fixes #39608.

4 years agoAuto merge of #69509 - RalfJung:debug-assert-write, r=eddyb
bors [Fri, 20 Mar 2020 19:02:32 +0000 (19:02 +0000)]
Auto merge of #69509 - RalfJung:debug-assert-write, r=eddyb

debug-assert ptr sanity in ptr::write

This is a re-submission of the parts that we removed from https://github.com/rust-lang/rust/pull/69208 due to ["interesting" test failures](https://github.com/rust-lang/rust/pull/69208#issuecomment-591310437).

Fixes https://github.com/rust-lang/rust/issues/53871
r? @Mark-Simulacrum @eddyb

4 years agoAuto merge of #70174 - JohnTitor:rollup-0lum0jh, r=JohnTitor
bors [Fri, 20 Mar 2020 15:58:34 +0000 (15:58 +0000)]
Auto merge of #70174 - JohnTitor:rollup-0lum0jh, r=JohnTitor

Rollup of 9 pull requests

Successful merges:

 - #69618 (Clarify the relationship between `forget()` and `ManuallyDrop`.)
 - #69768 (Compute the correct layout for variants of uninhabited enums)
 - #69935 (codegen/mir: support polymorphic `InstanceDef`s)
 - #70103 (Clean up E0437 explanation)
 - #70131 (Add regression test for TAIT lifetime inference (issue #55099))
 - #70133 (remove unused imports)
 - #70145 (doc: Add quote to .init_array)
 - #70146 (Clean up e0438 explanation)
 - #70150 (triagebot.toml: accept cleanup-crew)

Failed merges:

r? @ghost

4 years agoUpdate const_forget.rs
DutchGhost [Fri, 20 Mar 2020 09:36:40 +0000 (10:36 +0100)]
Update const_forget.rs

4 years agoRollup merge of #70150 - rust-lang:accept-felixes-typo, r=Mark-Simulacrum
Yuki Okushi [Fri, 20 Mar 2020 08:02:14 +0000 (17:02 +0900)]
Rollup merge of #70150 - rust-lang:accept-felixes-typo, r=Mark-Simulacrum

triagebot.toml: accept cleanup-crew

r? @Mark-Simulacrum

4 years agoRollup merge of #70146 - GuillaumeGomez:cleanup-e0438, r=Dylan-DPC
Yuki Okushi [Fri, 20 Mar 2020 08:02:12 +0000 (17:02 +0900)]
Rollup merge of #70146 - GuillaumeGomez:cleanup-e0438, r=Dylan-DPC

Clean up e0438 explanation

r? @Dylan-DPC

4 years agoRollup merge of #70145 - lzutao:patch-1, r=Dylan-DPC
Yuki Okushi [Fri, 20 Mar 2020 08:02:11 +0000 (17:02 +0900)]
Rollup merge of #70145 - lzutao:patch-1, r=Dylan-DPC

doc: Add quote to .init_array

The current formatting is not good without quotes:
![without-quote](https://i.imgur.com/RkIm4cr.png)

4 years agoRollup merge of #70133 - hermitcore:libpanic_unwind, r=nikomatsakis
Yuki Okushi [Fri, 20 Mar 2020 08:02:09 +0000 (17:02 +0900)]
Rollup merge of #70133 - hermitcore:libpanic_unwind, r=nikomatsakis

remove unused imports

patch is required to avoid compiler errors by building src/libpanic_unwind/hermit.rs

4 years agoRollup merge of #70131 - Aaron1011:fix/issue-55099-test, r=nikomatsakis
Yuki Okushi [Fri, 20 Mar 2020 08:02:08 +0000 (17:02 +0900)]
Rollup merge of #70131 - Aaron1011:fix/issue-55099-test, r=nikomatsakis

Add regression test for TAIT lifetime inference (issue #55099)

Fixes #55099

The minimized reproducer in issue #55099 now compiles successfully.
This commit adds a regression test for it.

4 years agoRollup merge of #70103 - GuillaumeGomez:cleanup-e0437, r=Dylan-DPC
Yuki Okushi [Fri, 20 Mar 2020 08:02:06 +0000 (17:02 +0900)]
Rollup merge of #70103 - GuillaumeGomez:cleanup-e0437, r=Dylan-DPC

Clean up E0437 explanation

r? @Dylan-DPC

4 years agoRollup merge of #69935 - davidtwco:issue-69925, r=eddyb
Yuki Okushi [Fri, 20 Mar 2020 08:02:05 +0000 (17:02 +0900)]
Rollup merge of #69935 - davidtwco:issue-69925, r=eddyb

codegen/mir: support polymorphic `InstanceDef`s

cc #69925

This PR modifies the use of `subst_and_normalize_erasing_regions` on parts of the MIR bodies returned from `instance_mir`, so that `InstanceDef::CloneShim` and `InstanceDef::DropGlue` (where there is a type) do not perform substitutions. This avoids double substitutions and enables polymorphic `InstanceDef`s.

r? @eddyb
cc @nikomatsakis

4 years agoRollup merge of #69768 - oli-obk:union_field_ice, r=eddyb,RalfJung
Yuki Okushi [Fri, 20 Mar 2020 08:02:03 +0000 (17:02 +0900)]
Rollup merge of #69768 - oli-obk:union_field_ice, r=eddyb,RalfJung

Compute the correct layout for variants of uninhabited enums

r? @eddyb
cc @RalfJung

fixes #69191
cc #69763

4 years agoRollup merge of #69618 - hniksic:mem-forget-doc-fix, r=RalfJung
Yuki Okushi [Fri, 20 Mar 2020 08:02:01 +0000 (17:02 +0900)]
Rollup merge of #69618 - hniksic:mem-forget-doc-fix, r=RalfJung

Clarify the relationship between `forget()` and `ManuallyDrop`.

As discussed on reddit, this commit addresses two issues with the
documentation of `mem::forget()`:

* The documentation of `mem::forget()` can confuse the reader because of the
  discrepancy between usage examples that show correct usage and the
  accompanying text which speaks of the possibility of double-free.  The
  text that says "if the panic occurs before `mem::forget` was called"
  refers to a variant of the second example that was never shown, modified
  to use `mem::forget` instead of `ManuallyDrop`.  Ideally the documentation
  should show both variants, so it's clear what it's talking about.

  Also, the double free could be fixed just by placing `mem::forget(v)`
  before the construction of `s`.  Since the lifetimes of `s` and `v`
  wouldn't overlap, there would be no point where panic could cause a double
  free.  This could be mentioned, and contrasted against the more robust fix
  of using `ManuallyDrop`.

* This sentence seems unjustified: "For some types, operations such as
  passing ownership (to a funcion like `mem::forget`) requires them to
  actually be fully owned right now [...]".  Unlike C++, Rust has no move
  constructors, its moves are (possibly elided) bitwise copies.  Even if you
  pass an invalid object to `mem::forget`, no harm should come to pass
  because `mem::forget` consumes the object and exists solely to prevent
  drop, so there no one left to observe the invalid state state.

4 years agoMake std::sync::Arc compatible with ThreadSanitizer
Tomasz Miąsko [Fri, 20 Mar 2020 00:00:00 +0000 (00:00 +0000)]
Make std::sync::Arc compatible with ThreadSanitizer

The memory fences used previously in Arc implementation are not properly
understood by ThreadSanitizer as synchronization primitives. This had
unfortunate effect where running any non-trivial program compiled with
`-Z sanitizer=thread` would result in numerous false positives.

Replace acquire fences with acquire loads when using ThreadSanitizer to
address the issue.

4 years agomake "other" in docs of `Option::{zip,zip_with}` monofont
Waffle [Thu, 19 Mar 2020 19:19:37 +0000 (22:19 +0300)]
make "other" in docs of `Option::{zip,zip_with}` monofont

4 years agoAuto merge of #69402 - GuillaumeGomez:extend-search, r=kinnison
bors [Thu, 19 Mar 2020 16:07:59 +0000 (16:07 +0000)]
Auto merge of #69402 - GuillaumeGomez:extend-search, r=kinnison

Extend search

I realized that when looking for "struct:String" in the rustdoc search for example, the "in arguments" and "returned" tabs were always empty. After some investigation, I realized it was because we only provided the name, and not the type, making it impossible to pass the "type filtering" check.

To resolve this, I added the type alongside the name. Note for the future: we could improve this by instead only registering the path id and use the path dictionary directly. The only problem with that solution (which I already tested) is that it becomes complicated for types in other crates. It'd force us to handle both case with an id and a case with `(name, type)`. I found the current PR big enough to not want to provide it directly. However, I think this is definitely worth it to make it work this way in the future.

About the two tests I added: they don't have much interest except checking that we actually have something returned in the search in the cases of a type filtering with and without literal search.

I also had to update a bit the test script to add the new locally global (haha) variable I created (`NO_TYPE_FILTER`). I added this variable to make the code easier to read than just "-1".

r? @kinnison

cc @ollie27

4 years agotriagebot.toml: accept typo due to pnkfelix
Mazdak Farrokhzad [Thu, 19 Mar 2020 14:38:31 +0000 (15:38 +0100)]
triagebot.toml: accept typo due to pnkfelix

4 years agoDon't hard-code the vector length in the examples.
Hrvoje Nikšić [Thu, 19 Mar 2020 12:56:48 +0000 (13:56 +0100)]
Don't hard-code the vector length in the examples.

Co-Authored-By: lzutao <taolzu@gmail.com>
4 years agoMinor re-wordings and typo fixes.
Hrvoje Nikšić [Wed, 18 Mar 2020 10:30:39 +0000 (11:30 +0100)]
Minor re-wordings and typo fixes.

Co-Authored-By: Ralf Jung <post@ralfj.de>
4 years agoRestore (and reword) the warning against passing invalid values to mem::forget.
Hrvoje Niksic [Wed, 4 Mar 2020 21:12:53 +0000 (22:12 +0100)]
Restore (and reword) the warning against passing invalid values to mem::forget.

As pointed out by Ralf Jung, dangling references and boxes are
undefined behavior as per
https://doc.rust-lang.org/reference/behavior-considered-undefined.html
and the Miri checker.

4 years agoClarify the relationship between `forget()` and `ManuallyDrop`.
Hrvoje Niksic [Sun, 1 Mar 2020 20:31:08 +0000 (21:31 +0100)]
Clarify the relationship between `forget()` and `ManuallyDrop`.

As discussed on reddit, this commit addresses two issues with the
documentation of `mem::forget()`:

* The documentation of `mem::forget()` can confuse the reader because of the
  discrepancy between usage examples that show correct usage and the
  accompanying text which speaks of the possibility of double-free.  The
  text that says "if the panic occurs before `mem::forget` was called"
  refers to a variant of the second example that was never shown, modified
  to use `mem::forget` instead of `ManuallyDrop`.  Ideally the documentation
  should show both variants, so it's clear what it's talking about.

  Also, the double free could be fixed just by placing `mem::forget(v)`
  before the construction of `s`.  Since the lifetimes of `s` and `v`
  wouldn't overlap, there would be no point where panic could cause a double
  free.  This could be mentioned, and contrasted against the more robust fix
  of using `ManuallyDrop`.

* This sentence seems unjustified: "For some types, operations such as
  passing ownership (to a funcion like `mem::forget`) requires them to
  actually be fully owned right now [...]".  Unlike C++, Rust has no move
  constructors, its moves are (possibly elided) bitwise copies.  Even if you
  pass an invalid object to `mem::forget`, no harm should come to pass
  because `mem::forget` consumes the object and exists solely to prevent
  drop, so there no one left to observe the invalid state state.

4 years agoClean up e0438 explanation
Guillaume Gomez [Thu, 19 Mar 2020 13:11:27 +0000 (14:11 +0100)]
Clean up e0438 explanation

4 years agoClean up E0437 explanation
Guillaume Gomez [Wed, 18 Mar 2020 13:13:48 +0000 (14:13 +0100)]
Clean up E0437 explanation

4 years agoAuto merge of #70137 - RalfJung:miri, r=RalfJung
bors [Thu, 19 Mar 2020 12:59:10 +0000 (12:59 +0000)]
Auto merge of #70137 - RalfJung:miri, r=RalfJung

update miri

Fixes https://github.com/rust-lang/rust/issues/70055
r? @ghost
Cc @oli-obk @Amanieu

4 years agodoc: Add quote to .init_array
lzutao [Thu, 19 Mar 2020 10:35:28 +0000 (17:35 +0700)]
doc: Add quote to .init_array

4 years agoAuto merge of #66131 - eddyb:local-def-id, r=petrochenkov
bors [Thu, 19 Mar 2020 09:18:49 +0000 (09:18 +0000)]
Auto merge of #66131 - eddyb:local-def-id, r=petrochenkov

rustc: use LocalDefId instead of DefIndex where possible.

That is, wherever `DefIndex` always referred to a "def" in the local crate, I replaced it with `LocalDefId`.
While `LocalDefId` already existed, it wasn't used a lot, but I hope I'm on the right track.

Unresolved questions:
* [x] ~~should `LocalDefId` implement `rustc_index::Idx`?~~
  * ~~this would get rid of a couple more `DefIndex` uses~~
* [x] ~~should `LocalDefId` be encoded/decoded as just a `DefIndex`?~~
  * ~~right now it's a bit messy, `LocalDefId` encodes/decodes like `DefId`~~
* [x] ~~should `DefId::assert_local` be named something else, like `expect_local`?~~

A future PR should change `tcx.hir().local_def_id(...)` to return `LocalDefId` instead of `DefId`, as changing it in this PR would be too noisy.

r? @michaelwoerister cc @nikomatsakis @petrochenkov @Zoxc

4 years agorustc: use LocalDefId instead of DefIndex in hir::map::definitions.
Eduard-Mihai Burtescu [Sun, 3 Nov 2019 12:36:59 +0000 (14:36 +0200)]
rustc: use LocalDefId instead of DefIndex in hir::map::definitions.

4 years agorustc: use LocalDefId instead of DefIndex in ich.
Eduard-Mihai Burtescu [Tue, 5 Nov 2019 16:44:07 +0000 (18:44 +0200)]
rustc: use LocalDefId instead of DefIndex in ich.

4 years agorustc: use LocalDefId instead of DefIndex in HirId.
Eduard-Mihai Burtescu [Wed, 18 Mar 2020 18:27:59 +0000 (20:27 +0200)]
rustc: use LocalDefId instead of DefIndex in HirId.

4 years agorustc: use LocalDefId instead of DefIndex in hir::lowering.
Eduard-Mihai Burtescu [Sun, 3 Nov 2019 19:29:40 +0000 (21:29 +0200)]
rustc: use LocalDefId instead of DefIndex in hir::lowering.

4 years agorustc: introduce DefId::as_local(self) -> Option<LocalDefId> and use it.
Eduard-Mihai Burtescu [Sun, 3 Nov 2019 18:48:08 +0000 (20:48 +0200)]
rustc: introduce DefId::as_local(self) -> Option<LocalDefId> and use it.

4 years agorustc: rename DefId::to_local to expect_local and use it instead of LocalDefId::from_...
Eduard-Mihai Burtescu [Sun, 3 Nov 2019 12:48:52 +0000 (14:48 +0200)]
rustc: rename DefId::to_local to expect_local and use it instead of LocalDefId::from_def_id.

4 years agorustc: make LocalDefId's index field public like DefId's is.
Eduard-Mihai Burtescu [Thu, 31 Oct 2019 18:48:13 +0000 (20:48 +0200)]
rustc: make LocalDefId's index field public like DefId's is.

4 years agorustc_typeck: remove dead impl for `DefIndex`.
Eduard-Mihai Burtescu [Thu, 31 Oct 2019 14:27:44 +0000 (16:27 +0200)]
rustc_typeck: remove dead impl for `DefIndex`.

4 years agorustc: use LocalDefId instead of DefIndex for query keys.
Eduard-Mihai Burtescu [Thu, 31 Oct 2019 13:32:07 +0000 (15:32 +0200)]
rustc: use LocalDefId instead of DefIndex for query keys.

4 years agoupdate miri
Ralf Jung [Thu, 19 Mar 2020 08:08:13 +0000 (09:08 +0100)]
update miri

4 years agoremove unused imports
Stefan Lankes [Thu, 19 Mar 2020 06:43:16 +0000 (07:43 +0100)]
remove unused imports

patch is required to avoid compiler errors by building src/libpanic_unwind/hermit.rs

4 years agoAuto merge of #70132 - Centril:rollup-oe8unsn, r=Centril
bors [Thu, 19 Mar 2020 05:57:57 +0000 (05:57 +0000)]
Auto merge of #70132 - Centril:rollup-oe8unsn, r=Centril

Rollup of 9 pull requests

Successful merges:

 - #68941 (Properly handle Spans that reference imported SourceFiles)
 - #69036 (rustc: don't resolve Instances which would produce malformed shims.)
 - #69443 (tidy: Better license checks.)
 - #69814 (Smaller and more correct generator codegen)
 - #69929 (Regenerate tables for Unicode 13.0.0)
 - #69959 (std: Don't abort process when printing panics in tests)
 - #69969 (unix: Set a guard page at the end of signal stacks)
 - #70005 ([rustdoc] Improve visibility for code blocks warnings)
 - #70088 (Use copy bound in atomic operations to generate simpler MIR)

Failed merges:

r? @ghost

4 years agoRollup merge of #70088 - tmiasko:atomic-copy, r=eddyb
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:41 +0000 (06:57 +0100)]
Rollup merge of #70088 - tmiasko:atomic-copy, r=eddyb

Use copy bound in atomic operations to generate simpler MIR

4 years agoRollup merge of #70005 - GuillaumeGomez:code-block-signs, r=kinnison
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:39 +0000 (06:57 +0100)]
Rollup merge of #70005 - GuillaumeGomez:code-block-signs, r=kinnison

[rustdoc] Improve visibility for code blocks warnings

It appeared that a lot of people didn't notice when a code block was meant to fail compilation or wasn't tested at all. The changes here make the colors less transparent and the icon bigger. So before it looked like this:

![old-light](https://user-images.githubusercontent.com/3050060/76687070-f1cdbb80-6620-11ea-9b73-0c787dc671f7.png)
![old-dark](https://user-images.githubusercontent.com/3050060/76687079-f4c8ac00-6620-11ea-90fb-e548329e01b4.png)

And now it looks like this:

![new-light](https://user-images.githubusercontent.com/3050060/76687092-fd20e700-6620-11ea-9ebb-2b6852f00899.png)
![new-dark](https://user-images.githubusercontent.com/3050060/76687091-fd20e700-6620-11ea-8fea-6854c8367b97.png)

cc @rust-lang/rustdoc
r? @kinnison

4 years agoRollup merge of #69969 - iximeow:sigstack-guard-page, r=cuviper
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:37 +0000 (06:57 +0100)]
Rollup merge of #69969 - iximeow:sigstack-guard-page, r=cuviper

unix: Set a guard page at the end of signal stacks

This mitigates possible issues when signal stacks overflow, which could
manifest as segfaults or in unlucky circumstances possible clobbering of
other memory values as stack overflows tend to enable.

I went ahead and made a PR for this because it's a pretty small change, though if I should open an issue/RFC for this and discuss there first I'll happily do so. I've also added some example programs that demonstrate the uncomfortably clobber-happy behavior we currently have, and the segfaults that could/should result instead, [here](https://github.com/iximeow/jubilant-train).

4 years agoRollup merge of #69959 - alexcrichton:fix-panic-in-print, r=Mark-Simulacrum
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:36 +0000 (06:57 +0100)]
Rollup merge of #69959 - alexcrichton:fix-panic-in-print, r=Mark-Simulacrum

std: Don't abort process when printing panics in tests

This commit fixes an issue when using `set_print` and friends, notably
used by libtest, to avoid aborting the process if printing panics. This
previously panicked due to borrowing a mutable `RefCell` twice, and this
is worked around by borrowing these cells for less time, instead
taking out and removing contents temporarily.

Closes #69558

4 years agoRollup merge of #69929 - cuviper:unicode-13.0.0, r=Mark-Simulacrum
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:34 +0000 (06:57 +0100)]
Rollup merge of #69929 - cuviper:unicode-13.0.0, r=Mark-Simulacrum

Regenerate tables for Unicode 13.0.0

4 years agoRollup merge of #69814 - jonas-schievink:gen-ret-unw, r=Zoxc
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:32 +0000 (06:57 +0100)]
Rollup merge of #69814 - jonas-schievink:gen-ret-unw, r=Zoxc

Smaller and more correct generator codegen

This removes unnecessary panicking branches in the resume function when the generator can not return or unwind, respectively.

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

It also addresses the correctness concerns wrt poisoning on unwind. These are not currently a soundness issue because any operation *inside* a generator that could possibly unwind will result in a cleanup path for dropping it, ultimately reaching a `Resume` terminator, which we already handled correctly. Future MIR optimizations might optimize that out, though.

r? @Zoxc

4 years agoRollup merge of #69443 - ehuss:tidy-license, r=skade,Mark-Simulacrum
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:30 +0000 (06:57 +0100)]
Rollup merge of #69443 - ehuss:tidy-license, r=skade,Mark-Simulacrum

tidy: Better license checks.

This implements some improvements to the license checks in tidy:

* Use `cargo_metadata` instead of parsing vendored crates. This allows license checks to run without vendoring enabled, and allows the checks to run on PR builds.
* Check for stale entries.
* Check that the licenses for exceptions are what we think they are.
* Verify exceptions do not leak into the runtime.

Closes #62618
Closes #62619
Closes #63238 (I think)

There are some substantive changes here. The follow licenses have changed from the original comments:

* openssl BSD+advertising clause to Apache-2.0
* pest MPL2 to MIT/Apache-2.0
* smallvec MPL2 to MIT/Apache-2.0
* clippy lints MPL2 to MIT OR Apache-2.0

4 years agoRollup merge of #69036 - eddyb:monoshim, r=nikomatsakis
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:28 +0000 (06:57 +0100)]
Rollup merge of #69036 - eddyb:monoshim, r=nikomatsakis

rustc: don't resolve Instances which would produce malformed shims.

There are some `InstanceDef` variants (shims and drop "glue") which contain a `Ty`, and that `Ty` is used in generating the shim MIR. But if that `Ty` mentions any generic parameters, the generated shim would refer to them (but they won't match the `Substs` of the `Instance`), or worse, generating the shim would fail because not enough of the type is known.

Ideally we would always produce a "skeleton" of the type, e.g. `(_, _)` for dropping any tuples with two elements, or `Vec<_>` for dropping any `Vec` value, but that's a lot of work, and they would still not match the `Substs` of the `Instance` as it exists today, so `Instance` would probably need to change.

By making `Instance::resolve` return `None` in the still-generic cases, we get behavior similar to specialization, where a default can only be used if there are no more generic parameters which would allow a more specialized `impl` to match.

<hr/>

This was found while testing the MIR inliner with #68965, because it was trying to inline shims.

cc @rust-lang/wg-mir-opt

4 years agoRollup merge of #68941 - Aaron1011:fix/imported-span, r=petrochenkov
Mazdak Farrokhzad [Thu, 19 Mar 2020 05:57:27 +0000 (06:57 +0100)]
Rollup merge of #68941 - Aaron1011:fix/imported-span, r=petrochenkov

Properly handle Spans that reference imported SourceFiles

Previously, metadata encoding used DUMMY_SP to represent any spans that
referenced an 'imported' SourceFile - e.g. a SourceFile from an upstream
dependency. This currently has no visible consequences, since these
kinds of spans don't currently seem to be emitted anywhere. However,
there's no reason that we couldn't start using such spans in
diagnostics.

This PR changes how we encode and decode spans in crate metadata. We
encode spans in one of two ways:

* 'Local' spans, which reference non-imported SourceFiles, are encoded
  exactly as before.
* 'Foreign' spans, which reference imported SourceFiles, are encoded
  with the CrateNum of their 'originating' crate. Additionally, their
'lo' and 'high' values are rebased on top of the 'originating' crate,
which allows them to be used with the SourceMap data encoded for that
crate.

To support this change, I've also made the following modifications:

* `DefId` and related structs are now moved to `rustc_span`. This allows
  us to use a `CrateNum` inside `SourceFile`. `CrateNum` has special
handling during deserialization (it gets remapped to be the proper
`CrateNum` from the point of view of the current compilation session),
so using a `CrateNum` instead of a plain integer 'workaround type' helps
to simplify deserialization.
* The `ExternalSource` enum is renamed to `ExternalSourceKind`. There is
now a struct called `ExternalSource`, which holds an
`ExternalSourceKind` along with the original line number information for
the file. This is used during `Span` serialization to rebase spans onto
their 'owning' crate.

4 years agoAdd regression test for TAIT lifetime inference (issue #55099)
Aaron Hill [Thu, 19 Mar 2020 04:13:06 +0000 (00:13 -0400)]
Add regression test for TAIT lifetime inference (issue #55099)

Fixes #55099

The minimized reproducer in issue #55099 now compiles successfully.
This commit adds a regression test for it.

4 years agoProperly handle Spans that reference imported SourceFiles
Aaron Hill [Fri, 7 Feb 2020 19:02:24 +0000 (14:02 -0500)]
Properly handle Spans that reference imported SourceFiles

Previously, metadata encoding used DUMMY_SP to represent any spans that
referenced an 'imported' SourceFile - e.g. a SourceFile from an upstream
dependency. These leads to sub-optimal error messages in certain cases
(see the included test).

This PR changes how we encode and decode spans in crate metadata. We
encode spans in one of two ways:

* 'Local' spans, which reference non-imported SourceFiles, are encoded
  exactly as before.
* 'Foreign' spans, which reference imported SourceFiles, are encoded
  with the CrateNum of their 'originating' crate. Additionally, their
'lo' and 'high' values are rebased on top of the 'originating' crate,
which allows them to be used with the SourceMap data encoded for that
crate.

The `ExternalSource` enum is renamed to `ExternalSourceKind`. There is
now a struct called `ExternalSource`, which holds an
`ExternalSourceKind` along with the original line number information for
the file. This is used during `Span` serialization to rebase spans onto
their 'owning' crate.

4 years agoAuto merge of #70118 - pietroalbini:rollup-pgjc90i, r=pietroalbini
bors [Thu, 19 Mar 2020 00:28:33 +0000 (00:28 +0000)]
Auto merge of #70118 - pietroalbini:rollup-pgjc90i, r=pietroalbini

Rollup of 2 pull requests

Successful merges:

 - #70112 (Rollup of 10 pull requests)
 - #70116 (ci: use python from the correct path)

Failed merges:

r? @ghost

4 years agoRollup merge of #70116 - pietroalbini:ci-fix-windows-python-path, r=Mark-Simulacrum
Pietro Albini [Wed, 18 Mar 2020 20:11:11 +0000 (21:11 +0100)]
Rollup merge of #70116 - pietroalbini:ci-fix-windows-python-path, r=Mark-Simulacrum

ci: use python from the correct path

Apparently the old path we were using for Python 2 on Windows was not documented, and eventually got removed. This switches our CI to use the correct path.

See https://github.com/rust-lang/rust/pull/70112#issuecomment-600760786 for the actual failure.

4 years agoRollup merge of #70112 - Centril:rollup-gpi5tbq, r=Centril
Pietro Albini [Wed, 18 Mar 2020 20:11:07 +0000 (21:11 +0100)]
Rollup merge of #70112 - Centril:rollup-gpi5tbq, r=Centril

Rollup of 10 pull requests

Successful merges:

 - #67749 (keyword docs for else and inkeyword docs for else and in.)
 - #69139 (clean up E0308 explanation)
 - #69189 (Erase regions in writeback)
 - #69837 (Use smaller discriminants for generators)
 - #69838 (Expansion-driven outline module parsing)
 - #69839 (Miri error reform)
 - #69899 (Make methods declared by `newtype_index` macro `const`)
 - #69920 (Remove some imports to the rustc crate)
 - #70075 (Fix repr pretty display)
 - #70106 (Tidy: fix running rustfmt twice)

Failed merges:

 - #70051 (Allow `hir().find` to return `None`)
 - #70074 (Expand: nix all fatal errors)

r? @ghost

4 years agoMove the const-forget test into ui tests
DutchGhost [Wed, 18 Mar 2020 20:08:52 +0000 (21:08 +0100)]
Move the const-forget test into ui tests

4 years agoci: use python from the correct path
Pietro Albini [Wed, 18 Mar 2020 17:57:37 +0000 (18:57 +0100)]
ci: use python from the correct path

Apparently the old path we were using for Python 2 on Windows was not
documented, and eventually got removed. This switches our CI to use the
correct path.

4 years agoRollup merge of #70106 - ehuss:fix-tidy-fmt-twice, r=Mark-Simulacrum
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:49 +0000 (18:03 +0100)]
Rollup merge of #70106 - ehuss:fix-tidy-fmt-twice, r=Mark-Simulacrum

Tidy: fix running rustfmt twice

`./x.py test tidy` runs rustfmt twice. This is because `Build::build` runs `execute_cli` twice (once dry, once not). This can be quite slow (and prints a bunch of things twice).

I'm not sure if this is really the best place to check the dry_run status.

4 years agoRollup merge of #70075 - GuillaumeGomez:fix-repr-display, r=petrochenkov
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:47 +0000 (18:03 +0100)]
Rollup merge of #70075 - GuillaumeGomez:fix-repr-display, r=petrochenkov

Fix repr pretty display

Fixes #70027.

r? @varkor

4 years agoRollup merge of #69920 - Centril:hir-cleanup, r=Zoxc
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:44 +0000 (18:03 +0100)]
Rollup merge of #69920 - Centril:hir-cleanup, r=Zoxc

Remove some imports to the rustc crate

- When we have `NestedVisitorMap::None`, we use `type Map = dyn intravisit::Map<'v>;` instead of the actual map. This doesn't actually result in dynamic dispatch (in the future we may want to use an associated type default to simplify the code).

- Use `rustc_session::` imports instead of `rustc::{session, lint}`.

r? @Zoxc

4 years agoRollup merge of #69899 - ecstatic-morse:const-idx-methods, r=oli-obk
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:42 +0000 (18:03 +0100)]
Rollup merge of #69899 - ecstatic-morse:const-idx-methods, r=oli-obk

Make methods declared by `newtype_index` macro `const`

Crates that use the macro to define an `Idx` type need to enable `#![feature(const_if_match, const_panic)]`.

4 years agoRollup merge of #69839 - RalfJung:miri-error-cleanup, r=oli-obk
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:40 +0000 (18:03 +0100)]
Rollup merge of #69839 - RalfJung:miri-error-cleanup, r=oli-obk

Miri error reform

Some time ago we started moving Miri errors into a few distinct categories, but we never classified all the old errors. That's what this PR does.

~~This is on top of https://github.com/rust-lang/rust/pull/69762; [relative diff](https://github.com/RalfJung/rust/compare/validity-errors...RalfJung:miri-error-cleanup).~~

r? @oli-obk

Fixes https://github.com/rust-lang/const-eval/issues/4

4 years agoRollup merge of #69838 - Centril:expand-module, r=petrochenkov
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:38 +0000 (18:03 +0100)]
Rollup merge of #69838 - Centril:expand-module, r=petrochenkov

Expansion-driven outline module parsing

After this PR, the parser will not do any conditional compilation or loading of external module files when `mod foo;` is encountered. Instead, the parser only leaves `mod foo;` in place in the AST, with no items filled in. Expansion later kicks in and will load the actual files and do the parsing. This entails that the following is now valid:

```rust
#[cfg(FALSE)]
mod foo {
    mod bar {
        mod baz; // `foo/bar/baz.rs` doesn't exist, but no error!
    }
}
```

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

r? @petrochenkov

4 years agoRollup merge of #69837 - jonas-schievink:gen-discr-opt, r=tmandry
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:37 +0000 (18:03 +0100)]
Rollup merge of #69837 - jonas-schievink:gen-discr-opt, r=tmandry

Use smaller discriminants for generators

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

I'm not yet sure about the runtime performance impact of this, so I'll try running this on some benchmarks (if I can find any). (Update: No impact on the benchmarks I've measured on)

* [x] Add test with a generator that has exactly 256 total states
* [x] Add test with a generator that has more than 256 states so that it needs to use a u16 discriminant
* [x] Add tests for the size of `Option<[generator]>`
* [x] Add tests for the `discriminant_value` intrinsic in all cases

4 years agoRollup merge of #69189 - matthewjasper:erase-the-world, r=nikomatsakis
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:35 +0000 (18:03 +0100)]
Rollup merge of #69189 - matthewjasper:erase-the-world, r=nikomatsakis

Erase regions in writeback

Regions in `TypeckTables` (except canonicalized user annotations) are now erased. Further, we no longer do lexical region solving on item bodies with `-Zborrowck=mir`.

cc #68261
r? @nikomatsakis

4 years agoRollup merge of #69139 - GuillaumeGomez:cleanup-e0308, r=Dylan-DPC
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:33 +0000 (18:03 +0100)]
Rollup merge of #69139 - GuillaumeGomez:cleanup-e0308, r=Dylan-DPC

clean up E0308 explanation

r? @Dylan-DPC

4 years agoRollup merge of #67749 - gilescope:keyword-in, r=Dylan-DPC
Mazdak Farrokhzad [Wed, 18 Mar 2020 17:03:31 +0000 (18:03 +0100)]
Rollup merge of #67749 - gilescope:keyword-in, r=Dylan-DPC

keyword docs for else and inkeyword docs for else and in.

First cut of else and in keyword docs. Comments and suggestions more than welcome.

4 years agoTidy: fix running rustfmt twice
Eric Huss [Wed, 18 Mar 2020 15:15:29 +0000 (08:15 -0700)]
Tidy: fix running rustfmt twice

4 years ago--bless windows test
Mazdak Farrokhzad [Tue, 17 Mar 2020 03:39:22 +0000 (04:39 +0100)]
--bless windows test

4 years agofix rebase fallout
Mazdak Farrokhzad [Sun, 15 Mar 2020 23:56:27 +0000 (00:56 +0100)]
fix rebase fallout

4 years agofix pre-expansion linting infra
Mazdak Farrokhzad [Sun, 15 Mar 2020 23:43:37 +0000 (00:43 +0100)]
fix pre-expansion linting infra

4 years agouse pretty-compare-only in a test
Mazdak Farrokhzad [Tue, 10 Mar 2020 06:21:40 +0000 (07:21 +0100)]
use pretty-compare-only in a test

4 years agotweak outline module parsing spans
Mazdak Farrokhzad [Mon, 9 Mar 2020 10:16:00 +0000 (11:16 +0100)]
tweak outline module parsing spans

4 years agoparser/expand: minor cleanup
Mazdak Farrokhzad [Mon, 9 Mar 2020 09:35:35 +0000 (10:35 +0100)]
parser/expand: minor cleanup

4 years agoadd test for stripped nested outline module
Mazdak Farrokhzad [Sun, 8 Mar 2020 21:48:24 +0000 (22:48 +0100)]
add test for stripped nested outline module

4 years ago{rustc_parse -> rustc_expand}::config
Mazdak Farrokhzad [Sun, 8 Mar 2020 21:32:25 +0000 (22:32 +0100)]
{rustc_parse -> rustc_expand}::config

4 years ago{rustc_parse::parser -> rustc_expand}::module
Mazdak Farrokhzad [Sun, 8 Mar 2020 21:21:37 +0000 (22:21 +0100)]
{rustc_parse::parser -> rustc_expand}::module

4 years agomove Directory -> parser::module
Mazdak Farrokhzad [Sun, 8 Mar 2020 21:10:37 +0000 (22:10 +0100)]
move Directory -> parser::module

4 years agoparse: module parsing -> item.rs
Mazdak Farrokhzad [Sun, 8 Mar 2020 20:50:01 +0000 (21:50 +0100)]
parse: module parsing -> item.rs

4 years agooutline modules: parse -> expand.
Mazdak Farrokhzad [Sun, 8 Mar 2020 12:36:20 +0000 (13:36 +0100)]
outline modules: parse -> expand.

4 years agoextract error_on_circular_module
Mazdak Farrokhzad [Sun, 8 Mar 2020 12:29:37 +0000 (13:29 +0100)]
extract error_on_circular_module

4 years agoextract parse_external_module
Mazdak Farrokhzad [Sun, 8 Mar 2020 11:33:15 +0000 (12:33 +0100)]
extract parse_external_module

4 years agode-fatalize outline module parsing
Mazdak Farrokhzad [Sun, 8 Mar 2020 11:19:27 +0000 (12:19 +0100)]
de-fatalize outline module parsing

4 years agoexpand: use push_directory
Mazdak Farrokhzad [Sun, 8 Mar 2020 10:18:26 +0000 (11:18 +0100)]
expand: use push_directory

4 years agodecouple eval_src_mod from Parser
Mazdak Farrokhzad [Sun, 8 Mar 2020 10:06:30 +0000 (11:06 +0100)]
decouple eval_src_mod from Parser

4 years agodecouple push_directory from Parser
Mazdak Farrokhzad [Sun, 8 Mar 2020 08:54:19 +0000 (09:54 +0100)]
decouple push_directory from Parser

4 years agodetach submod_path from Parser
Mazdak Farrokhzad [Sun, 8 Mar 2020 08:28:46 +0000 (09:28 +0100)]
detach submod_path from Parser

4 years agoextract error_on_circular_module
Mazdak Farrokhzad [Sat, 7 Mar 2020 18:53:25 +0000 (19:53 +0100)]
extract error_on_circular_module

4 years agoextract parse_mod
Mazdak Farrokhzad [Sat, 7 Mar 2020 19:19:52 +0000 (20:19 +0100)]
extract parse_mod

4 years agosubmod_path: use id.span
Mazdak Farrokhzad [Sat, 7 Mar 2020 18:41:24 +0000 (19:41 +0100)]
submod_path: use id.span

4 years agosimplify submod_path
Mazdak Farrokhzad [Sat, 7 Mar 2020 18:20:31 +0000 (19:20 +0100)]
simplify submod_path

4 years agoextract error_decl_mod_in_block
Mazdak Farrokhzad [Sat, 7 Mar 2020 18:15:35 +0000 (19:15 +0100)]
extract error_decl_mod_in_block

4 years agoextract error_cannot_declare_mod_here
Mazdak Farrokhzad [Sat, 7 Mar 2020 18:11:47 +0000 (19:11 +0100)]
extract error_cannot_declare_mod_here

4 years agosubmod_path_from_attr: simplify & document
Mazdak Farrokhzad [Sat, 7 Mar 2020 17:59:44 +0000 (18:59 +0100)]
submod_path_from_attr: simplify & document

4 years agostd: Don't abort process when printing panics in tests
Alex Crichton [Thu, 12 Mar 2020 20:03:48 +0000 (13:03 -0700)]
std: Don't abort process when printing panics in tests

This commit fixes an issue when using `set_print` and friends, notably
used by libtest, to avoid aborting the process if printing panics. This
previously panicked due to borrowing a mutable `RefCell` twice, and this
is worked around by borrowing these cells for less time, instead
taking out and removing contents temporarily.

Closes #69558

4 years agoincrease stack slack for x86_64-pc-windows-gnu
Ralf Jung [Wed, 18 Mar 2020 12:35:46 +0000 (13:35 +0100)]
increase stack slack for x86_64-pc-windows-gnu

4 years agofixes to `Option::{zip,zip_with}`
Waffle [Wed, 18 Mar 2020 08:02:29 +0000 (11:02 +0300)]
fixes to `Option::{zip,zip_with}`

- remove `#[inline]` attributes (see https://github.com/rust-lang/rust/pull/69997#discussion_r393942617)
- fill tracking issue in `#[unstable]` attributes
- slightly improve the docs

4 years agoadd `Option::{zip,zip_with}` methods under "option_zip" gate
Waffle [Fri, 13 Mar 2020 08:51:55 +0000 (11:51 +0300)]
add `Option::{zip,zip_with}` methods under "option_zip" gate

This commit introduces 2 methods - `Option::zip` and `Option::zip_with` with
respective signatures:
- zip: `(Option<T>, Option<U>) -> Option<(T, U)>`
- zip_with: `(Option<T>, Option<U>, (T, U) -> R) -> Option<R>`
Both are under the feature gate "option_zip".

I'm not sure about the name "zip", maybe we can find a better name for this.
(I would prefer `union` for example, but this is a keyword :( )

--------------------------------------------------------------------------------

Recently in a russian rust begginers telegram chat a newbie asked (translated):
> Are there any methods for these conversions:
>
> 1. `(Option<A>, Option<B>) -> Option<(A, B)>`
> 2. `Vec<Option<T>> -> Option<Vec<T>>`
>
> ?

While second (2.) is clearly `vec.into_iter().collect::<Option<Vec<_>>()`, the
first one isn't that clear.

I couldn't find anything similar in the `core` and I've come to this solution:
```rust
let tuple: (Option<A>, Option<B>) = ...;
let res: Option<(A, B)> = tuple.0.and_then(|a| tuple.1.map(|b| (a, b)));
```

However this solution isn't "nice" (same for just `match`/`if let`), so I thought
that this functionality should be in `core`.

4 years agoAuto merge of #69907 - ehuss:update-cargo, r=ehuss
bors [Wed, 18 Mar 2020 06:31:24 +0000 (06:31 +0000)]
Auto merge of #69907 - ehuss:update-cargo, r=ehuss

Update cargo

Update cargo

21 commits in bda50510d1daf6e9c53ad6ccf603da6e0fa8103f..7019b3ed3d539db7429d10a343b69be8c426b576
2020-03-02 18:05:34 +0000 to 2020-03-17 21:02:00 +0000
- Run through clippy (rust-lang/cargo#8015)
- Fix config profiles using "dev" in `cargo test`. (rust-lang/cargo#8012)
- Run CI on all PRs. (rust-lang/cargo#8011)
- Add unit-graph JSON output. (rust-lang/cargo#7977)
- Split workspace/validate() into multiple functions (rust-lang/cargo#8008)
- Use Option::as_deref (rust-lang/cargo#8005)
- De-duplicate edges (rust-lang/cargo#7993)
- Revert "Disable preserving mtimes on archives" (rust-lang/cargo#7935)
- Close the front door for clippy but open the back (rust-lang/cargo#7533)
- Fix CHANGELOG.md typos (rust-lang/cargo#7999)
- Update changelog note about crate-versions flag. (rust-lang/cargo#7998)
- Bump to 0.45.0, update changelog (rust-lang/cargo#7997)
- Bump libgit2 dependencies (rust-lang/cargo#7996)
- Avoid buffering large amounts of rustc output. (rust-lang/cargo#7838)
- Add "Updating" status for git submodules. (rust-lang/cargo#7989)
- WorkspaceResolve: Use descriptive lifetime label. (rust-lang/cargo#7990)
- Support old html anchors in manifest chapter. (rust-lang/cargo#7983)
- Don't create hardlink for library test and integrations tests, fixing rust-lang/cargo#7960 (rust-lang/cargo#7965)
- Partially revert change to filter debug_assertions. (rust-lang/cargo#7970)
- Try to better handle restricted crate names. (rust-lang/cargo#7959)
- Fix bug with new feature resolver and required-features. (rust-lang/cargo#7962)

4 years agoUpdate cargo
Eric Huss [Wed, 11 Mar 2020 06:16:19 +0000 (23:16 -0700)]
Update cargo