Skip to content

Commit 559bfd6

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35613 - matthew-piziak:array-docs-trait-justification, r=steveklabnik
provide additional justification for array interface design Explain why Rust does not implement traits for large arrays. Explain why most methods are implemented on slices rather than arrays. Note: I'm dipping my toes in the water with a tiny PR. Especially looking for feedback on wording and style. Points of concern: appropriate level of top-level explanation; foreshadowing (is it appropriate to imply that we expect Rust's type system to eventually support size-generic arrays?); using `Foo` and `Bar` as type variables instead of e.g. `T` and `S`. @peschkaj
2 parents 997a248 + e173ead commit 559bfd6

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/libstd/primitive_docs.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,18 @@ mod prim_pointer { }
269269
/// - `Borrow`, `BorrowMut`
270270
/// - `Default`
271271
///
272+
/// This limitation to `N in 0..33` exists because Rust does not yet support
273+
/// generics over the size of an array type. `[Foo; 3]` and `[Bar; 3]` are
274+
/// instances of same generic type `[T; 3]`, but `[Foo; 3]` and `[Foo; 5]` are
275+
/// entirely different types. As a stopgap, trait implementations are
276+
/// statically generated for `N in 0..33`.
277+
///
272278
/// Arrays coerce to [slices (`[T]`)][slice], so their methods can be called on
273-
/// arrays.
279+
/// arrays. Slices are dynamic and do not coerce to arrays; consequently more
280+
/// methods are defined on `slice` where they support both types.
274281
///
275282
/// [slice]: primitive.slice.html
276283
///
277-
/// Rust does not currently support generics over the size of an array type.
278-
///
279284
/// # Examples
280285
///
281286
/// ```

0 commit comments

Comments
 (0)