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

Compat of adding parameters to stable types #1

Closed
SimonSapin opened this issue May 3, 2019 · 5 comments
Closed

Compat of adding parameters to stable types #1

SimonSapin opened this issue May 3, 2019 · 5 comments
Labels
A-Compatibility Issues regarding semver compatibility Blocker This issue has to be resolved before progress can be made
Milestone

Comments

@SimonSapin
Copy link
Contributor

Are there backward-compatibility issues with adding a defaulted type parameter to a stable type? For example changing:

struct Vec<T> {}

To:

struct Vec<T, A: Alloc = Global> {}

The API Evolution RFC claims this is not a major breaking change, but I vaguely recall discussion of type inference being negatively affected.

Is rust-lang/rust#27336 relevant here?

@TimDiekmann
Copy link
Member

It's compatible as long as methods returning Self are not affected.

changing

impl<T> Vec<T> {
    fn new() -> Self;
}

to

impl<T, A: Default> Vec<T, A> {
    fn new() -> Self;
}

would be a breaking change.

@glandium
Copy link

glandium commented May 3, 2019

It /might/ be possible to work around this issue with specialization... but specialization of inherent impls is not supported yet. rust-lang/rust#37653

@TimDiekmann
Copy link
Member

I think we should be conservative about it and just leave the constructors as they are for now. Similar to RawVec, methods like new_in and with_capacity_in can then be used (just like you did in rust-lang/rust#58457).

@TimDiekmann TimDiekmann added the A-Compatibility Issues regarding semver compatibility label May 3, 2019
@TimDiekmann TimDiekmann added this to the Implement `Box<T, A>` milestone May 3, 2019
@TimDiekmann TimDiekmann added the Blocker This issue has to be resolved before progress can be made label May 4, 2019
@SimonSapin
Copy link
Contributor Author

https://rust-lang.github.io/rfcs/1398-kinds-of-allocators.html#default-type-parameter-fallback is relevant:

Default type parameters themselves, in the context of type defintions, are a stable part of the Rust language.

However, the exact semantics of how default type parameters interact with inference is still being worked out (in part because allocators are a motivating use case), as one can see by reading the following:

@TimDiekmann
Copy link
Member

We tested this with rust-lang/rust#71873 and rust-lang/rust#77187.

bors added a commit to rust-lang-ci/rust that referenced this issue Nov 21, 2020
Add support for custom allocators in `Vec`

This follows the [roadmap](rust-lang/wg-allocators#7) of the allocator WG to add custom allocators to collections.

r? `@Amanieu`

This pull request requires a crater run.

### Prior work:
- rust-lang#71873: Crater-test to solve rust-lang/wg-allocators#1
- [`alloc-wg`](https://github.com/TimDiekmann/alloc-wg)-crate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Compatibility Issues regarding semver compatibility Blocker This issue has to be resolved before progress can be made
Projects
None yet
Development

No branches or pull requests

3 participants