Stabilize universal_impl_trait
This commit is contained in:
@@ -1,32 +0,0 @@
|
|||||||
# `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)));
|
|
||||||
}
|
|
||||||
```
|
|
||||||
@@ -1143,17 +1143,6 @@ impl<'a> LoweringContext<'a> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
ImplTraitContext::Universal(def_id) => {
|
ImplTraitContext::Universal(def_id) => {
|
||||||
let has_feature = self.sess.features_untracked().universal_impl_trait;
|
|
||||||
if !t.span.allows_unstable() && !has_feature {
|
|
||||||
emit_feature_err(
|
|
||||||
&self.sess.parse_sess,
|
|
||||||
"universal_impl_trait",
|
|
||||||
t.span,
|
|
||||||
GateIssue::Language,
|
|
||||||
"`impl Trait` in argument position is experimental",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let def_node_id = self.next_id().node_id;
|
let def_node_id = self.next_id().node_id;
|
||||||
|
|
||||||
// Add a definition for the in-band TyParam
|
// Add a definition for the in-band TyParam
|
||||||
|
|||||||
@@ -70,7 +70,7 @@
|
|||||||
#![feature(specialization)]
|
#![feature(specialization)]
|
||||||
#![feature(unboxed_closures)]
|
#![feature(unboxed_closures)]
|
||||||
#![feature(underscore_lifetimes)]
|
#![feature(underscore_lifetimes)]
|
||||||
#![feature(universal_impl_trait)]
|
#![cfg_attr(stage0, feature(universal_impl_trait))]
|
||||||
#![feature(trace_macros)]
|
#![feature(trace_macros)]
|
||||||
#![feature(trusted_len)]
|
#![feature(trusted_len)]
|
||||||
#![feature(catch_expr)]
|
#![feature(catch_expr)]
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
#![feature(underscore_lifetimes)]
|
#![feature(underscore_lifetimes)]
|
||||||
#![feature(macro_vis_matcher)]
|
#![feature(macro_vis_matcher)]
|
||||||
#![feature(allow_internal_unstable)]
|
#![feature(allow_internal_unstable)]
|
||||||
#![feature(universal_impl_trait)]
|
#![cfg_attr(stage0, feature(universal_impl_trait))]
|
||||||
|
|
||||||
#![cfg_attr(unix, feature(libc))]
|
#![cfg_attr(unix, feature(libc))]
|
||||||
#![cfg_attr(test, feature(test))]
|
#![cfg_attr(test, feature(test))]
|
||||||
|
|||||||
@@ -4600,7 +4600,6 @@ This error indicates that there is a mismatch between generic parameters and
|
|||||||
impl Trait parameters in a trait declaration versus its impl.
|
impl Trait parameters in a trait declaration versus its impl.
|
||||||
|
|
||||||
```compile_fail,E0643
|
```compile_fail,E0643
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
trait Foo {
|
trait Foo {
|
||||||
fn foo(&self, _: &impl Iterator);
|
fn foo(&self, _: &impl Iterator);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -279,9 +279,6 @@ declare_features! (
|
|||||||
// Allows `impl Trait` in function return types.
|
// Allows `impl Trait` in function return types.
|
||||||
(active, conservative_impl_trait, "1.12.0", Some(34511), None),
|
(active, conservative_impl_trait, "1.12.0", Some(34511), None),
|
||||||
|
|
||||||
// Allows `impl Trait` in function arguments.
|
|
||||||
(active, universal_impl_trait, "1.23.0", Some(34511), None),
|
|
||||||
|
|
||||||
// Allows exhaustive pattern matching on types that contain uninhabited types.
|
// Allows exhaustive pattern matching on types that contain uninhabited types.
|
||||||
(active, exhaustive_patterns, "1.13.0", None, None),
|
(active, exhaustive_patterns, "1.13.0", None, None),
|
||||||
|
|
||||||
@@ -566,6 +563,8 @@ declare_features! (
|
|||||||
// Copy/Clone closures (RFC 2132)
|
// Copy/Clone closures (RFC 2132)
|
||||||
(accepted, clone_closures, "1.26.0", Some(44490), None),
|
(accepted, clone_closures, "1.26.0", Some(44490), None),
|
||||||
(accepted, copy_closures, "1.26.0", Some(44490), None),
|
(accepted, copy_closures, "1.26.0", Some(44490), None),
|
||||||
|
// Allows `impl Trait` in function arguments.
|
||||||
|
(accepted, universal_impl_trait, "1.26.0", Some(34511), None),
|
||||||
);
|
);
|
||||||
|
|
||||||
// If you change this, please modify src/doc/unstable-book as well. You must
|
// If you change this, please modify src/doc/unstable-book as well. You must
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
trait Foo {
|
trait Foo {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
trait Foo {
|
trait Foo {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
//! A simple test for testing many permutations of allowedness of
|
//! A simple test for testing many permutations of allowedness of
|
||||||
//! impl Trait
|
//! impl Trait
|
||||||
#![feature(conservative_impl_trait, universal_impl_trait, dyn_trait)]
|
#![feature(conservative_impl_trait, dyn_trait)]
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
// Allowed
|
// Allowed
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
//[nll] compile-flags: -Znll -Zborrowck=mir
|
//[nll] compile-flags: -Znll -Zborrowck=mir
|
||||||
|
|
||||||
#![feature(conservative_impl_trait,
|
#![feature(conservative_impl_trait,
|
||||||
universal_impl_trait,
|
|
||||||
fn_traits,
|
fn_traits,
|
||||||
step_trait,
|
step_trait,
|
||||||
unboxed_closures,
|
unboxed_closures,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(conservative_impl_trait, underscore_lifetimes, universal_impl_trait)]
|
#![feature(conservative_impl_trait, underscore_lifetimes)]
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
fn hrtb(f: impl Fn(&u32) -> u32) -> u32 {
|
fn hrtb(f: impl Fn(&u32) -> u32) -> u32 {
|
||||||
f(&22) + f(&44)
|
f(&22) + f(&44)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
fn hrtb(f: impl for<'a> Fn(&'a u32) -> &'a u32) -> u32 {
|
fn hrtb(f: impl for<'a> Fn(&'a u32) -> &'a u32) -> u32 {
|
||||||
f(&22) + f(&44)
|
f(&22) + f(&44)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
fn check_display_eq(iter: &Vec<impl Display>) {
|
fn check_display_eq(iter: &Vec<impl Display>) {
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
fn check_display_eq(iter: impl IntoIterator<Item = impl Display>) {
|
fn check_display_eq(iter: impl IntoIterator<Item = impl Display>) {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
trait InTraitDefnParameters {
|
trait InTraitDefnParameters {
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
fn foo(f: impl Display + Clone) -> String {
|
fn foo(f: impl Display + Clone) -> String {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
#![feature(in_band_lifetimes, universal_impl_trait, conservative_impl_trait)]
|
#![feature(in_band_lifetimes, conservative_impl_trait)]
|
||||||
|
|
||||||
fn foo(x: &'x u8) -> &'x u8 { x }
|
fn foo(x: &'x u8) -> &'x u8 { x }
|
||||||
fn foo2(x: &'a u8, y: &u8) -> &'a u8 { x }
|
fn foo2(x: &'a u8, y: &u8) -> &'a u8 { x }
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
#![feature(conservative_impl_trait)]
|
#![feature(conservative_impl_trait)]
|
||||||
#![deny(non_camel_case_types)]
|
#![deny(non_camel_case_types)]
|
||||||
|
|
||||||
|
|||||||
@@ -8,5 +8,4 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
pub fn ice(f: impl Fn()) {}
|
pub fn ice(f: impl Fn()) {}
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
|
||||||
// file at the top-level directory of this distribution and at
|
|
||||||
// http://rust-lang.org/COPYRIGHT.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
||||||
// option. This file may not be copied, modified, or distributed
|
|
||||||
// except according to those terms.
|
|
||||||
|
|
||||||
// gate-test-universal_impl_trait
|
|
||||||
|
|
||||||
fn foo(x: impl std::fmt::Debug) { print!("{:?}", x); }
|
|
||||||
//~^ ERROR `impl Trait` in argument position is experimental
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
error[E0658]: `impl Trait` in argument position is experimental (see issue #34511)
|
|
||||||
--> $DIR/feature-gate-universal.rs:13:11
|
|
||||||
|
|
|
||||||
LL | fn foo(x: impl std::fmt::Debug) { print!("{:?}", x); }
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= help: add #![feature(universal_impl_trait)] to the crate attributes to enable
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0658`.
|
|
||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
fn foo(x: impl Debug) -> String {
|
fn foo(x: impl Debug) -> String {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/universal-mismatched-type.rs:16:5
|
--> $DIR/universal-mismatched-type.rs:14:5
|
||||||
|
|
|
|
||||||
LL | fn foo(x: impl Debug) -> String {
|
LL | fn foo(x: impl Debug) -> String {
|
||||||
| ------ expected `std::string::String` because of return type
|
| ------ expected `std::string::String` because of return type
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
fn foo(x: impl Debug, y: impl Debug) -> String {
|
fn foo(x: impl Debug, y: impl Debug) -> String {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/universal-two-impl-traits.rs:17:9
|
--> $DIR/universal-two-impl-traits.rs:15:9
|
||||||
|
|
|
|
||||||
LL | a = y; //~ ERROR mismatched
|
LL | a = y; //~ ERROR mismatched
|
||||||
| ^ expected type parameter, found a different type parameter
|
| ^ expected type parameter, found a different type parameter
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![feature(universal_impl_trait)]
|
|
||||||
|
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
fn foo(f: impl Display + Clone) -> String {
|
fn foo(f: impl Display + Clone) -> String {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
error[E0425]: cannot find function `wants_clone` in this scope
|
error[E0425]: cannot find function `wants_clone` in this scope
|
||||||
--> $DIR/universal_wrong_bounds.rs:18:5
|
--> $DIR/universal_wrong_bounds.rs:16:5
|
||||||
|
|
|
|
||||||
LL | wants_clone(f); //~ ERROR cannot find
|
LL | wants_clone(f); //~ ERROR cannot find
|
||||||
| ^^^^^^^^^^^ did you mean `wants_cone`?
|
| ^^^^^^^^^^^ did you mean `wants_cone`?
|
||||||
|
|
||||||
error[E0405]: cannot find trait `Debug` in this scope
|
error[E0405]: cannot find trait `Debug` in this scope
|
||||||
--> $DIR/universal_wrong_bounds.rs:21:24
|
--> $DIR/universal_wrong_bounds.rs:19:24
|
||||||
|
|
|
|
||||||
LL | fn wants_debug(g: impl Debug) { } //~ ERROR cannot find
|
LL | fn wants_debug(g: impl Debug) { } //~ ERROR cannot find
|
||||||
| ^^^^^ not found in this scope
|
| ^^^^^ not found in this scope
|
||||||
@@ -15,7 +15,7 @@ LL | use std::fmt::Debug;
|
|||||||
|
|
|
|
||||||
|
|
||||||
error[E0405]: cannot find trait `Debug` in this scope
|
error[E0405]: cannot find trait `Debug` in this scope
|
||||||
--> $DIR/universal_wrong_bounds.rs:22:26
|
--> $DIR/universal_wrong_bounds.rs:20:26
|
||||||
|
|
|
|
||||||
LL | fn wants_display(g: impl Debug) { } //~ ERROR cannot find
|
LL | fn wants_display(g: impl Debug) { } //~ ERROR cannot find
|
||||||
| ^^^^^ not found in this scope
|
| ^^^^^ not found in this scope
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
#![feature(dyn_trait, conservative_impl_trait, universal_impl_trait)]
|
#![feature(dyn_trait, conservative_impl_trait)]
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::option;
|
use std::option;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
#![allow(warnings)]
|
#![allow(warnings)]
|
||||||
#![feature(in_band_lifetimes, universal_impl_trait)]
|
#![feature(in_band_lifetimes)]
|
||||||
|
|
||||||
fn bar<F>(x: &F) where F: Fn(&'a u32) {} //~ ERROR must be explicitly
|
fn bar<F>(x: &F) where F: Fn(&'a u32) {} //~ ERROR must be explicitly
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
#![feature(conservative_impl_trait, universal_impl_trait)]
|
#![feature(conservative_impl_trait)]
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user