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

Remove an uneeded 'static lifetime #1752

Merged
merged 5 commits into from
Dec 14, 2020
Merged

Remove an uneeded 'static lifetime #1752

merged 5 commits into from
Dec 14, 2020

Conversation

steveklabnik
Copy link
Member

Fixes #1744

@carols10cents
Copy link
Member

@steveklabnik see this comment, in chapter 13 when we change this function to not take a reference anymore, we have to put the 'static in at that point and explain it there instead (and explain why the change makes us add it). is it literally just eliding the lifetimes and when we have an input lifetime, saying "oh static outlives that, so this is fine"? did this behavior change recently? i can't find a release notes entry that looks relevant... or have we not needed to specify 'static here for a long time?

Copy link
Member

@carols10cents carols10cents left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs more changes that i'm not sure how to make halp

@steveklabnik
Copy link
Member Author

did this behavior change recently? i can't find a release notes entry that looks relevant... or have we not needed to specify 'static here for a long time?

I am not 100% sure, @Centril knows maybe?

@carols10cents
Copy link
Member

Triage: this is still waiting on additional input/knowledge from somewhere/someone and then appropriate changes :-/

@Centril
Copy link

Centril commented Apr 22, 2019

is it literally just eliding the lifetimes and when we have an input lifetime, saying "oh static outlives that, so this is fine"?

@carols10cents

Yes. After inference, the signature of the function is:

    fn new<'a, 'b>(args: &'a [String]) -> Result<Config, &'b str>;

When type checking "not enough arguments" we assign it the type &'static str; and for<'b> 'static: 'b holds so it conforms with the return type.

@steveklabnik

I am not 100% sure, @Centril knows maybe?

Using:

#![allow(dead_code)]

struct Config {
    query: String,
    filename: String,
}

impl Config {
    fn new(args: &[String]) -> Result<Config, &str> {
        if args.len() < 3 {
            return Err("not enough arguments");
        }

        let query = args[1].clone();
        let filename = args[2].clone();

        Ok(Config { query: query, filename: filename })
    }
}

I checked this with godbolt back to 1.0 and it has worked since then.

@steveklabnik
Copy link
Member Author

Okay! I've rebased this.

success case and a `&'static str` in the error case. Recall from [“The Static
Lifetime”][the-static-lifetime]<!-- ignore --> section in Chapter 10 that
`&'static str` is the type of string literals, which is our error message type
for now.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if we want to keep this sentence but remove the static lifetime bits. thoughts?

@stappersg
Copy link
Contributor

stappersg commented May 5, 2020

For what it's worth:

  • previous update was from 2020-04-02
  • pre previous update was from 2019-04-22

What can / should be done to prevent that is pull request drags for another twelve months?

@carols10cents
Copy link
Member

If you could stop the global pandemic, pay Steve or I to work on the book, provide childcare, or make more hours in the day, that would help.

Please be patient, your pings are not helpful.

@carols10cents
Copy link
Member

@steveklabnik ok I think I've made the rest of the changes that need to be made for this PR; can you review what I've added? Also note I rebased and force pushed...

Copy link
Member Author

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Since I opened the PR I can't approve it, haha.

@steveklabnik steveklabnik merged commit b702f3b into master Dec 14, 2020
@steveklabnik steveklabnik deleted the gh1744 branch December 14, 2020 16:24
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Dec 22, 2020
Update books

## nomicon

2 commits in d8383b65f7948c2ca19191b3b4bd709b403aaf45..a5a48441d411f61556b57d762b03d6874afe575d
2020-11-22 10:24:42 -0500 to 2020-12-06 10:39:41 +0900
- Update atomics.md (rust-lang/nomicon#249)
- Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate` (rust-lang/nomicon#248)

## reference

2 commits in a8afdca5d0715b2257b6f8b9a032fd4dd7dae855..b278478b766178491a8b6f67afa4bcd6b64d977a
2020-11-30 06:44:46 -0800 to 2020-12-21 18:18:03 -0800
- Update unions for safe ManuallyDrop assignment. (rust-lang/reference#912)
- Removing ambiguity in type-layout.md (rust-lang/reference#911)

## book

25 commits in a190438d77d28041f24da4f6592e287fab073a61..5bb44f8b5b0aa105c8b22602e9b18800484afa21
2020-11-16 10:44:08 -0600 to 2020-12-18 20:07:31 -0500
- Make some further edits to rust-lang/book#2447
- Merge remote-tracking branch 'origin/pr/2447'
- Remove copied and dangling link brackets
- Merge remote-tracking branch 'origin/pr/2359'
- Override toolchain to nightly for run lints action. (rust-lang/book#2528)
- Remove an uneeded 'static lifetime (rust-lang/book#1752)
- Fixes rust-lang/book#2330. Clarify why the lock is held too long
- Update paragraph about rustfmt in Chapter 1.2 (rust-lang/book#2304)
- Clarify language around  further from rust-lang/book#2418
- Merge remote-tracking branch 'origin/pr/2418'
- Merge remote-tracking branch 'origin/pr/2475'
- Add some further edits to rust-lang/book#2433
- Merge remote-tracking branch 'origin/pr/2433'
- Note all the method families to handle integer overflow
- Merge remote-tracking branch 'origin/pr/2405'
- Fix rust-lang/book#1855 - incorporate new reference cycle diagram
- Make some further edits to the changes in rust-lang/book#1886
- Merge remote-tracking branch 'origin/pr/1886'
- Make some further edits to rust-lang/book#1998
- Merge remote-tracking branch 'origin/pr/1998'
- Update Rust version and output (rust-lang/book#2518)
- Fix typo, regarding privileged ports being up to 1023 instead of 1024 (rust-lang/book#2509)
- Change "appendixes" to "appendices" in intro. (rust-lang/book#2498)
- Update 16-11 to use method call expression for `clone` (rust-lang/book#2511)
- Correct chapter 20 final listing (rust-lang/book#2516)

## rust-by-example

7 commits in 236c734a2cb323541b3394f98682cb981b9ec086..1cce0737d6a7d3ceafb139b4a206861fb1dcb2ab
2020-11-30 14:05:49 -0300 to 2020-12-21 17:36:29 -0300
- Add book.description in book.toml (rust-lang/rust-by-example#1397)
- Simplify the call of filter_map (rust-lang/rust-by-example#1396)
- Update README.md (rust-lang/rust-by-example#1382)
- Add missing main function in static life time example. (rust-lang/rust-by-example#1383)
- Clarify first matching arm and all possible values (rust-lang/rust-by-example#1395)
- Clarify distinction between for iter and into_iter (rust-lang/rust-by-example#1394)
- Drop extern crate (rust-lang/rust-by-example#1393)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chapter 12.3 add note to explain that 'static is actually not required
4 participants