Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement impl Trait in argument position (RFC1951, Universal quantification) #45918

Merged
merged 28 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
779fc37
Move E0562 to librustc from librustc_typeck
chrisvittal Nov 10, 2017
8fd48e7
Split hir::TyImplTrait, move checks to HIR lowering
chrisvittal Nov 10, 2017
e4c7e2c
Add bool item is_in_impl_trait to LoweringContext
chrisvittal Nov 10, 2017
94df3c5
Alter type collection to collect impl Trait bounds
chrisvittal Nov 10, 2017
f225fe4
Add collection of impl Trait argument lifetimes
chrisvittal Nov 10, 2017
109f2dd
Add new error comparision to hide desugaring
chrisvittal Nov 10, 2017
bdff946
Add universal_impl_trait feature gate
chrisvittal Nov 10, 2017
06dff80
Add/Modify tests for argument position impl Trait
chrisvittal Nov 10, 2017
a23bea5
Fix style and grammar
chrisvittal Nov 10, 2017
7d25d2e
Remove unamed parameters
chrisvittal Nov 10, 2017
04ad8fd
Fix unclosed delimiter in sample error
chrisvittal Nov 10, 2017
b4c1aef
Add universal_impl_trait unstable-book entry
chrisvittal Nov 10, 2017
2520279
test we reject equivalent signatures with more than one argument
nikomatsakis Nov 13, 2017
ebc4408
rename many-cases to where-allowed
nikomatsakis Nov 13, 2017
37dd79f
extend `where-allowed.rs` with many more cases
nikomatsakis Nov 13, 2017
6f9fb91
rename `equality-universal` to a more extensible naming scheme
nikomatsakis Nov 13, 2017
9d71bf6
add some more positive tests
nikomatsakis Nov 13, 2017
15001ee
add a UI test showing the current output from an impl trait type
nikomatsakis Nov 13, 2017
2786ea6
some tests featuring multiple bounds, other errors
nikomatsakis Nov 13, 2017
7e9948f
Add proper names to impl Trait parameters.
chrisvittal Nov 14, 2017
9b4372e
Incorporate review feedback
chrisvittal Nov 14, 2017
b276429
Disallow all impl Trait within Fn trait sugar
chrisvittal Nov 15, 2017
f710d41
Add/Fix stderr references for impl Trait ui tests
chrisvittal Nov 15, 2017
22f0940
Add cases to where-allowed.rs
chrisvittal Nov 15, 2017
517db79
Renumber error to fix tidy
chrisvittal Nov 15, 2017
337dee4
Remove Fn trait + impl Trait rustdoc tests
chrisvittal Nov 15, 2017
98d5db3
add a new test featuring two impl traits to show what it looks like
nikomatsakis Nov 15, 2017
4ce61b7
Change clippy to broken after hir::Ty enum change
chrisvittal Nov 15, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# `universal_impl_trait`

The tracking issue for this feature is: [#34511].

[#34511]: https://github.com/rust-lang/rust/issues/34511

--------------------

The `universal_impl_trait` feature extends the [`conservative_impl_trait`]
feature allowing the `impl Trait` syntax in arguments (universal
quantification).

[`conservative_impl_trait`]: ./language-features/conservative-impl-trait.html

## Examples

```rust
#![feature(universal_impl_trait)]
use std::ops::Not;

fn any_zero(values: impl IntoIterator<Item = i32>) -> bool {
for val in values { if val == 0 { return true; } }
false
}

fn main() {
let test1 = -5..;
let test2 = vec![1, 8, 42, -87, 60];
assert!(any_zero(test1));
assert!(bool::not(any_zero(test2)));
}
```
40 changes: 40 additions & 0 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,46 @@ If you want to get command-line arguments, use `std::env::args`. To exit with a
specified exit code, use `std::process::exit`.
"##,

E0562: r##"
Abstract return types (written `impl Trait` for some trait `Trait`) are only
allowed as function return types.

Erroneous code example:

```compile_fail,E0562
#![feature(conservative_impl_trait)]

fn main() {
let count_to_ten: impl Iterator<Item=usize> = 0..10;
// error: `impl Trait` not allowed outside of function and inherent method
// return types
for i in count_to_ten {
println!("{}", i);
}
}
```

Make sure `impl Trait` only appears in return-type position.

```
#![feature(conservative_impl_trait)]

fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
0..n
}

fn main() {
for i in count_to_n(10) { // ok!
println!("{}", i);
}
}
```

See [RFC 1522] for more details.

[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
"##,

E0591: r##"
Per [RFC 401][rfc401], if you have a function declaration `foo`:

Expand Down
5 changes: 4 additions & 1 deletion src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,10 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
}
visitor.visit_lifetime(lifetime);
}
TyImplTrait(ref bounds) => {
TyImplTraitExistential(ref bounds) => {
walk_list!(visitor, visit_ty_param_bound, bounds);
}
TyImplTraitUniversal(_, ref bounds) => {
walk_list!(visitor, visit_ty_param_bound, bounds);
}
TyTypeof(expression) => {
Expand Down
Loading