bors [Thu, 21 Jun 2018 23:08:32 +0000 (23:08 +0000)]
Auto merge of #51690 - nikomatsakis:issue-51683-existential-fail, r=oli-obk
do not ICE when existing type info is incomplete
Apparently master is kinda ICE-y right now, but only for some people (sadly that set includes me).
I'm not crazy about this PR, because it seems to regress diagnostics a lot, but it *does* fix the problems. I think probably fixing the diagnostics should be done by doing a better job of suppressing errors?
bors [Thu, 21 Jun 2018 20:58:51 +0000 (20:58 +0000)]
Auto merge of #48149 - varkor:generics-generalisation, r=petrochenkov
The Great Generics Generalisation: HIR Edition
This is essentially a followup to https://github.com/rust-lang/rust/pull/45930, consolidating the use of separate lifetime and type vectors into single kinds vectors wherever possible. This is intended to provide more of the groundwork for const generics (https://github.com/rust-lang/rust/issues/44580).
bors [Thu, 21 Jun 2018 08:55:13 +0000 (08:55 +0000)]
Auto merge of #51601 - Emerentius:step_by_range_diet, r=sfackler
Specialize StepBy<Range(Inclusive)>
Part of #51557, related to #43064, #31155
As discussed in the above issues, `step_by` optimizes very badly on ranges which is related to
1. the special casing of the first `StepBy::next()` call
2. the need to do 2 additions of `n - 1` and `1` inside the range's `next()`
This PR eliminates both by overriding `next()` to always produce the current element and also step ahead by `n` elements in one go. The generated code is much better, even identical in the case of a `Range` with constant `start` and `end` where `start+step` can't overflow. Without constant bounds it's a bit longer than the manual loop. `RangeInclusive` doesn't optimize as nicely but is still much better than the original asm.
Unsigned integers optimize better than signed ones for some reason.
See the following two links for a comparison.
[godbolt: specialization for ..](https://godbolt.org/g/haHLJr)
[godbolt: specialization for ..=](https://godbolt.org/g/ewyMu6)
`RangeFrom`, the only other range with an `Iterator` implementation can't be specialized like this without changing behaviour due to overflow. There is no way to save "finished-ness".
The approach can not be used in general, because it would produce side effects of the underlying iterator too early.
bors [Tue, 19 Jun 2018 23:37:09 +0000 (23:37 +0000)]
Auto merge of #51639 - SimonSapin:missing-alloc, r=rkruppe
Update the error message for a missing global allocator
Don’t mention `#[default_lib_allocator]` (which is an implementation detail irrelevant to most users) and instead suggest using `#[global_allocator]`, which is often the correct fix.
NLL: revise `fn check_access_permissions` so that its (still branchy) shares more code paths between the different cases, and also provide more diagnostics in more cases (though the added diagnostics still do not always meet the quality bar established by AST-borrowck)
----
Transcribing "checklist" suggested by Niko, except I am rendering it as a table to make it clear that I do not regard every item in the list to be a "must have" for landing this PR.
goal | does this PR do it?
-----|------------------------------
no suggestions for `ref mut` | yes
suggestions for direct local assignment (`{ let x = 3; x = 4; }`) | yes (see commits at end)
suggestions for direct field assignment (`{ let x = (3, 4); x.0 = 5; }` | yes (see commits at end)
suggestions for upvars (`let x = 3; let c = \|\| { &mut x; }`) | yes
Note that I added support for a couple of rows via changes that are not strictly part of `fn check_access_permissions`. If desired I can remove those commits from this PR and leave them for a later PR.
Fix #51031
Fix #51032
(bug #51191 needs a little more investigation before closing.)
Fix #51578
bors [Tue, 19 Jun 2018 19:22:12 +0000 (19:22 +0000)]
Auto merge of #51543 - SimonSapin:oom, r=SimonSapin
Rename OOM to allocation error
The acronym is not descriptive unless one has seen it before.
* Rename the `oom` function to `handle_alloc_error`. It was **stabilized in 1.28**, so if we do this at all we need to land it this cycle.
* Rename `set_oom_hook` to `set_alloc_error_hook`
* Rename `take_oom_hook` to `take_alloc_error_hook`
Simon Sapin [Tue, 19 Jun 2018 18:10:56 +0000 (20:10 +0200)]
Update the error message for a missing global allocator
Don’t mention `#[default_lib_allocator]` (which is an implementation detail
irrelevant to most users) and instead suggest using `#[global_allocator]`,
which is often the correct fix.
Add unit test for case that didn't seem to be covered in existing UI tests
(since I made this mistake at first but the tests didn't catch it):
we should not suggest adding `mut` to a reassigned `ref` or `ref mut` binding.
(The Rust language, since at least 1.0, does not have `mut ref mut` or
`ref mut mut` etc.)
Tried to unify various common code paths and also vaguely approximate
the AST-borrowck diagnostics.
The change in (subjective) quality of diagnostics is not a universal
improvement. But I think this is a better code base to work from
for future fixes.
Thread more argument info down from `Hir` into the `mir::LocalDecls`.
Namely, we thread down the `HirId` of the explicit type of the
argument. In the case of the special `self` variable with an implicit
type, we also thread down a description of its structure (`self`/`mut
self`/`&self`/`&mut self`).
Thread info about form of variable bindings, including spans of arg types, down into `mir::LocalDecls`.
As a drive-by: the ref_for_guards created by `fn declare_binding`
should not have been tagged as user_variables in the first
place. These secret internal locals are *pointers* to user variables,
but themselves are not such (IMO. For now at least.)
Emerentius [Sat, 16 Jun 2018 19:58:28 +0000 (21:58 +0200)]
specialize StepBy<Range(Inclusive)>
the originally generated code was highly suboptimal
this brings it close to the same code or even exactly the same as a
manual while-loop by eliminating a branch and the
double stepping of n-1 + 1 steps
The intermediate trait lets us circumvent the specialization
type inference bugs
bors [Tue, 19 Jun 2018 13:09:04 +0000 (13:09 +0000)]
Auto merge of #51081 - kornelski:examplestr, r=steveklabnik
Use String, not &str in some collection examples
Discussed in #46966
Overuse of borrowed values in data structures is a common mistake I see in Rust user forums. Users who copy&paste such examples end up fighting with the borrow checker as soon as they replace string literals with some real values.
This changes a couple of examples to use `String`, and it adds opportunity to demonstrate use of `Borrow`.
bors [Tue, 19 Jun 2018 02:17:52 +0000 (02:17 +0000)]
Auto merge of #51278 - EPashkin:fix_mod_with_multilevel_paths_on_windows, r=nikomatsakis
Fix processing mod with multi-level path on Windows
Fix error in [rustfmt](https://github.com/rust-lang-nursery/rustfmt/issues/1754) because libsyntax can not handle `mod` with multilevel path on Windows.
Alternative is do almost same in https://github.com/rust-lang/rust/blob/master/src/libstd/sys/windows/fs.rs#L717 to allow work on paths with different separators, Ex. "\\\\?\\c:\\windows/temp"