bors [Thu, 16 Nov 2017 06:10:36 +0000 (06:10 +0000)]
Auto merge of #45920 - sunfishcode:trap-on-unreachable, r=Zoxc
Enable TrapUnreachable in LLVM.
This patch enables LLVM's TrapUnreachable flag, which tells it to translate `unreachable` instructions into hardware trap instructions, rather than allowing control flow to "fall through" into whatever code happens to follow it in memory.
This follows up on https://github.com/rust-lang/rust/issues/28728#issuecomment-332581533. For example, for @zackw's testcase [here](https://github.com/rust-lang/rust/issues/42009#issue-228745924), the output function contains a `ud2` instead of no code, so it won't "fall through" into whatever happens to be next in memory.
(I'm also working on the problem of LLVM optimizing away infinite loops, but the patch here is useful independently.)
I tested this patch on a few different codebases, and the code size increase ranged from 0.0% to 0.1%.
bors [Wed, 15 Nov 2017 22:47:54 +0000 (22:47 +0000)]
Auto merge of #45918 - chrisvittal:impl-trait-pr, r=nikomatsakis
Implement `impl Trait` in argument position (RFC1951, Universal quantification)
Implements the remainder of #44721, part of #34511.
**Note**: This PR currently allows argument position `impl Trait` in trait functions. The machinery is there to prevent this if we want to, but it currently does not.
Rename `hir::TyImplTrait` to `hir::TyImplTraitExistential` and add `hir::TyImplTraitUniversal(DefId, TyParamBounds)`. The `DefId` is needed to extract the index of the parameter in `ast_ty_to_ty`.
Introduce an `ImplTraitContext` enum to lowering to keep track of the kind and allowedness of `impl Trait` in that position. This new argument is passed through many places, all ending up in `lower_ty`.
Modify `generics_of` and `explicit_predicates_of` to collect the `impl Trait` args into anonymous synthetic generic parameters and to extend the predicates with the appropriate bounds.
Add a comparison of the 'syntheticness' of type parameters, that is, prevent the following.
```rust
trait Foo {
fn foo(&self, &impl Debug);
}
impl Foo for Bar {
fn foo<U: Debug>(&self, x: &U) { ... }
}
```
And vice versa.
Incedentally, supress `unused type parameter` errors if the type being compared is already a `TyError`.
**TODO**: I have tried to annotate open questions with **FIXME**s. The most notable ones that haven't been resolved are the names of the `impl Trait` types and the questions surrounding the new `compare_synthetic_generics` method.
1. For now, the names used for `impl Trait` parameters are `keywords::Invalid.name()`. I would like them to be `impl ...` if possible, but I haven't figured out a way to do that yet.
2. For `compare_synthetic_generics` I have tried to outline the open questions in the [function itself](https://github.com/chrisvittal/rust/blob/3fc9e3705f7bd01f3cb0ea470cf2892f17a92350/src/librustc_typeck/check/compare_method.rs#L714-L725)
Chris Vittal [Tue, 14 Nov 2017 17:27:55 +0000 (12:27 -0500)]
Add proper names to impl Trait parameters.
Uses Symbol::intern and hir.node_to_pretty_string to create a name for
the impl Trait parameter that is just impl and then a ' + ' separated
list of bounds that the user typed.
We do not want to allow this, and so we add a new error and check.
The check just tests that all paramters 'syntheticness' match up. As
during collection, the impl Trait parameters are transformed into
anonymous synthetic generics.
Furthermore, causes a check for unused type parameters to be skipped in
check_bounds_are_used if there is already a TyError. Thus, an unused
input will not trigger `type parameter unused` errors.
Update the one test that checked for this error in the case of
a TyError.
Alter type collection to collect impl Trait bounds
In ast_generics extraction in generics_of and explicit_predicates_of,
also collect inputs if there are any.
Then use a Visitor to extract the necessary information from the
TyImplTraitUniversal types before extending generics and predicates with
the new information.
This is for tracking if an ImplItem is part of a trait impl. Add
a with_trait_impl_ref method to ItemLowerer to appropriately save the
state to allow appropriate nesting of trait and non-trait impls.
Split hir::TyImplTrait, move checks to HIR lowering
Replace hir::TyImplTrait with TyImplTraitUniversal and
TyImplTraitExistential.
Add an ImplTraitContext enum to rustc::hir::lowering to track the kind
and allowedness of an impl Trait.
Significantly alter lowering to thread ImplTraitContext and one other
boolean parameter described below throughought much of lowering.
The other parameter is for tracking if lowering a function is in a trait
impl, as there is not enough information to otherwise know this
information during lowering otherwise.
This change also removes the checks from ast_ty_to_ty for impl trait
allowedness as they are now all taking place in HIR lowering.
bors [Wed, 15 Nov 2017 08:02:19 +0000 (08:02 +0000)]
Auto merge of #45944 - eddyb:provide, r=nikomatsakis
rustc_driver: expose a way to override query providers in CompileController.
This API has been a long-time coming and will probably become the main method for custom drivers (that is, binaries other than `rustc` itself that use `librustc_driver`) to adapt the compiler's behavior.
bors [Tue, 14 Nov 2017 18:47:34 +0000 (18:47 +0000)]
Auto merge of #45821 - djzin:unreachable-match-arms, r=nikomatsakis
always add an unreachable branch on matches to give more info to llvm
As part of https://github.com/djzin/rustc-optimization I discovered that some simple enum optimizations (src/unary/three_valued_enum.rs and src/unary/four_valued_enum.rs in the repo) are not applied - and the reason for this is that we erase the info that the discriminant of an enum is one of the options by putting the last one in an "otherwise" branch. This patch adds an extra branch so that LLVM can know what the possibilities are for the discriminant, which fixes the three- and four- valued cases.
Note that for whatever reason, this doesn't fix the case of 2 variants (most notably `Option` and `Result` have 2 variants) - a pass re-ordering might fix this or we may wish to add "assume" annotations on discriminants to force it to optimize.
Guillaume Gomez [Tue, 14 Nov 2017 15:52:12 +0000 (16:52 +0100)]
Rollup merge of #45967 - matthewjasper:array-move-types, r=arielb1
MIR-borrowck: don't ICE for cannot move from array error
Closes #45694
compile-fail test E0508 now gives
```text
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Ast)
--> .\src\test\compile-fail\E0508.rs:18:18
|
18 | let _value = array[0]; //[ast]~ ERROR E0508
| ^^^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&array[0]`
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array (Mir)
--> .\src\test\compile-fail\E0508.rs:18:18
|
18 | let _value = array[0]; //[ast]~ ERROR E0508
| ^^^^^^^^ cannot move out of here
Guillaume Gomez [Tue, 14 Nov 2017 15:52:07 +0000 (16:52 +0100)]
Rollup merge of #45815 - QuietMisdreavus:happy-little-notices, r=GuillaumeGomez
rustdoc: tweak notes on ignore/compile_fail examples
Part of https://github.com/rust-lang/rust/issues/44927
This is a softening of these notices to mention *why* a given example has a given callout, rather then telling viewers to be careful with an example. It also changes the character used for these samples from a warning logo to a circle-i/information logo.
bors [Tue, 14 Nov 2017 13:46:19 +0000 (13:46 +0000)]
Auto merge of #45896 - malbarbo:use-libc-const, r=alexcrichton
Use getrandom syscall for all Linux and Android targets.
I suppose we can use it in all Linux and Android targets. In function `is_getrandom_available` is checked if the syscall is available (getrandom syscall was add in version 3.17 of Linux kernel), if the syscall is not available `fill_bytes` fallback to reading from `/dev/urandom`.
Update libc to include getrandom related constants.
bors [Tue, 14 Nov 2017 07:54:51 +0000 (07:54 +0000)]
Auto merge of #45916 - eddyb:even-mirer-0, r=nikomatsakis
rustc_mir: hardcode pass list internally and remove premature pluggability.
Fixes #41712 by moving the MIR pass lists from `rustc_driver` to `rustc_mir`.
The application of the passes is done with the `rustc_mir::transform::run_passes` macro, which is public, as are all the passes AFAIK, and can be used to apply MIR passes outside of `rustc_mir`.
With the ability to override query providers through the `rustc_driver` (orthogonal to, and not included in this PR), custom drivers will be able to substitute the entire pass list if they want to.
**EDIT**: the aforementioned ability is added by #45944.
bors [Mon, 13 Nov 2017 17:42:13 +0000 (17:42 +0000)]
Auto merge of #45890 - arielb1:self-first, r=eddyb
check::method - unify receivers before normalizing method signatures
Normalizing method signatures can unify inference variables, which can
cause receiver unification to fail. Unify the receivers first to avoid
that.
Fixes #36701.
Fixes #45801.
Fixes #45855.
r? @eddyb
beta-nominating because #43880 made this ICE happen in more cases (the code in that issue ICEs post-#43880 only, but the unit test here ICEs on all versions).
kennytm [Mon, 13 Nov 2017 09:09:47 +0000 (17:09 +0800)]
Rollup merge of #45952 - zackmdavis:singular_projection, r=estebank
deduplicate projection error (E0271) messages
The `ErrorId` variant takes a u16 so that `DiagnosticMessageId` can retain
its `Copy` status (the present author's first choice having been the "EXXX"
code as a string).
The duplicated "type mismatch resolving `{}`" literal is unfortunate, but
the `struct_span_err!` macro (which we want to mark that error code as
used) is fussy about taking a literal, and the one-time-diagnostics set
needs an owned string.
kennytm [Mon, 13 Nov 2017 09:09:45 +0000 (17:09 +0800)]
Rollup merge of #45927 - sinkuu:mir-borrowck-closure, r=estebank
MIR-borrowck: fix diagnostics for closures
Emit notes for captured variables in the same manner as AST borrowck.
```
error[E0499]: cannot borrow `x` as mutable more than once at a time (Ast)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
error[E0499]: cannot borrow `x` as mutable more than once at a time (Mir)
--> $DIR/borrowck-closures-two-mut.rs:24:24
|
23 | let c1 = to_fn_mut(|| x = 4);
| -- - previous borrow occurs due to use of `x` in closure
| |
| first mutable borrow occurs here
24 | let c2 = to_fn_mut(|| x = 5); //~ ERROR cannot borrow `x` as mutable more than once
| ^^ - borrow occurs due to use of `x` in closure
| |
| second mutable borrow occurs here
25 | }
| - first borrow ends here
```
kennytm [Mon, 13 Nov 2017 09:09:44 +0000 (17:09 +0800)]
Rollup merge of #45917 - ollie27:compiletest_stamp, r=alexcrichton
compiletest: Fix a couple of test re-run issues
* Re-run rustdoc tests if rustdoc or htmldocck.py was updated.
* Put stamp files in the correct subdirectories to avoid clashes when
the file names match but the subdirectory doesn't.
kennytm [Mon, 13 Nov 2017 09:09:43 +0000 (17:09 +0800)]
Rollup merge of #45914 - michaelwoerister:fix-test-header-parsing, r=alexcrichton
Fix test case header parsing code in presence of multiple revisions.
The previous code would parse the TestProps, and then parse them again with a revision set, adding some elements (like aux_builds) a second time to the existing TestProps.
kennytm [Mon, 13 Nov 2017 09:09:42 +0000 (17:09 +0800)]
Rollup merge of #45893 - redox-os:futex_timeout, r=alexcrichton
Redox: Use futex timeout to implement CondVar::wait_timeout
`CondVar::wait_timeout` is implemented by supplying a `TimeSpec` pointer to `futex`. In addition, all calls to `unimplemented!()` have been removed from the Redox `sys` module.
Related to https://github.com/rust-lang/rust/pull/45892
kennytm [Mon, 13 Nov 2017 09:09:41 +0000 (17:09 +0800)]
Rollup merge of #45892 - redox-os:is_absolute_fix, r=alexcrichton
Redox: Return true from Path::is_absolute if a Path contains root or a scheme
In Redox, different subsystems have different filesystem paths. However, the majority of applications using the `Path::is_absolute` function really only want to know if a path is absolute from the perspective of the scheme it is currently running in, usually `file:`. This makes both `file:/` and `/` return `true` from `Path::is_absolute`, meaning that most code does not have to check if it is running on Redox.
Code that wants to know if a path contains a scheme can implement such a check on its own.
Related to https://github.com/rust-lang/rust/pull/45893