Chapter 10.3. Third elision rule.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 18.3k
- Forks
- 4.1k
- Avg merge
- 14m
- Merged PRs (30d)
- 1
Description
- I have checked the latest
mainbranch to see if this has already been fixed - I have searched existing issues and pull requests for duplicates
URL to the section(s) of the book with this problem:
https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html
Description of the problem:
This has to do with the example provided of the 3rd elision rule in action:
impl<'a> ImportantExcerpt<'a> {
fn announce_and_return_part(&self, announcement: &str) -> &str {
println!("Attention please: {}", announcement);
self.part
}
}
I'm new to Rust. My immediate thought in reading this example was "Oh no, what if the function returns 'announcement'? Assigning self's lifetime to the output reference seems very dangerous here. What if 'announcement' is returned instead?" I was so concerned, I tried it. And was very relieved that the compiler reported an error.
Suggested fix:
I would suggest stating that the 3rd elision is making the assumption that self (or some component thereof) will be returned. And although the compiler will in all cases apply the 3rd elision rule to a method signature like the above, the code will not compile if that assumption is violated. This is an important difference from the first two elision rules. I believe they can safely be applied without any particular assumptions about the body of the function. Otherwise put, I don't think either of them could cause code to fail to compile.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked Chapter 10.3 section and inspect the source for the announce_and_return_part example. Clarify the third elision rule's assumption about returning data tied to self, and explain what happens when the function body violates that assumption. Done when the example and surrounding explanation address this distinction clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100