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

type-alias-impl-trait with lifetime param can't be used in fn input #96564

Closed
aliemjay opened this issue Apr 29, 2022 · 1 comment · Fixed by #96903
Closed

type-alias-impl-trait with lifetime param can't be used in fn input #96564

aliemjay opened this issue Apr 29, 2022 · 1 comment · Fixed by #96903
Assignees
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

aliemjay commented Apr 29, 2022

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=f758d0536248cf9a970114bf75257429

#![feature(type_alias_impl_trait)]
type Ty<'a> = impl FnOnce() -> &'a str;
fn defining(s: &str) -> Ty<'_> { move || s }
fn execute(ty: Ty<'_>) -> &str { ty() }

I expected to see this happen: program compiles

Instead, this happened:

error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
 --> src/lib.rs:4:27
  |
4 | fn execute(ty: Ty<'_>) -> &str { ty() }
  |                           ^^^^
  |
  = note: lifetimes appearing in an associated type are not considered constrained

Same code compiles if type params are used instead:

#![feature(type_alias_impl_trait)]
type Ty<T> = impl FnOnce() -> T;
fn defining<T>(s: T) -> Ty<T> { move || s }
fn execute<T>(ty: Ty<T>) -> T { ty() }

Meta

Nightly playground : 1.62.0-nightly (2022-04-28 e85edd9)

Backtrace

<backtrace>

@aliemjay aliemjay added the C-bug Category: This is a bug. label Apr 29, 2022
@aliemjay
Copy link
Member Author

aliemjay commented Apr 30, 2022

Simpler:

#![feature(type_alias_impl_trait)]
type Ty<'a> = impl Sized;
fn defining(s: &str) -> Ty<'_> { s }
fn execute(ty: Ty<'_>) -> &str { todo!() }

@rustbot label F-type_alias_impl_trait T-compiler

@rustbot rustbot added F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 30, 2022
@oli-obk oli-obk added the A-borrow-checker Area: The borrow checker label Apr 30, 2022
@oli-obk oli-obk self-assigned this May 3, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 10, 2022
…aints, r=compiler-errors

Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes

fixes rust-lang#96564

TLDR:

```rust
fn execute(ty: Ty<'_>) -> &str { todo!() }
```

(`Ty` being a type alias impl trait) used to produce the following error before this PR

```
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
 --> src/lib.rs:4:27
  |
4 | fn execute(ty: Ty<'_>) -> &str { todo!() }
  |                           ^^^^
  |
  = note: lifetimes appearing in an associated type are not considered constrained
```
@bors bors closed this as completed in 17a735b May 11, 2022
@oli-obk oli-obk moved this from Todo to Done in type alias impl trait stabilization Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
3 participants