Generalize object and type parameter bounds#16453
Merged
bors merged 1 commit intorust-lang:masterfrom Aug 28, 2014
Merged
Conversation
Contributor
Author
|
r? @pnkfelix Note: there are still a lot of commits here. I got tired of grouping them together. I will likely come back and group them some more later, but I'd also like to walk you through the code a bit. |
Contributor
Author
|
Per discussion with @nick29581 and @pnkfelix, we're going to delay review (or at least landing) somewhat so as to try and avoid conflicts with DST branch. |
Closed
Contributor
Author
|
OK, I cleaned up the set of commits, grouping things together as best I could. It's reasonably clean now, though the commits will not build independently. |
Contributor
Author
|
Closes #16462 |
1a584c0 to
d12d394
Compare
48887b6 to
e336eaf
Compare
1bd83ce to
1b487a8
Compare
Contributor
Author
|
Rebased over DST. At this point the history is ruined, so I squashed down to a single commit now that the review has been done. |
bors
added a commit
that referenced
this pull request
Aug 28, 2014
Implements rust-lang/rfcs#192. In particular: 1. type parameters can have lifetime bounds and objects can close over borrowed values, presuming that they have suitable bounds. 2. objects must have a bound, though it may be derived from the trait itself or from a `Send` bound. 3. all types must be well-formed. 4. type parameters and lifetime parameters may themselves have lifetimes as bounds. Something like `T:'a` means "the type T outlives 'a`" and something like `'a:'b`" means "'a outlives 'b". Outlives here means "all borrowed data has a lifetime at least as long". This is a [breaking-change]. The most common things you have to fix after this change are: 1. Introduce lifetime bounds onto type parameters if your type (directly or indirectly) contains a reference. Thus a struct like `struct Ref<'a, T> { x: &'a T }` would be changed to `struct Ref<'a, T:'a> { x: &'a T }`. 2. Introduce lifetime bounds onto lifetime parameters if your type contains a double reference. Thus a type like `struct RefWrapper<'a, 'b> { r: &'a Ref<'b, int> }` (where `Ref` is defined as before) would need to be changed to `struct RefWrapper<'a, 'b:'a> { ... }`. 2. Explicitly give object lifetimes in structure definitions. Most commonly, this means changing something like `Box<Reader>` to `Box<Reader+'static>`, so as to indicate that this is a reader without any borrowed data. (Note: you may wish to just change to `Box<Reader+Send>` while you're at it; it's a more restrictive type, technically, but means you can send the reader between threads.) The intuition for points 1 and 2 is that a reference must never outlive its referent (the thing it points at). Therefore, if you have a type `&'a T`, we must know that `T` (whatever it is) outlives `'a`. And so on. Closes #5723.
emberian
added a commit
to gfx-rs/gfx
that referenced
this pull request
Aug 30, 2014
carllerche
added a commit
to alexcrichton/curl-rust
that referenced
this pull request
Sep 1, 2014
Now that rust-lang/rust#16453 has landed, the body API can be improved to not require hard casting to trait objects
cburgdorf
added a commit
to nickel-org/nickel.rs
that referenced
this pull request
Sep 11, 2014
This is due to a breaking change from: rust-lang/rust#16453
matthiaskrgr
pushed a commit
to matthiaskrgr/rust
that referenced
this pull request
Feb 5, 2024
internal: Undo special bracket classification for attributes in vscode config I changed this thinking the `#` could be considered part of the bracket but on second though I don't think that's quite right in general. Fixes rust-lang/rust-analyzer#16449
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements rust-lang/rfcs#192.
In particular:
Sendbound.T:'ameans "the type T outlives 'a" and something like'a:'b`" means "'a outlives 'b". Outlives here means "all borrowed data has a lifetime at least as long".This is a [breaking-change]. The most common things you have to fix after this change are:
struct Ref<'a, T> { x: &'a T }would be changed tostruct Ref<'a, T:'a> { x: &'a T }.struct RefWrapper<'a, 'b> { r: &'a Ref<'b, int> }(whereRefis defined as before) would need to be changed tostruct RefWrapper<'a, 'b:'a> { ... }.Box<Reader>toBox<Reader+'static>, so as to indicate that this is a reader without any borrowed data. (Note: you may wish to just change toBox<Reader+Send>while you're at it; it's a more restrictive type, technically, but means you can send the reader between threads.)The intuition for points 1 and 2 is that a reference must never outlive its referent (the thing it points at). Therefore, if you have a type
&'a T, we must know thatT(whatever it is) outlives'a. And so on.Closes #5723.