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

Tracking issue for impl Trait in const and static items and let bindings #63065

Open
2 of 6 tasks
Centril opened this issue Jul 28, 2019 · 4 comments
Open
2 of 6 tasks
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` requires-nightly This issue requires a nightly compiler in some way. S-tracking-impl-incomplete Status: The implementation is incomplete. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Jul 28, 2019

As provided for by rust-lang/rfcs#2071, this is a tracking issue for impl Trait in:

  • const items
  • static items
  • let bindings

Steps:

Unresolved questions:

  • Should the part about let bindings be recast more generally to be about coercions? This would allow foo as impl Debug and foo: impl Debug as well.

Blocking issues:

Incomplete. Search the F-impl_trait_in_bindings issue.

@Centril Centril added B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. B-unstable Blocker: Implemented in the nightly compiler and unstable. A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC labels Jul 28, 2019
@Centril Centril added F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` requires-nightly This issue requires a nightly compiler in some way. and removed requires-nightly This issue requires a nightly compiler in some way. labels Jul 28, 2019
Centril added a commit to Centril/rust that referenced this issue Jul 29, 2019
strohel added a commit to strohel/rust that referenced this issue Mar 2, 2020
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.
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Oct 28, 2020
=== 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

==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Oct 28, 2020
=== 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

==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Nov 15, 2020
=== 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`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Nov 15, 2020
=== 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`.
==============
@Rua
Copy link
Contributor

Rua commented Jan 12, 2021

What's the status on this now? Is it ready to be stabilised?

github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Mar 17, 2021
=== 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`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue May 12, 2021
=== 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`.
==============
github-actions bot pushed a commit to rust-lang/glacier that referenced this issue Jun 10, 2021
=== 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`.
==============
JohnTitor pushed a commit to rust-lang/glacier that referenced this issue Jun 10, 2021
=== 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 <rustbot@users.noreply.github.com>
@QuineDot
Copy link

The implementation was removed as part of #86729 and the corresponding checkbox should be unchecked.

@NobodyXu
Copy link
Contributor

Pinging, is there any progress on this feature?

@ctrlcctrlv
Copy link

Hopefully there will be soon, as it was the cleanest way for me to solve an issue just now.

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 11, 2024
…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.
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 14, 2024
…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.
flip1995 pushed a commit to flip1995/rust that referenced this issue Dec 15, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` requires-nightly This issue requires a nightly compiler in some way. S-tracking-impl-incomplete Status: The implementation is incomplete. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants