Commit Graph

76837 Commits

Author SHA1 Message Date
bors 7291829268 Auto merge of #49830 - sinkuu:fix_ice_47715, r=cramertj
Fix ICE by disallowing `impl Trait` in unsupported position

Fixes #47715.
2018-04-13 19:22:14 +00:00
bors 9c2bfcbea2 Auto merge of #49808 - spastorino:dump_cause_ice, r=nikomatsakis
[NLL] Fix ICE when a borrow wrapped in a temporary is used after dropped

Fixes #47646

r? @nikomatsakis
2018-04-13 16:06:14 +00:00
bors b8f60f3fc4 Auto merge of #49800 - ishitatsuyuki:intern-goal, r=nikomatsakis
traits: Implement interning for Goal and Clause

r? @nikomatsakis

Close #49054

Contains some refactoring for the interning mechanism, mainly aimed at reducing pain when changing types of interning map.

This should be mostly good, although I'm not sure with the naming of `Goal::from_poly_domain_goal`.
2018-04-13 13:09:40 +00:00
bors 99d4886ead Auto merge of #49669 - SimonSapin:global-alloc, r=alexcrichton
Add GlobalAlloc trait + tweaks for initial stabilization

This is the outcome of discussion at the Rust All Hands in Berlin. The high-level goal is stabilizing sooner rather than later the ability to [change the global allocator](https://github.com/rust-lang/rust/issues/27389), as well as allocating memory without abusing `Vec::with_capacity` + `mem::forget`.

Since we’re not ready to settle every detail of the `Alloc` trait for the purpose of collections that are generic over the allocator type (for example the possibility of a separate trait for deallocation only, and what that would look like exactly), we propose introducing separately **a new `GlobalAlloc` trait**, for use with the `#[global_allocator]` attribute.

We also propose a number of changes to existing APIs. They are batched in this one PR in order to minimize disruption to Nightly users.

The plan for initial stabilization is detailed in the tracking issue https://github.com/rust-lang/rust/issues/49668.

CC @rust-lang/libs, @glandium

## Immediate breaking changes to unstable features

* For pointers to allocated memory, change the pointed type from `u8` to `Opaque`, a new public [extern type](https://github.com/rust-lang/rust/issues/43467). Since extern types are not `Sized`, `<*mut _>::offset` cannot be used without first casting to another pointer type. (We hope that extern types can also be stabilized soon.)
* In the `Alloc` trait, change these pointers to `ptr::NonNull` and change the `AllocErr` type to a zero-size struct. This makes return types `Result<ptr::NonNull<Opaque>, AllocErr>` be pointer-sized.
* Instead of a new `Layout`, `realloc` takes only a new size (in addition to the pointer and old `Layout`). Changing the alignment is not supported with `realloc`.
* Change the return type of `Layout::from_size_align` from `Option<Self>` to `Result<Self, LayoutErr>`, with `LayoutErr` a new opaque struct.
* A `static` item registered as the global allocator with the `#[global_allocator]` **must now implement the new `GlobalAlloc` trait** instead of `Alloc`.

## Eventually-breaking changes to unstable features, with a deprecation period

* Rename the respective `heap` modules to `alloc` in the `core`, `alloc`, and `std` crates. (Yes, this does mean that `::alloc::alloc::Alloc::alloc` is a valid path to a trait method if you have `exetrn crate alloc;`)
* Rename the the `Heap` type to `Global`, since it is the entry point for what’s registered with `#[global_allocator]`.

Old names remain available for now, as deprecated `pub use` reexports.

## Backward-compatible changes

* Add a new [extern type](https://github.com/rust-lang/rust/issues/43467) `Opaque`, for use in pointers to allocated memory.
* Add a new `GlobalAlloc` trait shown below. Unlike `Alloc`, it uses bare `*mut Opaque` without `NonNull` or `Result`. NULL in return values indicates an error (of unspecified nature). This is easier to implement on top of `malloc`-like APIs.
* Add impls of `GlobalAlloc` for both the `Global` and `System` types, in addition to existing impls of `Alloc`. This enables calling `GlobalAlloc` methods on the stable channel before `Alloc` is stable. Implementing two traits with identical method names can make some calls ambiguous, but most code is expected to have no more than one of the two traits in scope. Erroneous code like `use std::alloc::Global; #[global_allocator] static A: Global = Global;` (where `Global` is defined to call itself, causing infinite recursion) is not statically prevented by the type system, but we count on it being hard enough to do accidentally and easy enough to diagnose.

```rust
extern {
    pub type Opaque;
}

pub unsafe trait GlobalAlloc {
    unsafe fn alloc(&self, layout: Layout) -> *mut Opaque;
    unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout);

    unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque {
        // Default impl: self.alloc() and ptr::write_bytes()
    }
    unsafe fn realloc(&self, ptr: *mut Opaque, old_layout: Layout, new_size: usize) -> *mut Opaque {
        // Default impl: self.alloc() and ptr::copy_nonoverlapping() and self.dealloc()
    }

    fn oom(&self) -> ! {
        // intrinsics::abort
    }

    // More methods with default impls may be added in the future
}
```

## Bikeshed

The tracking issue https://github.com/rust-lang/rust/issues/49668 lists some open questions. If consensus is reached before this PR is merged, changes can be integrated.
2018-04-13 10:33:51 +00:00
bors f9f9050f50 Auto merge of #49389 - fanzier:euclidean-division, r=KodrAus
Implement RFC #2169 (Euclidean modulo).

Tracking issue: #49048
2018-04-13 07:34:37 +00:00
bors eec3208c4c Auto merge of #49360 - topecongiro:run-rustfmt/build_helper, r=nrc
Run rustfmt on build_helper

Using rustfmt 0.4.1-nightly (e784712f 2018-04-09).
2018-04-13 04:42:10 +00:00
bors defcfe7142 Auto merge of #49718 - petrochenkov:fieldcmp, r=eddyb
Hygiene 2.0: Avoid comparing fields by name

There are two separate commits here (not counting tests):
- The first one unifies named (`obj.name`) and numeric (`obj.0`) field access expressions in AST and HIR. Before field references in these expressions are resolved it doesn't matter whether the field is named or numeric (it's just a symbol) and 99% of code is common. After field references are resolved we work with
them by index for all fields (see the second commit), so it's again not important whether the field was named or numeric (this includes MIR where all fields were already by index).
(This refactoring actually fixed some bugs in HIR-based borrow checker where borrows through names (`S {
0: ref x }`) and indices (`&s.0`) weren't considered overlapping.)
- The second commit removes all by-name field comparison and instead resolves field references to their indices  once, and then uses those resolutions. (There are still a few name comparisons in save-analysis, because save-analysis is weird, but they are made correctly hygienic).
Thus we are fixing a bunch of "secondary" field hygiene bugs (in borrow checker, lints).

Fixes https://github.com/rust-lang/rust/issues/46314
2018-04-13 01:43:09 +00:00
bors c4a03283cd Auto merge of #45298 - toidiu:ak-44493-infer-predicate, r=nikomatsakis
Ak 44493 infer predicate

 **WIP**  Implements #44493

Things to do:

- [x] add feature gate and appropriate tests (see [forge](https://forge.rust-lang.org/feature-guide.html) for some details)
- [x] add a unit testing system similar to `#[rustc_variance]`
  - [x] to see how, maybe `rg rustc_variance` and take some notes
- [ ] add more tests:
- [x] we need to decide how to handle `struct Foo<'a, T> { x: &'a T::Item }`
- [x] handle explicit predicates on types
- [ ] handle explicit predicates on `dyn Trait` (this could be put off to a follow-up PR)
- [ ] handle explicit predicates on projections (this could be put off to a follow-up PR)
2018-04-12 23:07:07 +00:00
Fabian Zaiser ca4e458089 Address more nits. 2018-04-12 23:12:11 +02:00
Simon Sapin c5ffdd787d Initial docs for the GlobalAlloc trait 2018-04-12 22:53:22 +02:00
Simon Sapin f607a3872a Rename alloc::Void to alloc::Opaque 2018-04-12 22:53:22 +02:00
Simon Sapin ed29777759 Remove conversions for allocated pointers
One was now unused, and `NonNull::new(…).ok_or(AllocErr)` feels short enough
for the few cases that need the other conversion.
2018-04-12 22:53:22 +02:00
Mike Hommey fddf51ee0b Use NonNull<Void> instead of *mut u8 in the Alloc trait
Fixes #49608
2018-04-12 22:53:22 +02:00
Simon Sapin fd242ee64c impl GlobalAlloc for Global 2018-04-12 22:53:22 +02:00
Simon Sapin eae0d46893 Restore Global.oom() functionality
… now that #[global_allocator] does not define a symbol for it
2018-04-12 22:53:21 +02:00
Simon Sapin 96c9d225a9 Remove `impl Alloc for &'a System`
This was relevant to `#[global_allocator]`,
which is now based on `GlobalAlloc` trait instead.
2018-04-12 22:53:14 +02:00
Simon Sapin c033f1ff5f Move platform-specific OOM handling to functions 2018-04-12 22:53:14 +02:00
Simon Sapin 747cc74943 Conversions between Result<*mut u8, AllocErr>> and *mut Void 2018-04-12 22:53:14 +02:00
Simon Sapin c957e99b30 realloc with a new size only, not a full new layout.
Changing the alignment with realloc is not supported.
2018-04-12 22:53:13 +02:00
Simon Sapin b017742136 Return Result instead of Option in alloc::Layout constructors 2018-04-12 22:53:13 +02:00
Simon Sapin f9c96d70bd Add FIXME comments for Void::null_mut usage 2018-04-12 22:53:13 +02:00
Simon Sapin 93a9ad4897 Remove the now-unit-struct AllocErr field inside CollectionAllocErr 2018-04-12 22:53:13 +02:00
Simon Sapin 157ff8cd05 Remove the now-unit-struct AllocErr parameter of oom() 2018-04-12 22:53:13 +02:00
Simon Sapin 86753ce1cc Use the GlobalAlloc trait for #[global_allocator] 2018-04-12 22:53:12 +02:00
Simon Sapin eb69593f73 Implement GlobalAlloc for System 2018-04-12 22:53:03 +02:00
Simon Sapin ba7081a033 Make AllocErr a zero-size unit struct 2018-04-12 22:53:03 +02:00
Alex Crichton a4caac5e93 Update to most recent version of dlmalloc
Inline the definition of `GlobalAlloc` for `dlmalloc` on wasm and don't rely on
usage of unstable features in `dlmalloc` itself.
2018-04-12 22:53:02 +02:00
Simon Sapin 5e5a0c21fc Separate alloc::heap::Alloc trait for stage0 #[global_allocator] 2018-04-12 22:52:54 +02:00
Simon Sapin e521b8b472 Actually deprecate the Heap type 2018-04-12 22:52:47 +02:00
Simon Sapin 88ebd2d752 Rename the Heap type to Global
… since it is the entry point for what’s registered with `#[global_allocator]`
2018-04-12 22:52:47 +02:00
Simon Sapin 743c29bdc5 Actually deprecate heap modules. 2018-04-12 22:52:47 +02:00
Simon Sapin 09e8db1e4f Rename `heap` modules in the core, alloc, and std crates to `alloc` 2018-04-12 22:52:47 +02:00
Simon Sapin 1b895d8b88 Import the `alloc` crate as `alloc_crate` in std
… to make the name `alloc` available.
2018-04-12 22:52:47 +02:00
Simon Sapin c660cedc02 Add a GlobalAlloc trait 2018-04-12 22:52:47 +02:00
Simon Sapin 9b068867f0 Add a core::heap::Void extern type. 2018-04-12 22:52:47 +02:00
Simon Sapin 1569f8f812 Inline docs for the heap module’s reexports 2018-04-12 22:52:47 +02:00
Vadim Petrochenkov fcf48520a0 Add some new tests + Fix failing tests 2018-04-12 23:06:03 +03:00
Vadim Petrochenkov d3f8b8be6f Move hygiene tests to UI 2018-04-12 23:06:03 +03:00
Vadim Petrochenkov 4f69b7fb85 Avoid comparing fields by name when possible
Resolve them into field indices once and then use those resolutions

+ Fix rebase
2018-04-12 23:06:03 +03:00
Vadim Petrochenkov 44acea4d88 AST/HIR: Merge field access expressions for named and numeric fields 2018-04-12 23:02:09 +03:00
toidiu 6a229cbfac Implement inferring outlives requirements for references, structs, enum, union, and projection types. added a feature gate and tests for these scenarios. 2018-04-12 13:52:06 -04:00
bors 6c537493d0 Auto merge of #49558 - Zoxc:sync-misc, r=michaelwoerister
Even more thread-safety changes

r? @michaelwoerister
2018-04-12 16:22:36 +00:00
bors 9afed64645 Auto merge of #49551 - scottmcm:deprecate-offset_to, r=KodrAus
Deprecate offset_to; switch core&alloc to using offset_from instead

Bonus: might make code than uses `.len()` on slice iterators faster

cc https://github.com/rust-lang/rust/issues/41079
2018-04-12 08:29:10 +00:00
Seiichi Uchida 23b880ade5 Run rustfmt on build_helper 2018-04-12 14:49:03 +09:00
bors 252a459d37 Auto merge of #49371 - scottmcm:catch-wrapping, r=nikomatsakis
Add ok-wrapping to catch blocks, per RFC

Updates the `catch{}` lowering to wrap the result in `Try::from_ok`.

r? @nikomatsakis

Fixes #41414
Fixes #43818
2018-04-12 05:38:49 +00:00
Tatsuyuki Ishi b15df80345 traits: Implement interning for Goal and Clause 2018-04-12 13:43:10 +09:00
bors 47778811d9 Auto merge of #48528 - bitshifter:repr_packed, r=eddyb
Implementation of `#[repr(packed(n))]` RFC 1399.

Tracking issue https://github.com/rust-lang/rust/issues/33158.
2018-04-12 03:08:14 +00:00
bors d26f9e42df Auto merge of #49698 - SimonSapin:unicode-for-everyone, r=alexcrichton
Merge the std_unicode crate into the core crate

[The standard library facade](https://github.com/rust-lang/rust/issues/27783) has historically contained a number of crates with different roles, but that number has decreased over time. `rand` and `libc` have moved to crates.io, and [`collections` was merged into `alloc`](https://github.com/rust-lang/rust/pull/42648). Today we have `core` that applies everywhere, `std` that expects a full operating system, and `alloc` in-between that only requires a memory allocator (which can be provided by users)… and `std_unicode`, which doesn’t really have a reason to be separate anymore. It contains functionality based on Unicode data tables that can be large, but as long as relevant functions are not called the tables should be removed from binaries by linkers.

This deprecates the unstable `std_unicode` crate and moves all of its contents into `core`, replacing them with `pub use` reexports. The crate can be removed later. This also removes the `CharExt` trait (replaced with inherent methods in libcore) and `UnicodeStr` trait (merged into `StrExt`). There traits were both unstable and not intended to be used or named directly.

A number of new items are newly-available in libcore and instantly stable there, but only if they were already stable in libstd.

Fixes #49319.
2018-04-12 00:35:33 +00:00
Simon Sapin ef41788cf3 Mark the rest of the `unicode` feature flag as perma-unstable. 2018-04-12 00:13:53 +02:00
Simon Sapin 1ca2905cda Dedicated tracking issue for UnicodeVersion and UNICODE_VERSION. 2018-04-12 00:13:53 +02:00