Merge pull request #2397 from rust-lang/senekor/onvlpnlyoqww

Redesign vec1 to avoid confusing array literal
This commit is contained in:
Remo Senekowitsch 2026-05-14 23:34:25 +02:00 committed by GitHub
commit 9b50da484f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 21 deletions

View File

@ -21,6 +21,7 @@
- `vecs2`: Removed the use of `map` and `collect`, which are only taught later. - `vecs2`: Removed the use of `map` and `collect`, which are only taught later.
- `structs3`: Rewrote the exercise to make users type method syntax themselves. - `structs3`: Rewrote the exercise to make users type method syntax themselves.
- Rename the exercises for smart pointers and conversions so they're sorted alphabetically. [@foxfromworld](https://github.com/foxfromworld) - Rename the exercises for smart pointers and conversions so they're sorted alphabetically. [@foxfromworld](https://github.com/foxfromworld)
- `vecs1`: Remove array literal. Some learners assumed their task is to convert it to a vector.
## 6.5.0 (2025-08-21) ## 6.5.0 (2025-08-21)

View File

@ -1,11 +1,6 @@
fn array_and_vec() -> ([i32; 4], Vec<i32>) { fn elems_to_vec(a: i32, b: i32, c: i32) -> Vec<i32> {
let a = [10, 20, 30, 40]; // Array // TODO: Return a vector containing the elements a, b and c (in this order).
// Use the "vec!" macro.
// TODO: Create a vector called `v` which contains the exact same elements as in the array `a`.
// Use the vector macro.
// let v = ???;
(a, v)
} }
fn main() { fn main() {
@ -17,8 +12,11 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_array_and_vec_similarity() { fn test_elems_to_vec() {
let (a, v) = array_and_vec(); let (a, b, c) = (2, 7, 12);
assert_eq!(a, *v); let v = elems_to_vec(a, b, c);
assert_eq!(v[0], a);
assert_eq!(v[1], b);
assert_eq!(v[2], c);
} }
} }

View File

@ -1,10 +1,5 @@
fn array_and_vec() -> ([i32; 4], Vec<i32>) { fn elems_to_vec(a: i32, b: i32, c: i32) -> Vec<i32> {
let a = [10, 20, 30, 40]; // Array vec![a, b, c]
// Used the `vec!` macro.
let v = vec![10, 20, 30, 40];
(a, v)
} }
fn main() { fn main() {
@ -16,8 +11,11 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_array_and_vec_similarity() { fn test_elems_to_vec() {
let (a, v) = array_and_vec(); let (a, b, c) = (2, 7, 12);
assert_eq!(a, *v); let v = elems_to_vec(a, b, c);
assert_eq!(v[0], a);
assert_eq!(v[1], b);
assert_eq!(v[2], c);
} }
} }