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%.
Fix a bug where the rustfmt tarball was not being produced
r? @alexcrichton
This makes rustfmt a dep of 'extended', which seems to be necessary for the rustfmt dist step to actually get run.
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](3fc9e3705f/src/librustc_typeck/check/compare_method.rs (L714-L725))
r? @nikomatsakis
This new way is **slightly** less expressive (I would be shocked if it
affects any code, though) when it comes to higher-ranked bounds or a
few other weird tricks. But we don't handle those consistently
regardless, and the new way does not require normalization and is just
wildly simpler.
When we get around to resolving regions, we really ought to take region
obligations into account. There is one case where they are presently
being ignored. Keep ignoring them there for now but leave a TODO.
We already disallowed them to be in the arg list, such as
Fn(impl Debug), but now we disallow Fn() -> impl Debug.
Also remove the ImplTraitContext argument from the function
lower_parenthesized_parameter_data as it is now unused.
Comment out part of test run-pass/impl-trait/xcrate.rs that now fails.
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.
First some background:
To the compiler, the following two signatures in the trait vs the impl
are the same.
```rust
trait Foo {
fn foo(&self, &impl Debug);
}
impl Foo for () {
fn foo<U: Debug>(&self, x: &U) { ... }
}
```
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.
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.
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.