Skip to content

Commit 9b50da4

Browse files
authored
Merge pull request rust-lang#2397 from rust-lang/senekor/onvlpnlyoqww
Redesign vec1 to avoid confusing array literal
2 parents 03ddf36 + f303631 commit 9b50da4

3 files changed

Lines changed: 18 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- `vecs2`: Removed the use of `map` and `collect`, which are only taught later.
2222
- `structs3`: Rewrote the exercise to make users type method syntax themselves.
2323
- Rename the exercises for smart pointers and conversions so they're sorted alphabetically. [@foxfromworld](https://github.com/foxfromworld)
24+
- `vecs1`: Remove array literal. Some learners assumed their task is to convert it to a vector.
2425

2526
## 6.5.0 (2025-08-21)
2627

exercises/05_vecs/vecs1.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
2-
let a = [10, 20, 30, 40]; // Array
3-
4-
// TODO: Create a vector called `v` which contains the exact same elements as in the array `a`.
5-
// Use the vector macro.
6-
// let v = ???;
7-
8-
(a, v)
1+
fn elems_to_vec(a: i32, b: i32, c: i32) -> Vec<i32> {
2+
// TODO: Return a vector containing the elements a, b and c (in this order).
3+
// Use the "vec!" macro.
94
}
105

116
fn main() {
@@ -17,8 +12,11 @@ mod tests {
1712
use super::*;
1813

1914
#[test]
20-
fn test_array_and_vec_similarity() {
21-
let (a, v) = array_and_vec();
22-
assert_eq!(a, *v);
15+
fn test_elems_to_vec() {
16+
let (a, b, c) = (2, 7, 12);
17+
let v = elems_to_vec(a, b, c);
18+
assert_eq!(v[0], a);
19+
assert_eq!(v[1], b);
20+
assert_eq!(v[2], c);
2321
}
2422
}

solutions/05_vecs/vecs1.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
2-
let a = [10, 20, 30, 40]; // Array
3-
4-
// Used the `vec!` macro.
5-
let v = vec![10, 20, 30, 40];
6-
7-
(a, v)
1+
fn elems_to_vec(a: i32, b: i32, c: i32) -> Vec<i32> {
2+
vec![a, b, c]
83
}
94

105
fn main() {
@@ -16,8 +11,11 @@ mod tests {
1611
use super::*;
1712

1813
#[test]
19-
fn test_array_and_vec_similarity() {
20-
let (a, v) = array_and_vec();
21-
assert_eq!(a, *v);
14+
fn test_elems_to_vec() {
15+
let (a, b, c) = (2, 7, 12);
16+
let v = elems_to_vec(a, b, c);
17+
assert_eq!(v[0], a);
18+
assert_eq!(v[1], b);
19+
assert_eq!(v[2], c);
2220
}
2321
}

0 commit comments

Comments
 (0)