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

HRTB with nested lifetimes and explicit lifetime bounds fails. #95921

Open
aliemjay opened this issue Apr 11, 2022 · 1 comment
Open

HRTB with nested lifetimes and explicit lifetime bounds fails. #95921

aliemjay opened this issue Apr 11, 2022 · 1 comment
Labels
A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@aliemjay
Copy link
Member

I tried this code:

trait Service<Req> {}

impl<'a, Req: 'a> Service<&'a Req> for u8 {}

fn main() {
    fn impl_check() where u8: for<'a, 'b> Service<&'a &'b u8> {}
    impl_check()
}

I expected to see this happen: code compiles fine

Instead, this happened: Implementation is not general enough Error

Removing the explicit lifetime bound on the impl fixes the problem:

- impl<'a, Req: 'a> Service<&'a Req> for u8 {}
+ impl<'a, Req> Service<&'a Req> for u8 {}

Meta

Reproduced on both the current stable and nightly branches.

rustc --version --verbose:

1.62.0-nightly (2022-04-09 8bf93e9b6791acee3a59)
Error Output

error: implementation of `Service` is not general enough
 [--> src/lib.rs:7:5
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021#)  |
7 |     impl_check()
  |     ^^^^^^^^^^ implementation of `Service` is not general enough
  |
  = note: `u8` must implement `Service<&'0 &'1 u8>`, for any two lifetimes `'0` and `'1`...
  = note: ...but it actually implements `Service<&'2 &'b u8>`, for some specific lifetime `'2`

@rustbot label A-typesystem, A-lifetimes, A-traits
@aliemjay aliemjay added the C-bug Category: This is a bug. label Apr 11, 2022
@rustbot rustbot added A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system A-type-system Area: Type system labels Apr 11, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Oct 5, 2022

The error is now

error: higher-ranked lifetime error
 --> src/main.rs:7:5
  |
7 |     impl_check()
  |     ^^^^^^^^^^
  |
  = note: could not prove `for<'a, 'b> u8: Service<&'a &'b u8>`

@Noratrieb Noratrieb added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 5, 2023
@fmease fmease added the A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) label Sep 24, 2024
@fmease fmease added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lifetimes Area: Lifetimes / regions A-trait-system Area: Trait system A-type-system Area: Type system C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants