Skip to content

lazy_type_alias: return type references an anonymous lifetime, which is not constrained by the fn input types  #114220

Closed
@matthiaskrgr

Description

@matthiaskrgr

I tried this code:
tests/ui/late-bound-lifetimes/late_bound_through_alias.rs

#![feature(lazy_type_alias)]
// check-pass

fn f(_: X) -> X {
    unimplemented!()
}

fn g<'a>(_: X<'a>) -> X<'a> {
    unimplemented!()
}

type X<'a> = &'a ();

fn main() {
    let _: for<'a> fn(X<'a>) -> X<'a> = g;
    let _: for<'a> fn(X<'a>) -> X<'a> = f;
}

without -Zcrate-attr=feature(lazy_type_alias) : no warnings

with -Zcrate-attr=feature(lazy_type_alias):

error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
 --> tests/ui/late-bound-lifetimes/late_bound_through_alias.rs:3:15
  |
3 | fn f(_: X) -> X {
  |               ^
  |
  = note: lifetimes appearing in an associated or opaque type are not considered constrained
  = note: consider introducing a named lifetime parameter

error[E0581]: return type references lifetime `'a`, which is not constrained by the fn input types
 --> tests/ui/late-bound-lifetimes/late_bound_through_alias.rs:7:23
  |
7 | fn g<'a>(_: X<'a>) -> X<'a> {
  |                       ^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0581`.
rustc 1.73.0-nightly (04abc370b 2023-07-28)
binary: rustc
commit-hash: 04abc370b9f3855b28172b65a7f7d5a433f41412
commit-date: 2023-07-28
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.F-lazy_type_alias`#![feature(lazy_type_alias)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions