Dylan DPC [Wed, 27 May 2020 01:09:23 +0000 (03:09 +0200)]
Rollup merge of #72626 - phimuemue:doubleendediter_doc, r=dtolnay
Add remark regarding DoubleEndedIterator
While reviewing https://github.com/rust-itertools/itertools/pull/442/commits/14293bd18f01b6bd4856816222f808f46603eccd#diff-2c16d2ada06ad2fd1fc754679646d471, I realized that a `DoubleEndedIterator` may yield different elements depending on whether it is traversed forwards or backwards. (Not only the *order*, but possibly also the yielded values.)
I found this remarkable, but could not find anything in the current docs, so I thought it may be worth mentioning this explicitly.
Unfortunately, I could not test these changes locally (`rustdoc` complains about `unresolved import`). Sorry if this causes headache.
If I should change something, please let me know. If it seems too trivial, feel free to just close this PR.
Dylan DPC [Wed, 27 May 2020 01:09:15 +0000 (03:09 +0200)]
Rollup merge of #72548 - rossmacarthur:add-mcve-for-50687, r=nikomatsakis
Add test for old compiler ICE when using `Borrow`
The original issue was caused by implementing `Borrow` on a local type and using the tokio-reactor crate which had this impl: https://github.com/tokio-rs/tokio/blob/tokio-0.1.4/tokio-reactor/src/poll_evented.rs#L547-L577
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.27.0 (3eda71b00 2018-06-19) running on x86_64-apple-darwin
```
Dylan DPC [Wed, 27 May 2020 01:09:12 +0000 (03:09 +0200)]
Rollup merge of #72533 - Diggsey:db-fix-arc-ub2, r=dtolnay
Resolve UB in Arc/Weak interaction (2)
Use raw pointers to avoid making any assertions about the data field.
Follow up from #72479, see that PR for more detail on the motivation.
@RalfJung I was able to avoid a lot of the changes to `Weak`, by making a helper type (`WeakInner`) - because of auto-deref and because the fields have the same name, the rest of the code continues to compile.
Dylan DPC [Tue, 26 May 2020 20:11:34 +0000 (22:11 +0200)]
Rollup merge of #72592 - ehuss:update-books, r=ehuss
Update books
## reference
7 commits in 892b928b565e35d25b6f9c47faee03b94bc41489..becdca9477c9eafa96a4eea5156fe7a2730d9dd2
2020-05-11 11:13:51 -0700 to 2020-05-21 21:08:02 +0100
- Update tuple index token. (rust-lang-nursery/reference#814)
- Fixes minor errors (rust-lang-nursery/reference#818)
- Update that macros can be deprecated. (rust-lang-nursery/reference#813)
- work on char/str descriptions (rust-lang-nursery/reference#809)
- cfg_attr needs a valid predicate (rust-lang-nursery/reference#812)
- Account for removal of UB in float-to-int casts (rust-lang-nursery/reference#810)
- Fix stray plus signs. (rust-lang-nursery/reference#811)
## book
6 commits in 6247be15a7f7509559f7981ee2209b9e0cc121df..e8a4714a9d8a6136a59b8e63544e149683876e36
2020-05-03 10:55:09 -0500 to 2020-05-25 10:29:27 -0500
- code is 1024 now, not 512
- Clean up install a bit
- We don't need build.sh anymore
- Fix CI status in README
- Port to github actions (rust-lang/book#2337)
- operating system -> allocator
## rust-by-example
5 commits in ab072b14393cbd9e8a1d1d75879bf51e27217bbb..7aa82129aa23e7e181efbeb8da03a2a897ef6afc
2020-05-09 08:46:39 -0300 to 2020-05-25 14:54:26 -0300
- Person of age 0 is alive (rust-lang/rust-by-example#1348)
- Gramatical fix in std/rc.md (rust-lang/rust-by-example#1347)
- Capture example should use String (rust-lang/rust-by-example#1331)
- Fix empty bound examples (rust-lang/rust-by-example#1343)
- Fix an inline comment in macros/repeat.md (rust-lang/rust-by-example#1344)
Dylan DPC [Tue, 26 May 2020 20:11:33 +0000 (22:11 +0200)]
Rollup merge of #72581 - samrat:allow-desugared-break-in-labeled-block, r=davidtwco
Allow unlabeled breaks from desugared `?` in labeled blocks
`?` is desugared into a `break` targeting the innermost `try` scope in which it resides. The `break` however will not have a label. https://github.com/rust-lang/rust/blob/master/src/librustc_ast_lowering/expr.rs#L1560
Since the `target` of the `break` is known, the compiler should not complain about an unlabeled jump for `break`s desugared from `?`.
Dylan DPC [Tue, 26 May 2020 20:11:29 +0000 (22:11 +0200)]
Rollup merge of #72342 - jsgf:warn-unused-deps, r=petrochenkov
Warn about unused crate deps
Implements #57274 by adding -Wunused-crate-dependencies. This will warn about any `--extern` option on the command line which isn't referenced by the crate source either via `use` or `extern crate`.
Crates which are added for some side effect but are otherwise unreferenced - such as for symbols they define - the warning can be suppressed with `use somecrate as _;`.
If a crate has multiple aliases (eg using `foo = { package = "bar" }` in `Cargo.toml`), then it will warn about each unused alias.
This does not consider crate added by some other means than `--extern`, including the standard library. It also doesn't consider any crate without `add_prelude` set (though I'm not sure about this).
Unfortunately this probably [does not yet work well with Cargo](https://github.com/rust-lang/rust/issues/57274#issuecomment-624839355) as it will over-specify crates, causing spurious warnings. As a result, this lint is "allow" by default and must be explicitly enabled either via `#![warn(unused_crate_deps)]` or with `-Wunused-crate-deps`.
Dylan DPC [Tue, 26 May 2020 20:11:26 +0000 (22:11 +0200)]
Rollup merge of #72294 - GuillaumeGomez:js-cleanup, r=kinnison
JS cleanup
The goal here is just to improve the source code a bit. I recommend to review one commit at a time, otherwise it might not make much sense. :)
The biggest commit is the second one: to prevent to have "global" variables declared in `main.js` (and thus prevent name conflict or overwriting), I moved such code into anonymous functions.
Dylan DPC [Tue, 26 May 2020 20:11:22 +0000 (22:11 +0200)]
Rollup merge of #72270 - RalfJung:lint-ref-to-packed, r=oli-obk
add a lint against references to packed fields
Creating a reference to an insufficiently aligned packed field is UB and should be disallowed, both inside and outside of `unsafe` blocks. However, currently there is no stable alternative (https://github.com/rust-lang/rust/issues/64490) so all we do right now is have a future incompatibility warning when doing this outside `unsafe` (https://github.com/rust-lang/rust/issues/46043).
This adds an allow-by-default lint. @retep998 suggested this can help early adopters avoid issues. It also means we can then do a crater run where this is deny-by-default as suggested by @joshtriplett.
I guess the main thing to bikeshed is the lint name. I am not particularly happy with "packed_references" as it sounds like the packed field has reference type. I chose this because it is similar to "safe_packed_borrows". What about "reference_to_packed" or "unaligned_reference" or so?
bors [Tue, 26 May 2020 17:38:47 +0000 (17:38 +0000)]
Auto merge of #71931 - alexcrichton:reproducible-macos, r=eddyb
Export ZERO_AR_DATE for macos linker invocations
This commit attempts to improve reproducibility of builds on macOS by
exporting the `ZERO_AR_DATE=1` environment variable for all invocations
of the linker. While it looks like this env var is targeted at just the
`ar` command (which does actually read this) it appears that recent-ish
versions of the linker *also* read this environment variable. This
env var forces the linker to set a deterministic zero value for the
mtime in the N_OSO field of the object file.
Currently it's believe that older versions of the linker will simply
ignore this env var, while newer versions will read it and produce a
deterministic output for compilations with debuginfo.
Alex Crichton [Tue, 5 May 2020 21:25:58 +0000 (14:25 -0700)]
Export ZERO_AR_DATE for macos linker invocations
This commit attempts to improve reproducibility of builds on macOS by
exporting the `ZERO_AR_DATE=1` environment variable for all invocations
of the linker. While it looks like this env var is targeted at just the
`ar` command (which does actually read this) it appears that recent-ish
versions of the linker *also* read this environment variable. This
env var forces the linker to set a deterministic zero value for the
mtime in the N_OSO field of the object file.
Currently it's believe that older versions of the linker will simply
ignore this env var, while newer versions will read it and produce a
deterministic output for compilations with debuginfo.
This will print a diagnostic for crates which are mentioned as `--extern`
arguments on the command line, but are never referenced from the source.
This diagnostic is controlled by `-Wunused-crate-dependencies` or
`#![warn(unused_crate_dependencies)]` and is "allow" by default.
There are cases where certain crates need to be linked in but are not
directly referenced - for example if they are providing symbols for C
linkage. In this case the warning can be suppressed with
`use needed_crate as _;`.
bors [Tue, 26 May 2020 01:43:40 +0000 (01:43 +0000)]
Auto merge of #71487 - rcoh:71471-shebang, r=petrochenkov
Fix bug in shebang handling
Shebang handling was too agressive in stripping out the first line in cases where it is actually _not_ a shebang, but instead, valid rust (#70528). This is a second attempt at resolving this issue (the first attempt was reverted, for, among other reasons, causing an ICE in certain cases (#71372, #71471).
The behavior is now codified by a number of UI tests, but simply:
For the first line to be a shebang, the following must all be true:
1. The line must start with `#!`
2. The line must contain a non-whitespace character after `#!`
3. The next character in the file, ignoring comments & whitespace must not be `[`
I believe this is a strict superset of what we used to allow, so perhaps a crater run is unnecessary, but probably not a terrible idea.
Dylan DPC [Mon, 25 May 2020 21:58:57 +0000 (23:58 +0200)]
Rollup merge of #72451 - ecstatic-morse:nrvo-type-mismatch, r=matthewjasper
Perform MIR NRVO even if types don't match
This is the most straightforward way to resolve #72428, but it could cause problems in codegen since the type of `_0` may no longer match the return type of the body.
Dylan DPC [Mon, 25 May 2020 21:58:53 +0000 (23:58 +0200)]
Rollup merge of #72061 - lcnr:const-inference-test, r=eddyb
add regression tests for stalled_on const vars
closes #70180
Afaict this has been fixed sometime after #70213
`trait_ref_type_vars` correctly adds const infers and I did not find any remaining `FIXME`s which correspond to this issue.
https://github.com/rust-lang/rust/blob/7c59a81a5fcbaaca311f744cd7c68d99bfbb05d3/src/librustc_trait_selection/traits/fulfill.rs#L555-L557
Added both examples from the issue as regression tests and renamed `trait_ref_type_vars` -> `trait_ref_infer_vars`.
bors [Mon, 25 May 2020 17:14:44 +0000 (17:14 +0000)]
Auto merge of #72575 - Dylan-DPC:rollup-zo679hv, r=Dylan-DPC
Rollup of 4 pull requests
Successful merges:
- #72153 (exhaustively check `ty::Kind` during structural match checking)
- #72308 (Emit a better diagnostic when function actually has a 'self' parameter)
- #72560 (Enable `glacier` command via triagebot)
- #72567 (Clean up E0608 explanation)
Dylan DPC [Mon, 25 May 2020 16:07:44 +0000 (18:07 +0200)]
Rollup merge of #72308 - Aaron1011:fix/hygiene-error-message, r=matthewjasper
Emit a better diagnostic when function actually has a 'self' parameter
Fixes #66898
When we are unable to resolve a reference to `self`, we current assume
that the containing function doesn't have a `self` parameter, and
emit an error message accordingly.
However, if the reference to `self` was created by a macro invocation,
then resolution will correctly fail, due to hygiene. In this case, we
don't want to tell the user that the containing fuction doesn't have a
'self' paramter if it actually has one.
This PR checks for the precense of a 'self' parameter, and adjusts the
error message we emit accordingly.
TODO: The exact error message we emit could probably be improved. Should
we explicitly mention hygiene?
Russell Cohen [Thu, 23 Apr 2020 19:51:12 +0000 (15:51 -0400)]
Fix bug in shebang handling
Shebang handling was too agressive in stripping out the first line in cases where it is actually _not_ a shebang, but instead, valid rust (#70528). This is a second attempt at resolving this issue (the first attempt was flawed, for, among other reasons, causing an ICE in certain cases (#71372, #71471).
The behavior is now codified by a number of UI tests, but simply:
For the first line to be a shebang, the following must all be true:
1. The line must start with `#!`
2. The line must contain a non whitespace character after `#!`
3. The next character in the file, ignoring comments & whitespace must not be `[`
I believe this is a strict superset of what we used to allow, so perhaps a crater run is unnecessary, but probably not a terrible idea.
bors [Mon, 25 May 2020 09:43:59 +0000 (09:43 +0000)]
Auto merge of #72562 - RalfJung:rollup-2ngjgwi, r=RalfJung
Rollup of 5 pull requests
Successful merges:
- #71940 (Add `len` and `slice_from_raw_parts` to `NonNull<[T]>`)
- #72525 (Miri casts: do not blindly rely on dest type)
- #72537 (Fix InlineAsmOperand expresions being visited twice during liveness checking)
- #72544 (librustc_middle: Rename upvars query to upvars_mentioned)
- #72551 (First draft documenting Debug stability.)
Ralf Jung [Mon, 25 May 2020 09:01:10 +0000 (11:01 +0200)]
Rollup merge of #72551 - alilleybrinker:document-debug-stability, r=KodrAus
First draft documenting Debug stability.
Debug implementations of std types aren't stable, and neither are derived Debug implementations for any types, including user-defined types. This commit adds a section to the Debug documentation noting this stability status.
Ralf Jung [Mon, 25 May 2020 09:01:03 +0000 (11:01 +0200)]
Rollup merge of #71940 - SimonSapin:nonnull-slice, r=kennytm
Add `len` and `slice_from_raw_parts` to `NonNull<[T]>`
This follows the precedent of the recently-added `<*const [T]>::len` (adding to its tracking issue https://github.com/rust-lang/rust/issues/71146) and `ptr::slice_from_raw_parts`.
Debug implementations of std types aren't stable, and neither are
derived Debug implementations for any types, including user-defined
types. This commit adds a section to the Debug documentatio noting this
stability status.
bors [Sun, 24 May 2020 22:11:12 +0000 (22:11 +0000)]
Auto merge of #72287 - Aaron1011:feature/min-token-collect, r=petrochenkov
Store tokens inside `ast::Expr`
This is a smaller version of #70091.
We now store captured tokens inside `ast::Expr`, which allows us to avoid some reparsing in `nt_to_tokenstream`. To try to mitigate the performance impact, we only collect tokens when we've seen an outer attribute.
This makes progress towards solving #43081. There are still many things left to do:
* Collect tokens for other AST items.
* Come up with a way to handle inner attributes (we need to be collecting tokens by the time we encounter them)
* Avoid re-parsing when a `#[cfg]` attr is used.
However, this is enough to fix spans for a simple example, which I've included as a test case.
bors [Sun, 24 May 2020 18:40:28 +0000 (18:40 +0000)]
Auto merge of #72539 - RalfJung:rollup-8yfidi8, r=RalfJung
Rollup of 5 pull requests
Successful merges:
- #72402 (Remove all uses of `NodeId` in `ResolverOutputs`)
- #72527 (bootstrap: propagate test-args to miri and clippy test suites)
- #72530 (Clean up E0602 explanation)
- #72532 (Use `dyn` trait syntax in more comments and docs)
- #72535 (Use sort_unstable_by in its own docs)
Ralf Jung [Sun, 24 May 2020 14:51:30 +0000 (16:51 +0200)]
Rollup merge of #72527 - RalfJung:miri-clippy-test-args, r=Mark-Simulacrum
bootstrap: propagate test-args to miri and clippy test suites
For Miri I verified this works. For clippy, unfortunately it doesn't seem to work as a stage 0 tool:
```
./x.py --stage 0 test src/tools/clippy --test-args init
```
gives
```
Compiling clippy-mini-macro-test v0.2.0 (/home/r/src/rust/rustc.3/src/tools/clippy/mini-macro)
error[E0658]: procedural macros cannot be expanded to expressions
--> src/tools/clippy/mini-macro/src/lib.rs:11:5
|
11 | / quote!(
12 | | #[allow(unused)]
13 | | fn needless_take_by_value(s: String) {
14 | | println!("{}", s.len());
... |
24 | | }
25 | | )
| |_____^
|
= note: see issue #54727 <https://github.com/rust-lang/rust/issues/54727> for more information
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable
Compiling proc-macro2 v1.0.3
Compiling syn v1.0.11
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.
error: could not compile `clippy-mini-macro-test`.
```
But propagating `--test-args` to the test suite seems to make sense regardless.
Cc @rust-lang/clippy
Ralf Jung [Sun, 24 May 2020 10:17:09 +0000 (12:17 +0200)]
Rollup merge of #72284 - Aaron1011:feature/inline-macro-did, r=petrochenkov
Remove `macro_defs` map
We now store the `DefId` directly in `ExpnKind::Macro`. This will allow
us to serialize `ExpnData` in PR #72121 without needing to manage a side
table.