Mark Rousskov [Fri, 8 Jun 2018 23:21:03 +0000 (17:21 -0600)]
Rollup merge of #51394 - nnethercote:NCA-depths, r=nikomatsakis
Use scope tree depths to speed up `nearest_common_ancestor`.
This patch adds depth markings to all entries in the `ScopeTree`'s
`parent_map`. This change increases memory usage somewhat, but permits a
much faster algorithm to be used:
- If one scope has a greater depth than the other, the deeper scope is
moved upward until they are at equal depths.
- Then we move the two scopes upward in lockstep until they match.
This avoids the need to keep track of which scopes have already been
seen, which was the major part of the cost of the old algorithm. It also
reduces the number of child-to-parent moves (which are hash table
lookups) when the scopes start at different levels, because it never
goes past the nearest common ancestor the way the old algorithm did.
Finally, the case where one of the scopes is the root is now handled in
advance, because that is moderately common and lets us skip everything.
This change speeds up runs of several rust-perf benchmarks, the best by
6%.
A selection of the bigger improvements:
```
clap-rs-check
avg: -2.6% min: -6.6% max: 0.0%
syn-check
avg: -2.2% min: -5.0% max: 0.0%
style-servo-check
avg: -2.9%? min: -4.8%? max: 0.0%?
cargo-check
avg: -1.3% min: -2.8% max: 0.0%
sentry-cli-check
avg: -1.0% min: -2.1% max: 0.0%
webrender-check
avg: -0.9% min: -2.0% max: 0.0%
style-servo
avg: -0.9%? min: -1.8%? max: -0.0%?
ripgrep-check
avg: -0.7% min: -1.8% max: 0.1%
clap-rs
avg: -0.9% min: -1.6% max: -0.2%
regex-check
avg: -0.2% min: -1.3% max: 0.1%
syn
avg: -0.6% min: -1.3% max: 0.1%
hyper-check
avg: -0.5% min: -1.1% max: 0.0%
```
The idea came from multiple commenters on my blog and on Reddit. Thank you!
Mark Rousskov [Fri, 8 Jun 2018 23:21:00 +0000 (17:21 -0600)]
Rollup merge of #51360 - estebank:braces-around-literal-structs, r=nikomatsakis
Suggest parentheses when a struct literal needs them
When writing a struct literal in an expression that expects a block to
be started afterwards (like an `if` statement), do not suggest using the
same struct literal:
```
did you mean `S { /* fields * /}`?
```
Instead, suggest surrounding the expression with parentheses:
```
did you mean `(S { /* fields * /})`?
```
Fix #47360, #50090. Leaving #42982 open to come back to this problem with a better solution.
Mark Rousskov [Fri, 8 Jun 2018 23:20:58 +0000 (17:20 -0600)]
Rollup merge of #51276 - Havvy:dyn-trait-send-send, r=nikomatsakis
Dedup auto traits in trait objects.
Fixes #47010
Note that the test file `run-pass/trait-object-auto-dedup.rs` passes before and after this change. It's the `ui` test that changed from compiling to not compiling. Which does make this a breaking change, but I cannot imagine anybody actually being broken by it.
bors [Thu, 7 Jun 2018 23:06:39 +0000 (23:06 +0000)]
Auto merge of #51426 - kennytm:rollup, r=kennytm
Rollup of 9 pull requests
Successful merges:
- #51186 (Remove two redundant .nll.stderr files)
- #51283 (Deny #[cfg] and #[cfg_attr] on generic parameters.)
- #51368 (Fix the use of closures within #[panic_implementation])
- #51380 (Remove dependency on fmt_macros from typeck)
- #51389 (rustdoc: Fix missing stability and src links for inlined external macros)
- #51399 (NLL performance boost)
- #51407 (Update RLS and Rustfmt)
- #51417 (Revert #49719)
- #51420 (Tries to address the recent network issues)
kennytm [Thu, 7 Jun 2018 23:05:48 +0000 (07:05 +0800)]
Rollup merge of #51420 - kennytm:some-network-issues, r=Mark-Simulacrum
Tries to address the recent network issues
1. Set the DNS server to 8.8.8.8/8.8.4.4/1.1.1.1/1.0.0.1 to workaround the daily "Cannot resolve host" error these two weeks.
2. Remove the unnecessary command `gem update --system` (originally added as experiment of the "Could not find a valid gem" error, which turns out to be useless).
kennytm [Thu, 7 Jun 2018 23:05:44 +0000 (07:05 +0800)]
Rollup merge of #51399 - ngg:nll-performance, r=nikomatsakis
NLL performance boost
This makes compilation of the [inflate](https://github.com/rust-lang-nursery/rustc-perf/tree/master/collector/benchmarks/inflate) benchmark compile 2 times faster on my computer when NLL is enabled.
This does not fix the #51377 perfectly, it's still 4-5 times slower than without NLL, but it's a start.
kennytm [Thu, 7 Jun 2018 23:05:39 +0000 (07:05 +0800)]
Rollup merge of #51283 - kennytm:fix-51279-preempt-the-warning-song-and-dance, r=nikomatsakis
Deny #[cfg] and #[cfg_attr] on generic parameters.
Fix #51279.
Attributes on generic parameters are not expanded, meaning `#[cfg]`, `#[cfg_attr]` and attribute proc macros are entirely ignored on them.
This PR makes using the first two attributes an error, because if they are correctly expanded will affect the AST and change code behavior.
I'm beta-nominating this, because generic parameter attributes are stabilizing in 1.27, and if we did not reserve their usage, we may never be able to repurpose the meaning of these attributes in the Rust 2015 edition.
kennytm [Thu, 7 Jun 2018 23:05:38 +0000 (07:05 +0800)]
Rollup merge of #51186 - pnkfelix:remove-unneccessary-nll-stderr-files, r=oli-obk
Remove two redundant .nll.stderr files
It turns out that the diagnostics generated from NLL for these cases are now exactly the same as that produced by AST borrowck, and thus we can just fallback on those `.stderr` files that already exist for AST-borrowck.
Bravo!
(it is a good idea to remove these files, because it slightly reduces the amount of time humans will spend reviewing the .nll.stderr fileset...)
((it *might* be worthwhile trying to change the `compiletest` code to even issue a warning when two such files have equivalent contents... but I am not going so far as to try to implement that right now...))
bors [Wed, 6 Jun 2018 19:42:19 +0000 (19:42 +0000)]
Auto merge of #51263 - cramertj:futures-in-core, r=aturon
Add Future and task system to the standard library
This adds preliminary versions of the `std::future` and `std::task` modules in order to unblock development of async/await (https://github.com/rust-lang/rust/issues/50547). These shouldn't be considered as final forms of these libraries-- design questions about the libraries should be left on https://github.com/rust-lang/rfcs/pull/2418. Once that RFC (or a successor) is merged, these APIs will be adjusted as necessary.
bors [Wed, 6 Jun 2018 14:04:06 +0000 (14:04 +0000)]
Auto merge of #51201 - estebank:dotdot, r=petrochenkov
Accept `..` in incorrect position to avoid further errors
We currently give a specific message when encountering a `..` anywhere
other than the end of a pattern. Modify the parser to accept it (while
still emitting the error) so that we don't also trigger "missing fields
in pattern" errors afterwards.
Add suggestions to either remove trailing `,` or moving the `..` to the
end.
bors [Wed, 6 Jun 2018 11:17:15 +0000 (11:17 +0000)]
Auto merge of #51316 - oli-obk:const_err, r=nikomatsakis
Refactor the const eval diagnostic API
* no longer report "const eval error" for things that have typeck errors
* errors and lints have saner spans and messages
* unified the diagnostic logic (const eval errors were slightly different depending on where they were reported, and there was also code duplication between the different reporters)
* report errors if an erroneous constant is used inside a promoted (fixes most of #50814)
Use scope tree depths to speed up `nearest_common_ancestor`.
This patch adds depth markings to all entries in the `ScopeTree`'s
`parent_map`. This change increases memory usage somewhat, but permits a
much faster algorithm to be used:
- If one scope has a greater depth than the other, the deeper scope is
moved upward until they are at equal depths.
- Then we move the two scopes upward in lockstep until they match.
This avoids the need to keep track of which scopes have already been
seen, which was the major part of the cost of the old algorithm. It also
reduces the number of child-to-parent moves (which are hash table
lookups) when the scopes start at different levels, because it never
goes past the nearest common ancestor the way the old algorithm did.
Finally, the case where one of the scopes is the root is now handled in
advance, because that is moderately common and lets us skip everything.
This change speeds up runs of several rust-perf benchmarks, the best by
6%.
Esteban Küber [Tue, 29 May 2018 23:37:06 +0000 (16:37 -0700)]
Accept `..` in incorrect position to avoid further errors
We currently give a specific message when encountering a `..` anywhere
other than the end of a pattern. Modify the parser to accept it (while
still emitting the error) so that we don't also trigger "missing fields
in pattern" errors afterwards.
bors [Tue, 5 Jun 2018 15:26:26 +0000 (15:26 +0000)]
Auto merge of #51369 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 7 pull requests
Successful merges:
- #50852 (Add doc comment to hiding portions of code example)
- #51183 (Update rustdoc book to suggest using Termination trait instead of hidden ‘foo’ function)
- #51255 (Fix confusing error message for sub_instant)
- #51256 (Fix crate-name option in rustdoc)
- #51308 (Check array indices in constant propagation)
- #51343 (test: Ignore some problematic tests on sparc and sparc64)
- #51358 (Tests that #39963 is fixed on MIR borrowck)
Mark Simulacrum [Tue, 5 Jun 2018 14:33:46 +0000 (08:33 -0600)]
Rollup merge of #51255 - avdv:patch-1, r=kennytm
Fix confusing error message for sub_instant
When subtracting an Instant from another, the function will panick when `RHS > self`, but the error message confusingly displays a different error:
```rust
let i = Instant::now();
let other = Instant::now();
if other > i {
println!("{:?}", i - other);
}
```
This results in a panic:
```
thread 'test_instant' panicked at 'other was less than the current instant', libstd/sys/unix/time.rs:292:17
```
But clearly, `other` was actually greater than the current instant.
Mark Simulacrum [Tue, 5 Jun 2018 14:33:43 +0000 (08:33 -0600)]
Rollup merge of #50852 - mandeep:fix-rustdoc-example-testing, r=GuillaumeGomez
Add doc comment to hiding portions of code example
fixes #50816
Not sure if this is all that's needed, but I think it's a good start. One thing to note is that the code block is a text block where it could possibly be a rust block.
bors [Tue, 5 Jun 2018 12:49:40 +0000 (12:49 +0000)]
Auto merge of #51246 - vakaras:select_polonius_algo_via_env_var, r=nikomatsakis
Select Polonius algorithm via `POLONIUS_ALGORITHM` environment variable
This pull request allows selecting the Polonius algorithm being used by providing an environment variable `POLONIUS_ALGORITHM`.
Example usage:
```
POLONIUS_ALGORITHM=compare RUST_LOG=rustc_mir::borrow_check::nll=trace ./x.py test --stage 1 --compare-mode polonius -- src/test/ui/nll/issue-47680.rs
...
stderr:
------------------------------------------
INFO 2018-05-31T17:35:31Z: rustc_mir::borrow_check::nll: Using Polonius algorithm: Compare
INFO 2018-05-31T17:35:31Z: rustc_mir::borrow_check::nll: Using Polonius algorithm: Compare
Esteban Küber [Tue, 5 Jun 2018 01:47:47 +0000 (18:47 -0700)]
Suggest braces when a struct literal needs them
When writing a struct literal in an expression that expects a block to
be started afterwards (like an `if` statement), do not suggest using the
same struct literal:
```
did you mean `S { /* fields * /}`?
```
Instead, suggest surrounding the expression with parentheses:
bors [Tue, 5 Jun 2018 01:47:13 +0000 (01:47 +0000)]
Auto merge of #51242 - ytausky:mut-ref, r=estebank
Suggest not mutably borrowing a mutable reference
This PR would (hopefully) solve #45392. I deviated a bit from @estebank's instructions since the error span only included the borrowed expression (e.g. the `b` in `&mut b`). I also didn't check the mutability of the local binding, since this whole case is concerned with an immutable local.
I can see two outstanding questions:
1. `note_immutability_blame` is called in two places, but I only have one test case. I think it covers the call in `report_bckerror`, but I'm not sure how to trigger the call from `report_aliasability_violation`.
2. There is one failing test, where the local binding is `self: &mut Self`. I'm not entirely sure what the correct output should be, but I think the new message should also apply. Unfortunately, since this parameter is parsed differently, its `let_span` covers both the pattern and the type, leading to a wrong suggestion text. I'm not sure how to correctly identify this case.
bors [Mon, 4 Jun 2018 11:29:38 +0000 (11:29 +0000)]
Auto merge of #51328 - oli-obk:no_union_promotion, r=eddyb
Do not promote union field accesses
r? @eddyb
technically a breaking change, but the code errored on the previous stable and produces UB + a warning on the current stable. I don't think we need a crater run in that case.