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

GAT: confusing diagnostic when missing where clause #84931

Closed
BoxyUwU opened this issue May 4, 2021 · 0 comments · Fixed by #87478
Closed

GAT: confusing diagnostic when missing where clause #84931

BoxyUwU opened this issue May 4, 2021 · 0 comments · Fixed by #87478
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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

@BoxyUwU
Copy link
Member

BoxyUwU commented May 4, 2021

Given the following code: playground

#![feature(generic_associated_types)]

trait StreamingIter {
    type Item<'a> where Self: 'a;
    fn next<'a>(&'a mut self) -> Option<Self::Item::<'a>>;
}

struct StreamingSliceIter<'a, T> {
    idx: usize,
    data: &'a mut [T],
}

impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
    type Item<'a> = &'a mut T;
    fn next(&mut self) -> Option<&mut T> {
        self.idx += 1;
        Some(&mut self.data[self.idx - 1])
    }
}

The current output is:

error[E0309]: the parameter type `T` may not live long enough
  --> src/lib.rs:14:5
   |
13 | impl<'b, T: 'b> StreamingIter for StreamingSliceIter<'b, T> {
   |          -- help: consider adding an explicit lifetime bound...: `T: 'a +`
14 |     type Item<'a> = &'a mut T;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the reference type `&'a mut T` does not outlive the data it points at

error: aborting due to previous error;

I'm not really sure what the correct output should be but it should mention that I forgot the where Self: 'a bound on the trait impl like I have it written in this compiling code. It should also not suggest adding adding a T: 'a bound because that bound is not writeable 😅

@BoxyUwU BoxyUwU added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 4, 2021
@jackh726 jackh726 added F-generic_associated_types `#![feature(generic_associated_types)]` a.k.a. GATs D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels May 5, 2021
@bors bors closed this as completed in d0a10b2 Aug 14, 2021
@fmease fmease added the A-GATs Area: Generic associated types (GATs) label Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-GATs Area: Generic associated types (GATs) D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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