diff options
| author | bors <bors@rust-lang.org> | 2017-11-15 22:47:54 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-15 22:47:54 +0000 |
| commit | b8c70b0fdf7dea9bfd1834e61d32fc40f0c70db4 (patch) | |
| tree | 74888938d7fc3c771fceebf683acf2a7c7a1dcf8 /src/libsyntax | |
| parent | fa26421f56e385b1055e65b29a55b36bb2eae23e (diff) | |
| parent | 4ce61b73620ade330bbafc3c6d56a0447bac2ca3 (diff) | |
| download | rust-b8c70b0fdf7dea9bfd1834e61d32fc40f0c70db4.tar.gz rust-b8c70b0fdf7dea9bfd1834e61d32fc40f0c70db4.zip | |
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)
r? @nikomatsakis
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index b6cb3ac1308..97eec3a21e9 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -275,6 +275,9 @@ declare_features! ( // Allows `impl Trait` in function return types. (active, conservative_impl_trait, "1.12.0", Some(34511)), + // Allows `impl Trait` in function arguments. + (active, universal_impl_trait, "1.23.0", Some(34511)), + // The `!` type (active, never_type, "1.13.0", Some(35121)), @@ -1451,10 +1454,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { ast::TyKind::BareFn(ref bare_fn_ty) => { self.check_abi(bare_fn_ty.abi, ty.span); } - ast::TyKind::ImplTrait(..) => { - gate_feature_post!(&self, conservative_impl_trait, ty.span, - "`impl Trait` is experimental"); - } ast::TyKind::Never => { gate_feature_post!(&self, never_type, ty.span, "The `!` type is experimental"); |
