-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Stabilize std::borrow #22210
Stabilize std::borrow #22210
Conversation
bf2b260
to
a5fd359
Compare
/// } | ||
/// ``` | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub enum Cow<'a, B: ?Sized + 'a> where B: ToOwned, <B as ToOwned>::Owned: 'a { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why Owned
now has a : 'a
bound? The old implementation didn't have that. But, perhaps something changed?
Other than the |
(Also it's nice that |
Have we pinged the community on the lost flexibility from BorrowFrom? I am always surprised what they manage to do with stuff. |
The extra bounds were added because of #22246, which currently means we know less about associated types than we do type parameters that are used directly. Unfortunately, the bounds I added here are overly constraining, so this change is effectively blocked on the issue above. Actually, thinking more clearly about it there's no real loss in flexibility, because the coherence rules already basically rule out associating a different owned type with |
@@ -0,0 +1,310 @@ | |||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come this moved to libcollections?
Needs a rebase, sorry. |
`no_late_bound_regions().unwrap()`, which allows us to write code that doesn't necessarily *fail* when there are higher-ranked trait bounds.
parameter environments so that it can be used elsewhere.
that it produces "outlives" relations for associated types. Add several tests relating to rust-lang#22246.
a5fd359
to
96d2ba9
Compare
1a9467e
to
a99e698
Compare
a99e698
to
ab59ee1
Compare
@bors: r=alexcrichton ab59ee1 |
ab59ee1
to
1d46e3b
Compare
This commit stabilizes `std::borrow`, making the following modifications to catch up the API with language changes: * It renames `BorrowFrom` to `Borrow`, as was originally intended (but blocked for technical reasons), and reorders the parameters accordingly. * It moves the type parameter of `ToOwned` to an associated type. This is somewhat less flexible, in that each borrowed type must have a unique owned type, but leads to a significant simplification for `Cow`. Flexibility can be regained by using newtyped slices, which is advisable for other reasons anyway. * It removes the owned type parameter from `Cow`, making the type much less verbose. * Deprecates the `is_owned` and `is_borrowed` predicates in favor of direct matching. The above API changes are relatively minor; the basic functionality remains the same, and essentially the whole module is now marked `#[stable]`. [breaking-change]
1d46e3b
to
9b70775
Compare
Conflicts: src/libcollections/btree/map.rs src/libcollections/str.rs src/libcollections/vec.rs src/libcore/borrow.rs src/libcore/hash/mod.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs
Merged in #22541 |
This commit stabilizes
std::borrow
, making the following modificationsto catch up the API with language changes:
BorrowFrom
toBorrow
, as was originally intended (butblocked for technical reasons), and reorders the parameters
accordingly.
ToOwned
to an associated type. Thisis somewhat less flexible, in that each borrowed type must have a
unique owned type, but leads to a significant simplification for
Cow
. Flexibility can be regained by using newtyped slices, which isadvisable for other reasons anyway.
Cow
, making the type muchless verbose.
The above API changes are relatively minor; the basic functionality
remains the same, and essentially the whole module is now marked
#[stable]
.[breaking-change]
r? @alexcrichton @gankro