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

Expand E0309 explanation with motivating example #38315

Merged
merged 1 commit into from
Dec 21, 2016

Conversation

jonhoo
Copy link
Contributor

@jonhoo jonhoo commented Dec 12, 2016

I recently started reading @gankro's "Learning Rust With Entirely Too Many Linked Lists", and came across a part where he comes across E0309, and after showing rustc --explain E0309 prompty says

This is dumb. I think it's dumb. You have to do it.

Humor aside, I think this says something about the current explanation being somewhat lacking.

This patch introduces a motivating example saying why T: 'a is a necessary restriction. Hopefully, this will help new Rustaceans understand why leaving out the 'a bound on T might lead to broken code.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@pnkfelix
Copy link
Member

pnkfelix commented Dec 19, 2016

one problem with the critique from the "Too Many Linked Lists" posting is that is so flippant that its text does not make it clear what exactly is dumb, and why it is dumb.

The way I read the complaint, I interpret the post author as saying:

it is silly that I have to specify this constraint on T, when we could "simply" infer it from the structure of the type definition itself.

This obviously does not match your reading of the complaint, since even in expanded example you have given, we would still be able to infer the constraint T: 'a. (Inference becomes more complex however if one considers mutually recursive struct definitions.)

Anyway, I'm not strictly opposed to expanding the explanatory text in the manner proposed here, but just realize that this may not be a satisfactory response to some critics...

@pnkfelix
Copy link
Member

(i restarted one of the travis builds since it seemed like its failure could not have been caused by this PR...)

@jonhoo
Copy link
Contributor Author

jonhoo commented Dec 19, 2016

I think there are two "layers" to this: understanding why the 'a bound is necessary in the first place, and understanding why that bound cannot be inferred automatically. This is in line with your comments (I think). The current explanation for E0309 doesn't help the reader with any of those. My patch tries to answer the first (and easiest) of the two, as I think that might help to clear up some confusion for readers who are still struggling with lifetimes (which is presumably why they're getting this error in the first place).

I agree that the author's original concern is probably more so the latter than the former. Answering the latter in the explanation would obviously also be great, but I can't immediately think of a concise and intuitive example in mind that would serve well for the purposes of exposition. I'd argue that this is still a step in the right direction.

@pnkfelix
Copy link
Member

r=me assuming the restarted travis build completes successfully. (if it doesn't then we need to look into what's going on there.)

@jonhoo
Copy link
Contributor Author

jonhoo commented Dec 20, 2016

@pnkfelix looks like the tests passed as expected :)

@pnkfelix
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 20, 2016

📌 Commit f09e2cc has been approved by pnkfelix

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Dec 20, 2016
Expand E0309 explanation with motivating example

I recently started reading @gankro's "[Learning Rust With Entirely Too Many Linked Lists](http://cglab.ca/~abeinges/blah/too-many-lists/book/README.html)", and came across [a part](http://cglab.ca/~abeinges/blah/too-many-lists/book/second-iter.html) where he comes across `E0309`, and after showing `rustc --explain E0309` prompty says

> This is dumb. I think it's dumb. You have to do it.

Humor aside, I think this says something about the current explanation being somewhat lacking.

This patch introduces a motivating example saying why `T: 'a` is a necessary restriction. Hopefully, this will help new Rustaceans understand why leaving out the `'a` bound on `T` might lead to broken code.
bors added a commit that referenced this pull request Dec 20, 2016
@bors bors merged commit f09e2cc into rust-lang:master Dec 21, 2016
@jonhoo jonhoo deleted the better-E0309 branch December 21, 2016 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants