-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Tracking issue for impl Trait
in const
and static
items and let
bindings
#63065
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
Comments
…varkor Update `impl Trait` gate issues cc rust-lang#63065 cc rust-lang#63063 r? @varkor cc @alexreg
The existing issue rust-lang#34511 has been closed and replaced by meta-issue rust-lang#63066. The concrete part of the new meta-issue for this feature should be rust-lang#63065.
=== stdout === === stderr === warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> <anon>:1:12 | 1 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information warning: function is never used: `foo` --> <anon>:16:8 | 16 | fn foo<T: Trait<Assoc=u32>>() { | ^^^ | = note: `#[warn(dead_code)]` on by default warning: 2 warnings emitted ==============
=== stdout === === stderr === /home/runner/work/glacier/glacier/ices/75962.sh: line 3: impl: command not found warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> <anon>:3:12 | 3 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information warning: function is never used: `foo` --> <anon>:29:8 | 29 | fn foo<T: Trait<Assoc=u32>>() { | ^^^ | = note: `#[warn(dead_code)]` on by default warning: 2 warnings emitted ==============
=== stdout === === stderr === warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/78721.rs:1:12 | 1 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information error: `async` blocks are not allowed in constants --> /home/runner/work/glacier/glacier/ices/78721.rs:5:57 | 5 | let f: impl core::future::Future<Output = u8> = async { 1 }; | ^^^^^^^^^^^ error[E0493]: destructors cannot be evaluated at compile-time --> /home/runner/work/glacier/glacier/ices/78721.rs:5:13 | 5 | let f: impl core::future::Future<Output = u8> = async { 1 }; | ^ constants cannot evaluate destructors 6 | 1 7 | }], | - value is dropped here error: aborting due to 2 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0493`. ==============
=== stdout === === stderr === warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/78722.rs:2:12 | 2 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information error: `async` blocks are not allowed in constants --> /home/runner/work/glacier/glacier/ices/78722.rs:11:20 | 11 | let f: F = async { 1 }; | ^^^^^^^^^^^ error[E0493]: destructors cannot be evaluated at compile-time --> /home/runner/work/glacier/glacier/ices/78722.rs:11:13 | 11 | let f: F = async { 1 }; | ^ constants cannot evaluate destructors 12 | 1 13 | }], | - value is dropped here error: aborting due to 2 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0493`. ==============
What's the status on this now? Is it ready to be stabilised? |
=== stdout === === stderr === error[E0658]: `impl Trait` in type aliases is unstable --> /home/runner/work/glacier/glacier/ices/53092.rs:21:18 | 21 | type Bug<T, U> = impl Fn(T) -> U + Copy; | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #63063 <rust-lang/rust#63063> for more information = help: add `#![feature(min_type_alias_impl_trait)]` to the crate attributes to enable warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/53092.rs:3:12 | 3 | #![feature(type_alias_impl_trait)] | ^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63063 <rust-lang/rust#63063> for more information error[E0658]: type alias impl trait is not permitted here --> /home/runner/work/glacier/glacier/ices/53092.rs:23:32 | 23 | const CONST_BUG: Bug<u8, ()> = transmute(|_: u8| ()); | ^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #63065 <rust-lang/rust#63065> for more information = help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable error: concrete type differs from previous defining opaque type use --> /home/runner/work/glacier/glacier/ices/53092.rs:25:1 | 25 | fn make_bug<T, U: From<T>>() -> Bug<T, U> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `[type error]`, got `[closure@/home/runner/work/glacier/glacier/ices/53092.rs:26:5: 26:17]` | note: previous use here --> /home/runner/work/glacier/glacier/ices/53092.rs:23:1 | 23 | const CONST_BUG: Bug<u8, ()> = transmute(|_: u8| ()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0658`. ==============
=== stdout === === stderr === error[E0557]: feature has been removed --> /home/runner/work/glacier/glacier/ices/53092.rs:1:12 | 1 | #![feature(const_fn)] | ^^^^^^^^ feature has been removed | = note: split into finer-grained feature gates warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/53092.rs:3:12 | 3 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/53092.rs:5:12 | 5 | #![feature(type_alias_impl_trait)] | ^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #63063 <rust-lang/rust#63063> for more information error: aborting due to previous error; 2 warnings emitted For more information about this error, try `rustc --explain E0557`. ==============
=== stdout === === stderr === warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/85113.rs:2:12 | 2 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ | note: hidden type `&'<empty> str` captures lifetime smaller than the function body --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ error[E0477]: the type `&'<empty> str` does not fulfill the required lifetime --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ | note: type must outlive the lifetime `'a` as defined on the item at 4:23 --> /home/runner/work/glacier/glacier/ices/85113.rs:4:23 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ | = note: first, the lifetime cannot outlive the empty lifetime... note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the item at 4:23... --> /home/runner/work/glacier/glacier/ices/85113.rs:4:23 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^ note: ...so that the types are compatible --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ = note: expected `Output<'a>` found `Output<'_>` error: aborting due to 3 previous errors; 1 warning emitted Some errors have detailed explanations: E0477, E0495, E0700. For more information about an error, try `rustc --explain E0477`. ==============
=== stdout === === stderr === warning: the feature `impl_trait_in_bindings` is incomplete and may not be safe to use and/or cause compiler crashes --> /home/runner/work/glacier/glacier/ices/85113.rs:2:12 | 2 | #![feature(impl_trait_in_bindings)] | ^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(incomplete_features)]` on by default = note: see issue #63065 <rust-lang/rust#63065> for more information error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ | note: hidden type `&'<empty> str` captures lifetime smaller than the function body --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ error[E0477]: the type `&'<empty> str` does not fulfill the required lifetime --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ | note: type must outlive the lifetime `'a` as defined on the item at 4:23 --> /home/runner/work/glacier/glacier/ices/85113.rs:4:23 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ | = note: first, the lifetime cannot outlive the empty lifetime... note: ...but the lifetime must also be valid for the lifetime `'a` as defined on the item at 4:23... --> /home/runner/work/glacier/glacier/ices/85113.rs:4:23 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^ note: ...so that the types are compatible --> /home/runner/work/glacier/glacier/ices/85113.rs:4:29 | 4 | type OpaqueOutputImpl<'a> = impl Output<'a> + 'a; | ^^^^^^^^^^^^^^^^^^^^ = note: expected `Output<'a>` found `Output<'_>` error: aborting due to 3 previous errors; 1 warning emitted Some errors have detailed explanations: E0477, E0495, E0700. For more information about an error, try `rustc --explain E0477`. ============== Co-authored-by: rustbot <[email protected]>
The implementation was removed as part of #86729 and the corresponding checkbox should be unchecked. |
Pinging, is there any progress on this feature? |
Hopefully there will be soon, as it was the cleanest way for me to solve an issue just now. |
…gs, r=<try> (Re-)Implement `impl_trait_in_bindings` This reimplements the `impl_trait_in_bindings` feature for local bindings. "`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference): ```rust let _: impl Fn(&u8) -> &u8 = |x| x; ``` They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes: ```rust trait Static: 'static {} impl<T> Static for T where T: 'static {} let local = 1; let x: impl Static = &local; //~^ ERROR `local` does not live long enough ``` r? oli-obk cc rust-lang#63065 --- Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example: ```rust type TAIT = impl Display; let local = 0; let x: TAIT = &local; //~^ ERROR `local` does not live long enough ``` That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here. --- I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
…gs, r=oli-obk (Re-)Implement `impl_trait_in_bindings` This reimplements the `impl_trait_in_bindings` feature for local bindings. "`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference): ```rust let _: impl Fn(&u8) -> &u8 = |x| x; ``` They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes: ```rust trait Static: 'static {} impl<T> Static for T where T: 'static {} let local = 1; let x: impl Static = &local; //~^ ERROR `local` does not live long enough ``` r? oli-obk cc rust-lang#63065 --- Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example: ```rust type TAIT = impl Display; let local = 0; let x: TAIT = &local; //~^ ERROR `local` does not live long enough ``` That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here. --- I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
…gs, r=oli-obk (Re-)Implement `impl_trait_in_bindings` This reimplements the `impl_trait_in_bindings` feature for local bindings. "`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference): ```rust let _: impl Fn(&u8) -> &u8 = |x| x; ``` They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes: ```rust trait Static: 'static {} impl<T> Static for T where T: 'static {} let local = 1; let x: impl Static = &local; //~^ ERROR `local` does not live long enough ``` r? oli-obk cc rust-lang#63065 --- Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example: ```rust type TAIT = impl Display; let local = 0; let x: TAIT = &local; //~^ ERROR `local` does not live long enough ``` That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here. --- I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
Without #![feature(impl_trait_in_bindings)]: error[E0562]: `impl Trait` is not allowed in paths --> tests/test.rs:1680:42 | 1680 | async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the type of variable bindings --> tests/test.rs:1680:42 | 1680 | async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `impl Trait` is only allowed in arguments and return types of functions and methods = note: see issue #63065 <rust-lang/rust#63065> for more information = help: add `#![feature(impl_trait_in_bindings)]` to the crate attributes to enable = note: this compiler was built on 2025-01-02; consider upgrading it if it is out of date With #![feature(impl_trait_in_bindings)]: error[E0562]: `impl Trait` is not allowed in paths --> tests/test.rs:1680:42 | 1680 | async fn method(&self) -> Result<impl AsRef<str> + Send + Sync, Self::Error> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `impl Trait` is only allowed in arguments and return types of functions and methods
The question I opened on Stack Overflow on this topic: https://stackoverflow.com/questions/79643282/why-errore0121-the-placeholder-is-not-allowed-within-types-on-item-signat. A workaround can be found there too. |
Uh oh!
There was an error while loading. Please reload this page.
As provided for by rust-lang/rfcs#2071, this is a tracking issue for
impl Trait
in:const
itemsstatic
itemslet
bindingsSteps:
let
: (Re-)Implementimpl_trait_in_bindings
#134185Unresolved questions:
let
bindings be recast more generally to be about coercions? This would allowfoo as impl Debug
andfoo: impl Debug
as well.Blocking issues:
Incomplete. Search the
F-impl_trait_in_bindings
issue.impl_trait_in_bindings
is a breaking change #83021impl_trait_in_bindings
and pick-constraint region bounds #61773The text was updated successfully, but these errors were encountered: