Commit Graph

76534 Commits

Author SHA1 Message Date
bors
9c9424de51 Auto merge of #49202 - csmoe:trait_engine, r=nikomatsakis
Introduce trait engine

address #48895 step 1: introduce trait engine
2018-03-27 14:31:43 +00:00
QuietMisdreavus
7f548bc8c6 add --edition flag to rustdoc 2018-03-27 16:31:19 +02:00
Tim Neumann
5b1a60062c Update compiler-rt with fix for 32bit iOS ARM 2018-03-27 15:32:06 +02:00
bors
3efe61c825 Auto merge of #49305 - SimonSapin:fallible, r=sfackler
Stabilize TryFrom / TryInto, and tweak impls for integers

Fixes https://github.com/rust-lang/rust/issues/33417 (tracking issue)

----

This adds:

* `impl From<u16> for usize`
* `impl From<i16> for isize`
* `impl From<u8> for isize`

… replacing corresponding `TryFrom<Error=!>` impls. (`TryFrom` still applies through the generic `impl<T, U> TryFrom<U> for T where T: From<U>`.) Their infallibility is supported by the C99 standard which (indirectly) requires pointers to be at least 16 bits.

The remaining `TryFrom` impls that define `type Error = !` all involve `usize` or `isize`. This PR changes them to use `TryFromIntError` instead, since having a return type change based on the target is a portability hazard.

Note: if we make similar assumptions about the *maximum* bit size of pointers (for all targets Rust will ever run on in the future), we could have similar `From` impls converting pointer-sized integers to large fixed-size integers. RISC-V considers the possibility of a 128-bit address space (RV128), which would leave only `impl From<usize> for u128` and `impl From<isize> for u128`. I [found](https://www.cl.cam.ac.uk/research/security/ctsrd/pdfs/20171017a-cheri-poster.pdf) some [things](http://www.csl.sri.com/users/neumann/2012resolve-cheri.pdf) about 256-bit “capabilities”, but I don’t know how relevant that would be to Rust’s `usize` and `isize` types.

I chose conservatively to make no assumption about the future there. Users making their portability decisions and using something like `.try_into().unwrap()`.

----

Since this feature already went through FCP in the tracking issue https://github.com/rust-lang/rust/issues/33417, this PR also proposes **stabilize** the following items:

* The `convert::TryFrom` trait
* The `convert::TryFrom` trait
* `impl<T> TryFrom<&[T]> for &[T; $N]` (for `$N` up to 32)
* `impl<T> TryFrom<&mut [T]> for &mut [T; $N]` (for `$N` up to 32)
* The `array::TryFromSliceError` struct, with impls of `Debug`, `Copy`, `Clone`, and `Error`
* `impl TryFrom<u32> for char`
* The `char::CharTryFromError` struct, with impls of `Copy`, `Clone`, `Debug`, `PartialEq`, `Eq`, `Display`, and `Error`
* Impls of `TryFrom` for all (?) combinations of primitive integer types where `From` isn’t implemented.
* The `num::TryFromIntError` struct, with impls of `Debug`, `Copy`, `Clone`, `Display`, `From<!>`, and `Error`

Some minor remaining questions that I hope can be resolved in this PR:

* Should the impls for error types be unified?
* ~Should `TryFrom` and `TryInto` be in the prelude? `From` and `Into` are.~ (Yes.)
2018-03-27 11:50:10 +00:00
Guillaume Gomez
73b97c7e7c Hide type declarations by default 2018-03-27 11:57:00 +02:00
kennytm
b4bc2b0cf8
Rollup merge of #49401 - alercah:format, r=cramertj
Add missing '?' to format grammar.
2018-03-27 10:47:54 +02:00
kennytm
2d05bde0b7
Rollup merge of #49399 - ehuss:termcolor-update, r=alexcrichton
Fix diagnostic colors on Windows 10 console.

This updates termcolor to pick up BurntSushi/ripgrep#867.

Fixes #49322.
2018-03-27 10:47:53 +02:00
kennytm
5eb4689d1f
Rollup merge of #49395 - petrochenkov:obsolete, r=alexcrichton
libsyntax: Remove obsolete.rs

This little piece of infra is obsolete (ha-ha) and is unlikely to be used in the future, even if new obsolete syntax appears.
2018-03-27 10:47:51 +02:00
Wangshan Lu
6313997e3e
Add back 1.24.1 release notes 2018-03-27 16:47:50 +08:00
kennytm
1c45f6c051
Rollup merge of #49381 - withoutboats:str_unicode, r=SimonSapin
Add is_whitespace and is_alphanumeric to str.

The other methods from `UnicodeStr` are already stable inherent
methods on str, but these have not been included.

r? @SimonSapin
2018-03-27 10:47:50 +02:00
kennytm
dbd6c56f32
Rollup merge of #49369 - petrochenkov:rprint, r=oli-obk
Fix pretty-printing for raw identifiers
2018-03-27 10:47:49 +02:00
kennytm
68a2e73d8c
Rollup merge of #49333 - GuillaumeGomez:link-assoc-const, r=QuietMisdreavus
Fix impl assoc constant link not working

Fixes #49323.

r? @QuietMisdreavus
2018-03-27 10:47:48 +02:00
kennytm
3d910b8dc1
Rollup merge of #49223 - GuillaumeGomez:propose-variant-for-E0599, r=cramertj
Propose a variant if it is an enum for E0599

Fixes #49192.
2018-03-27 10:47:46 +02:00
kennytm
42de36d4aa
Rollup merge of #48639 - varkor:sort_by_key-cached, r=bluss
Add slice::sort_by_cached_key as a memoised sort_by_key

At present, `slice::sort_by_key` calls its key function twice for each comparison that is made. When the key function is expensive (which can often be the case when `sort_by_key` is chosen over `sort_by`), this can lead to very suboptimal behaviour.

To address this, I've introduced a new slice method, `sort_by_cached_key`, which has identical semantic behaviour to `sort_by_key`, except that it guarantees the key function will only be called once per element.

Where there are `n` elements and the key function is `O(m)`:
- `slice::sort_by_cached_key` time complexity is `O(m n log m n)`, compared to `slice::sort_by_key`'s `O(m n + n log n)`.
- `slice::sort_by_cached_key` space complexity remains at `O(n + m)`. (Technically, it now reserves a slice of size `n`, whereas before it reserved a slice of size `n/2`.)

`slice::sort_unstable_by_key` has not been given an analogue, as it is important that unstable sorts are in-place, which is not a property that is guaranteed here. However, this also means that `slice::sort_unstable_by_key` is likely to be slower than `slice::sort_by_cached_key` when the key function does not have negligible complexity. We might want to explore this trade-off further in the future.

Benchmarks (for a vector of 100 `i32`s):
```
# Lexicographic: `|x| x.to_string()`
test bench_sort_by_key ... bench:      112,638 ns/iter (+/- 19,563)
test bench_sort_by_cached_key ... bench:       15,038 ns/iter (+/- 4,814)

# Identity: `|x| *x`
test bench_sort_by_key ... bench:        1,346 ns/iter (+/- 238)
test bench_sort_by_cached_key ... bench:        1,839 ns/iter (+/- 765)

# Power: `|x| x.pow(31)`
test bench_sort_by_key ... bench:        3,624 ns/iter (+/- 738)
test bench_sort_by_cached_key ... bench:        1,997 ns/iter (+/- 311)

# Abs: `|x| x.abs()`
test bench_sort_by_key ... bench:        1,546 ns/iter (+/- 174)
test bench_sort_by_cached_key ... bench:        1,668 ns/iter (+/- 790)
```
(So it seems functions that are single operations do perform slightly worse with this method, but for pretty much any more complex key, you're better off with this optimisation.)

I've definitely found myself using expensive keys in the past and wishing this optimisation was made (e.g. for https://github.com/rust-lang/rust/pull/47415). This feels like both desirable and expected behaviour, at the small cost of slightly more stack allocation and minute degradation in performance for extremely trivial keys.

Resolves #34447.
2018-03-27 10:47:44 +02:00
Guillaume Gomez
96ef2f8ab9 Fix search appearance 2018-03-27 10:33:31 +02:00
Simon Sapin
837d6c7023 Remove TryFrom impls that might become conditionally-infallible with a portability lint
https://github.com/rust-lang/rust/pull/49305#issuecomment-376293243
2018-03-27 09:48:42 +02:00
Oliver Schneider
6b3202a2bf
Trim discriminants to their final type size 2018-03-27 09:18:08 +02:00
bors
14ac1b5faa Auto merge of #49279 - varkor:generated-closure-return-type, r=alexcrichton
Fix implicit closure return type generation for libsyntax

The `lambda` function for constructing closures in libsyntax was explicitly setting the return type to `_`, which resulted in incorrect corresponding syntax (as `|| -> _ x` is not valid, without the enclosing brackets). This meant the generated code, when printed, was invalid.

I also took the opportunity to slightly improve the generated code for the `RustcEncodable::encode` method for unit structs.

Fixes #42213.
2018-03-27 07:16:29 +00:00
bors
31ae4f9fde Auto merge of #49249 - gnzlbg:simd_minmax, r=alexcrichton
implement minmax intrinsics

This adds the `simd_{fmin,fmax}` intrinsics, which do a vertical (lane-wise) `min`/`max` for floating point vectors that's equivalent to Rust's `min`/`max` for `f32`/`f64`.

It might make sense to make `{f32,f64}::{min,max}` use the `minnum` and `minmax` intrinsics as well.

---

~~HELP: I need some help with these. Either I should go to sleep or there must be something that I must be missing. AFAICT I am calling the `maxnum` builder correctly, yet rustc/LLVM seem to insert a call to `llvm.minnum` there instead...~~ EDIT: Rust's LLVM version is too old :/
2018-03-27 04:46:32 +00:00
Francis Gagné
87c08f9926 Update liblibc submodule to the 0.2.40 release 2018-03-26 23:42:30 -04:00
Francis Gagné
d032a4b079 Strengthen the repeat-trusted-len test
Simply checking for the presence of `llvm.memset` is too brittle because
this instrinsic can be used for seemingly trivial operations, such as
zero-initializing a `RawVec`.
2018-03-26 23:42:30 -04:00
Francis Gagné
afa7f5bc8a Add #[inline] to Clone impls for primitive types 2018-03-26 23:42:30 -04:00
Francis Gagné
f48c043154 Document builtin implementations of Clone and Copy
There are types that implement `Clone` and `Copy` but are not mentioned
in the documentation, because the implementations are provided by the
compiler. They are types of variants that cannot be fully covered by
trait implementations in Rust code, because the language is not
expressive enough.
2018-03-26 23:42:29 -04:00
matthew
48825bcb23 Remove an unnecessary/incorrect match in the expression check function 2018-03-26 19:41:19 -07:00
Francis Gagné
27164faaef Move some implementations of Clone and Copy to libcore
Add implementations of `Clone` and `Copy` for some primitive types to
libcore so that they show up in the documentation. The concerned types
are the following:

* All primitive signed and unsigned integer types (`usize`, `u8`, `u16`,
  `u32`, `u64`, `u128`, `isize`, `i8`, `i16`, `i32`, `i64`, `i128`);
* All primitive floating point types (`f32`, `f64`)
* `bool`
* `char`
* `!`
* Raw pointers (`*const T` and `*mut T`)
* Shared references (`&'a T`)

These types already implemented `Clone` and `Copy`, but the
implementation was provided by the compiler. The compiler no longer
provides these implementations and instead tries to look them up as
normal trait implementations. The goal of this change is to make the
implementations appear in the generated documentation.

For `Copy` specifically, the compiler would reject an attempt to write
an `impl` for the primitive types listed above with error `E0206`; this
error no longer occurs for these types, but it will still occur for the
other types that used to raise that error.

The trait implementations are guarded with `#[cfg(not(stage0))]` because
they are invalid according to the stage0 compiler. When the stage0
compiler is updated to a revision that includes this change, the
attribute will have to be removed, otherwise the stage0 build will fail
because the types mentioned above no longer implement `Clone` or `Copy`.

For type variants that are variadic, such as tuples and function
pointers, and for array types, the `Clone` and `Copy` implementations
are still provided by the compiler, because the language is not
expressive enough yet to be able to write the appropriate
implementations in Rust.

The initial plan was to add `impl` blocks guarded by `#[cfg(dox)]` to
make them apply only when generating documentation, without having to
touch the compiler. However, rustdoc's usage of the compiler still
rejected those `impl` blocks.

This is a [breaking-change] for users of `#![no_core]`, because they
will now have to supply their own implementations of `Clone` and `Copy`
for the primitive types listed above. The easiest way to do that is to
simply copy the implementations from `src/libcore/clone.rs` and
`src/libcore/marker.rs`.

Fixes #25893
2018-03-26 21:52:58 -04:00
Alexis Hunt
554dd3e350 Add missing '?' to format grammar. 2018-03-26 21:18:50 -04:00
Diggory Blake
04f6692aaf Implement shrink_to method on collections 2018-03-27 01:39:11 +01:00
Eric Huss
0f1c649827 Fix diagnostic colors on Windows 10 console.
This updates termcolor to pick up BurntSushi/ripgrep#867.

Fixes #49322.
2018-03-26 17:23:17 -07:00
Vadim Petrochenkov
604bbee84c libsyntax: Remove obsolete.rs 2018-03-27 00:45:28 +03:00
Simon Sapin
09008cc23f Add TryFrom and TryInto to the prelude 2018-03-26 23:36:04 +02:00
Simon Sapin
e53a2a7274 Stabilize the TryFrom and TryInto traits
Tracking issue: https://github.com/rust-lang/rust/issues/33417
2018-03-26 23:36:02 +02:00
Simon Sapin
9fd399feb1 Don’t use type Error = ! for target-dependant TryFrom impls.
Instead, expose apparently-fallible conversions in cases where
the implementation happens to be infallible for a given target.

Having an associated type / return type in a public API change
based on the target is a portability hazard.
2018-03-26 23:34:22 +02:00
Simon Sapin
2178ef8b22 TryFrom for integers: use From instead for truely-infallible impls
There is precendent in C for having a minimum pointer size, but I don’t feel confident enough about the future to mandate a maximum.
2018-03-26 23:34:22 +02:00
varkor
9c7b69e179 Remove mentions of unstable sort_by_cached key from stable documentation 2018-03-26 22:24:03 +01:00
bors
989b25718b Auto merge of #49053 - alexcrichton:fail-if-build-cargo-twice, r=Mark-Simulacrum
rustbuild: Fail the build if we build Cargo twice

This commit updates the `ToolBuild` step to stream Cargo's JSON messages, parse
them, and record all libraries built. If we build anything twice (aka Cargo)
it'll most likely happen due to dependencies being recompiled which is caught by
this check.
2018-03-26 21:21:33 +00:00
varkor
101e17df96 Add tests for items deprecated in the future 2018-03-26 22:16:10 +01:00
varkor
ecaf1f57ea Add future deprecation warning to rustdoc 2018-03-26 22:16:10 +01:00
varkor
c08902b084 Prevent deprecation warning for items deprecated in the future 2018-03-26 22:14:28 +01:00
Vadim Petrochenkov
a637dd00c8 Fix pretty-printing for raw identifiers 2018-03-27 00:07:16 +03:00
Alex Crichton
faebcc1087 rustbuild: Fail the build if we build Cargo twice
This commit updates the `ToolBuild` step to stream Cargo's JSON messages, parse
them, and record all libraries built. If we build anything twice (aka Cargo)
it'll most likely happen due to dependencies being recompiled which is caught by
this check.
2018-03-26 13:07:12 -07:00
bors
188e693b39 Auto merge of #49101 - mark-i-m:stabilize_i128, r=nagisa
Stabilize 128-bit integers 🎉

cc #35118

EDIT: This should be merged only after the following have been merged:
- [x] https://github.com/rust-lang-nursery/compiler-builtins/pull/236
- [x] https://github.com/rust-lang/book/pull/1230
2018-03-26 18:41:38 +00:00
Philipp Oppermann
b889f98fba Add a hash when a TargetPath is displayed 2018-03-26 19:01:26 +02:00
Philipp Oppermann
7b49190d3c Canonicalize paths 2018-03-26 18:57:24 +02:00
Philipp Oppermann
3908b2e443 Introduce a TargetTriple enum to support absolute target paths 2018-03-26 18:57:23 +02:00
bors
ab8b961677 Auto merge of #49379 - TimNN:rollup, r=TimNN
Rollup of 7 pull requests

- Successful merges: #48693, #48932, #49103, #49170, #49187, #49346, #49353
- Failed merges:
2018-03-26 15:48:06 +00:00
matthew
816c1b191c Check for known but incorrect attributes
- Change nested_visit_map so it will recusively check functions

- Add visit_stmt and visit_expr for impl Visitor for CheckAttrVisitor and check for incorrect
inline and repr attributes on staements and expressions

- Add regression test for isssue #43988
2018-03-26 08:43:16 -07:00
Anthony Ramine
bda718fd25 Allow niche-filling dataful variants to be represented as a ScalarPair 2018-03-26 17:35:29 +02:00
boats
5fc7e0a2ba
Remove unnecessary trait import. 2018-03-26 07:41:45 -07:00
Mark Mansi
140bf949bf fix last two tidy 2018-03-26 08:37:56 -05:00
Mark Mansi
6b625b3341 did i get it right now? 2018-03-26 08:37:56 -05:00