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

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

Closed
matthiaskrgr opened this issue Jul 29, 2023 · 2 comments · Fixed by #121344
Assignees
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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
@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example F-lazy_type_alias `#![feature(lazy_type_alias)]` labels Jul 29, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 29, 2023
@compiler-errors
Copy link
Member

Note for lazy_type_alias, we probably should eagerly normalize before doing generic arg constraint checks.

@compiler-errors compiler-errors added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 29, 2023
@matthiaskrgr
Copy link
Member Author

#![feature(lazy_type_alias)]
fn f(_: X) -> X {
    unimplemented!()
}

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

@compiler-errors compiler-errors removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jul 29, 2023
@fmease fmease self-assigned this Oct 13, 2023
@fmease fmease added the A-lifetimes Area: Lifetimes / regions label Feb 8, 2024
@bors bors closed this as completed in 532b3ea Feb 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 21, 2024
Rollup merge of rust-lang#121344 - fmease:lta-constr-by-input, r=oli-obk

Expand weak alias types before collecting constrained/referenced late bound regions + refactorings

Fixes rust-lang#114220.
Follow-up to rust-lang#120780.

r? `@oli-obk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. F-lazy_type_alias `#![feature(lazy_type_alias)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants