Commit Graph

70243 Commits

Author SHA1 Message Date
Nick Cameron
262029eca9 Fix a bug where the rustfmt tarball was not being produced 2017-11-16 16:02:18 +13:00
bors
42ea30c8b0 Auto merge of #45692 - steveklabnik:ship-cargo-book, r=alexcrichton
Start shipping the Cargo book

Fixes #44910
Fixes #39588

See both of those bugs for more details.
2017-11-16 01:16:58 +00:00
Dan Gohman
ac48348db8 Update the compiler-builtins to latest master. 2017-11-15 16:07:48 -08:00
bors
b8c70b0fdf 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](3fc9e3705f/src/librustc_typeck/check/compare_method.rs (L714-L725))

r? @nikomatsakis
2017-11-15 22:47:54 +00:00
Niko Matsakis
58c77600a5 move region resolution to be a sibling of region_inference
Temporary make various fields public.
2017-11-15 16:58:14 -05:00
Niko Matsakis
467f2ea653 extract lexical region resolution into its own sub-module 2017-11-15 16:50:32 -05:00
Niko Matsakis
efa09dbea5 modify MIR type-checker to process obligations as they are incurred 2017-11-15 16:50:32 -05:00
Niko Matsakis
9e8abd704a apply rustfmt to type_check 2017-11-15 16:50:30 -05:00
Niko Matsakis
6d672961fb thread location info through mir typeck (but do not use) 2017-11-15 16:49:23 -05:00
Niko Matsakis
15a2dfa324 move the OutlivesEnvironment into infer so that nll can use it
Unquestionably there is more cleanup to be done, but I'm not sure what
it should look like yet, so leaving it roughly as is.
2017-11-15 16:49:22 -05:00
Niko Matsakis
56e5eb5fd4 rename mod region_obligations to outlives::obligations 2017-11-15 16:49:22 -05:00
Niko Matsakis
0c81d0158f extract out the implied bounds code from regionck 2017-11-15 16:49:22 -05:00
Niko Matsakis
b587c1a024 regionck: only add implied bounds from root fn to free_region_map 2017-11-15 16:49:22 -05:00
Niko Matsakis
3cc44a569d do not invoke required_region_bounds in region_obligations
Instead, just search the param env predicates directly. This is
equivalent to what we were doing before but more efficient.
2017-11-15 16:49:22 -05:00
Niko Matsakis
e0630e8683 refactor how we extract outlives bounds from trait definitions
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.
2017-11-15 16:49:22 -05:00
Niko Matsakis
22cd041ba0 move the region_obligations processing code into InferCtxt 2017-11-15 16:49:21 -05:00
Niko Matsakis
d73be851fb extract regionck_outlives into a separate helper function
This helps make its inputs and outputs more clear.
2017-11-15 16:49:21 -05:00
Niko Matsakis
c925008a5c assert that we are consuming all of the region obligations
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.
2017-11-15 16:49:21 -05:00
Niko Matsakis
0d78e40e88 convert EXTRA_REQUIREMENT_IN_IMPL into a hard error
cc #37166
2017-11-15 16:49:21 -05:00
Niko Matsakis
64206b44b9 move region constraints into inference context 2017-11-15 16:49:21 -05:00
Niko Matsakis
4afe423fbf fulfill: remove dead code 2017-11-15 16:49:20 -05:00
Christopher Vittal
4ce61b7362 Change clippy to broken after hir::Ty enum change 2017-11-15 15:46:30 -05:00
Niko Matsakis
98d5db3350 add a new test featuring two impl traits to show what it looks like 2017-11-15 15:46:01 -05:00
Christopher Vittal
337dee4c80 Remove Fn trait + impl Trait rustdoc tests 2017-11-15 15:46:01 -05:00
Christopher Vittal
517db79c1f Renumber error to fix tidy 2017-11-15 15:46:01 -05:00
Christopher Vittal
22f0940f2d Add cases to where-allowed.rs 2017-11-15 15:46:01 -05:00
Christopher Vittal
f710d41f77 Add/Fix stderr references for impl Trait ui tests 2017-11-15 15:46:01 -05:00
Christopher Vittal
b276429734 Disallow all impl Trait within Fn trait sugar
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.
2017-11-15 15:46:01 -05:00
Christopher Vittal
9b4372e3b1 Incorporate review feedback
Add requested comments, restructure some small bits of code. Fix extern
declarations allowing impl Trait.
2017-11-15 15:46:01 -05:00
Chris Vittal
7e9948f92f 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.
2017-11-15 15:46:01 -05:00
Niko Matsakis
2786ea662d some tests featuring multiple bounds, other errors 2017-11-15 15:46:01 -05:00
Niko Matsakis
15001ee336 add a UI test showing the current output from an impl trait type 2017-11-15 15:46:01 -05:00
Niko Matsakis
9d71bf6d55 add some more positive tests
It'd be good to have a positive test for each case where it is
allowed, I should think.
2017-11-15 15:46:01 -05:00
Niko Matsakis
6f9fb91033 rename equality-universal to a more extensible naming scheme 2017-11-15 15:46:01 -05:00
Niko Matsakis
37dd79ff44 extend where-allowed.rs with many more cases
also merge disallowed and disallowed-2 into that set
2017-11-15 15:46:01 -05:00
Niko Matsakis
ebc4408fc0 rename many-cases to where-allowed 2017-11-15 15:46:01 -05:00
Niko Matsakis
2520279604 test we reject equivalent signatures with more than one argument 2017-11-15 15:46:01 -05:00
Christopher Vittal
b4c1aef1ca Add universal_impl_trait unstable-book entry 2017-11-15 15:46:01 -05:00
Christopher Vittal
04ad8fd7a5 Fix unclosed delimiter in sample error 2017-11-15 15:46:01 -05:00
Christopher Vittal
7d25d2e054 Remove unamed parameters 2017-11-15 15:46:01 -05:00
Christopher Vittal
a23bea5479 Fix style and grammar 2017-11-15 15:46:01 -05:00
Christopher Vittal
06dff80061 Add/Modify tests for argument position impl Trait 2017-11-15 15:46:01 -05:00
Christopher Vittal
bdff9463a0 Add universal_impl_trait feature gate
Move feature gate check to inside HIR lowering. Change error messages
and update tests.
2017-11-15 15:46:01 -05:00
Christopher Vittal
109f2dd36b Add new error comparision to hide desugaring
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.
2017-11-15 15:46:01 -05:00
Christopher Vittal
f225fe43f1 Add collection of impl Trait argument lifetimes 2017-11-15 15:46:01 -05:00
Christopher Vittal
94df3c5edf 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.
2017-11-15 15:46:01 -05:00
Christopher Vittal
e4c7e2c99a Add bool item is_in_impl_trait to LoweringContext
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.
2017-11-15 15:46:01 -05:00
Christopher Vittal
8fd48e7d59 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.
2017-11-15 15:46:01 -05:00
Christopher Vittal
779fc372c7 Move E0562 to librustc from librustc_typeck
With the check for impl trait moving from type checking to HIR lowering
the error needs to move too.
2017-11-15 15:46:01 -05:00
bors
fa26421f56 Auto merge of #45938 - vramana:fix-ice-45698, r=arielb1
Fix End-user description not implemented for field access on `TyClosure

- [x] Add Tests
2017-11-15 20:18:13 +00:00