Skip to content

A clearer description of the original problem#2188

Closed
jbethune wants to merge 2 commits into
rust-lang:mainfrom
jbethune:main
Closed

A clearer description of the original problem#2188
jbethune wants to merge 2 commits into
rust-lang:mainfrom
jbethune:main

Conversation

@jbethune
Copy link
Copy Markdown

@jbethune jbethune commented Jan 1, 2025

The original excercise instructs the learner to use the vector macro. It is easy to assume that the code needs to read from a which is not what is intended.

The updated excercise introduces the syntax for initial array and vector contents and lets the learner figure out how to tweak initial values of a vector. This learning seems to be the original intent of the excercise.

Jörn Bethune added 2 commits January 1, 2025 17:46
The original excercise instructs the learner to use the vector macro.
It is easy to assume that the code needs to read from `a` which is not
what is intended.

The updated excercise introduces the syntax for initial array and vector
contents and lets the learner figure out how to tweak initial values of
a vector. This learning seems to be the original intent of the
excercise.
let a = [10, 20, 30, 40]; // Array
// You can define an array with the intitial values 10, 20, 30 and 40 like
// this:
let a = [10, 20, 30, 40]; // Array. Do not change!
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original example already shows it’s just array initialization, so it works well. Still, it might be good to see the maintainer’s opinion.

// Use the vector macro.
// let v = ???;
// There is a similar way you can define a vector with initial values:
// let v = vec![10, 20, ???]; // Vector. Needs to be fixed
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both to_vec() and Vec::from compile, but the author just wanted vec![10, 20, 30, 40]. So I think the original is fine — let’s see the maintainer’s opinion.

Copy link
Copy Markdown
Contributor

@foxfromworld foxfromworld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is related to #2167.

@senekor
Copy link
Copy Markdown
Contributor

senekor commented May 12, 2026

I think this PR is over explaining stuff, but I can see how the current state is confusing to some. Duplicating the literals is not something people would do in a real code base, so the mind doesn't jump to that. Maybe it's a good idea to redesign the exercise a little, so the vec! macro is the more intuitive solution.

@mo8it
Copy link
Copy Markdown
Contributor

mo8it commented May 16, 2026

Resolved by #2397

@mo8it mo8it closed this May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants