Skip to content

Slightly confusing error message when using where with GATs #86787

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
AidanConnelly opened this issue Jul 1, 2021 · 0 comments · Fixed by #89914
Closed

Slightly confusing error message when using where with GATs #86787

AidanConnelly opened this issue Jul 1, 2021 · 0 comments · Fixed by #89914
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AidanConnelly
Copy link

AidanConnelly commented Jul 1, 2021

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

#![feature(generic_associated_types)]

use either::Either;

pub trait HasChildrenOf {
    type T;
    type TRef<'a>;

    fn ref_children<'a>(&'a self) -> Vec<Self::TRef<'a>>;
    fn take_children(self) -> Vec<Self::T>;
}

impl<Left, Right> HasChildrenOf for Either<Left, Right>
where
    Left: HasChildrenOf,
    Right: HasChildrenOf,
{
    type T = Either<Left::T, Right::T>;
    type TRef<'a>
    where 
    <Left as HasChildrenOf>::T: 'a,
    <Right as HasChildrenOf>::T: 'a
    = Either<&'a Left::T, &'a Right::T>;

    fn ref_children<'a>(&'a self) -> Vec<Self::TRef<'a>> {
        todo!()
    }

    fn take_children(self) -> Vec<Self::T> {
        todo!()
    }
}

I expected to see this happen: A slightly better error message

Instead, this happened: A slightly confusing error message

error[E0309]: the associated type `<Left as HasChildrenOf>::T` may not live long enough
  --> src/lib.rs:19:5
   |
19 | /     type TRef<'a>
20 | |     where 
21 | |     <Left as HasChildrenOf>::T: 'a,
22 | |     <Right as HasChildrenOf>::T: 'a
23 | |     = Either<&'a Left::T, &'a Right::T>;
   | |________________________________________^
   |
   = help: consider adding an explicit lifetime bound `<Left as HasChildrenOf>::T: 'a`...
   = note: ...so that the type `<Left as HasChildrenOf>::T` will meet its required lifetime bounds

Meta

rustc --version --verbose:

rustc 1.55.0-nightly (868c702d0 2021-06-30)
binary: rustc
commit-hash: 868c702d0c9a471a28fb55f0148eb1e3e8b1dcc5
commit-date: 2021-06-30
host: x86_64-pc-windows-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1
Backtrace


@AidanConnelly AidanConnelly added the C-bug Category: This is a bug. label Jul 1, 2021
@JohnTitor JohnTitor added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-bug Category: This is a bug. labels Jul 1, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 15, 2021
…=estebank

Emit impl difference error for GenericBoundFailure too

Fixes rust-lang#86787

r? `@estebank`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 15, 2021
…=estebank

Emit impl difference error for GenericBoundFailure too

Fixes rust-lang#86787

r? ``@estebank``
jackh726 added a commit to jackh726/rust that referenced this issue Oct 16, 2021
…=estebank

Emit impl difference error for GenericBoundFailure too

Fixes rust-lang#86787

r? ```@estebank```
@bors bors closed this as completed in e8efe09 Oct 16, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants