Closed mo8it closed 3 months ago
Pinging @orhun because you were willing to test it 🥰
Thanks for your efforts put into this!
I stumbled on an error while installing:
error: failed to compile `rustlings v6.0.0-beta.3`, intermediate artifacts can be found at `/var/folders/bc/g5l5nq855nd_fb3y1psnc6v00000gn/T/cargo-installsN59ZL`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.
Caused by:
package `clap_lex v0.7.0` cannot be built because it requires rustc 1.74 or newer, while the currently active rustc version is 1.73.0
I fixed this issue by running rustup update
. Maybe it's worth mentioning the minimal required Rust version (which seems to be 1.74) in the README?
@norraell I will add a note about this to the README. Thanks :D
@norraell The README is now updated to include rustup update
as a troubleshooting step if the installation fails :D
Hello, thanks for the ping!
I got this error right off the bat:
Error: Failed to run the command `target/debug/intro1`
Caused by:
No such file or directory (os error 2)
I'm assuming this is due to my custom cargo setup (global target
directory):
[build]
target-dir = "/drv/cargo/target"
So rustlings
probably shouldn't hardcode target
and respect this config option and also CARGO_TARGET_DIR
variable :bear:
@orhun Thank you for reporting this issue 😅
Would it be fine if I create the file .cargo/config.toml
with target-dir = "target"
to override the global setting?
Otherwise, I would need to add the serde_json
dependency and parse the JSON output of cargo metadata --no-deps --format-version 1
just to read the target_directory
field. This would mean running that command and parsing its output at every startup… Because CARGO_TARGET_DIR
is not a global environment variable.
Would it be fine if I create the file .cargo/config.toml with target-dir = "target" to override the global setting?
Don't think so, I think it would be best to not mess with the user's configuration.
Otherwise, I would need to add the serde_json dependency and parse the JSON output
Or you can simply read .cargo/config.toml
and check if the target directory is being overriden. Checking the value of CARGO_TARGET_DIR
at runtime would be fine also. So the correct logic should be:
target-dir
is configured in .cargo/config.toml
or .cargo/config
CARGO_TARGET_DIR
environment variable is set.target
directory as last resortWhat do you think?
It is not that easy because Cargo looks for the config file in the current directory and all parent directories. You would also need to find out what $CARGO_HOME
is. Sadly, we have platforms like Windows that we need to support 😅
I guess I will just parse that JSON then :P
It is not that easy because Cargo looks for the config file in the current directory and all parent directories.
Ouf, unfortunately I'm not aware of a crate that might help with that :/
Here is my feedback. I already know Rust, but I never looked at rustlings
before. I hope this is not too detailed. 😅 I have written down everything I found while doing the exercises. I'm getting a little bit tired; hoping my ramblings make sense.
Here are my solutions for reference.
I'm using
rustlings watch
doesn't workFrom the rustlings
command
Got all that? Great! To get started, run `rustlings watch` in order to get the first exercise.
Make sure to have your editor open in the `rustlings` directory!
When I run rustlings watch
:
>rustlings watch
error: unrecognized subcommand 'watch'
Usage: rustlings [OPTIONS] [COMMAND]
For more information, try '--help'.
Question Mark. Unicode Replacement Character?
If unit tests are failing (e.g. assert_eq!(2 + 2, 5)
), there is no output of the panic message. The only thing I see:
running 14 tests
test tests::test_array_correct ... ok
test tests::test_array_out_of_range_positive ... ok
test tests::test_array_sum ... ok
test tests::test_array_out_of_range_negative ... ok
test tests::test_slice_correct ... ok
test tests::test_slice_excess_length ... ok
test tests::test_slice_insufficient_length ... ok
test tests::test_slice_out_of_range_negative ... ok
test tests::test_tuple_out_of_range_positive ... ok
test tests::test_slice_out_of_range_positive ... ok
test tests::test_slice_sum ... ok
test tests::test_tuple_out_of_range_negative ... ok
test tests::test_tuple_sum ... ok
test tests::test_tuple_correct ... FAILED
failures:
failures:
tests::test_tuple_correct
test result: FAILED. 13 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Output
Ok(Color { red: 183, green: 65, blue: 14 })
Ok(Color { red: 183, green: 65, blue: 14 })
Ok(Color { red: 183, green: 65, blue: 14 })
Ok(Color { red: 183, green: 65, blue: 14 })
Not all files with compile errors are highlighted by Rust Analyzer. Workarounds:
exercises\quizzes\quiz3.rs
was the first quiz I got after completing 15_traits
. I neither got quiz1.rs
nor quiz2.rs
.
This is the output after I solved the exercises in order. Note: I didn't got to quiz1.rs
or quiz2.rs
.
Output
Hello and
welcome to...
_ _ _
_ __ _ _ ___| |_| (_)_ __ __ _ ___
| '__| | | / __| __| | | '_ \ / _` / __|
| | | |_| \__ \ |_| | | | | | (_| \__ \
|_| \__,_|___/\__|_|_|_| |_|\__, |___/
|___/
This exercise compiles successfully. The remaining exercises contain a compiler
or logic error. The central concept behind Rustlings is to fix these errors and
solve the exercises. Good luck!
The file of this exercise is `exercises/00_intro/intro1.rs`. Have a look!
The current exercise path is shown under the progress bar in the watch mode.
Exercise done ✓
When you are done experimenting, enter `n` or `next` to go to the next exercise 🦀
A solution file can be found at solutions/00_intro/intro1.rs
Progress: [#######################################################################################################################################################################################>-----------------------] 85/96 exercises
Current exercise: exercises/00_intro/intro1.rs
exercises\quizzes\quiz3.rs
: I got a bit confused. Why not directly change the line to grade: "A+".to_string(),
in tests::generate_alphabetic_report_card
?exercises\16_lifetimes\lifetimes2.rs
: My solution was to remove the scope block {}
. Not sure if this was the intended solution.exercises\23_conversions\as_ref_mut.rs
: Not sure what the expected solution is. Mine got a little bit complicated:
// Squares a number using as_mut().
// TODO: Add the appropriate trait bound.
fn num_sq<T: AsRef<U> + AsMut<U> + Clone, U: for<'a> MulAssign<&'a U>>(arg: &mut T) {
let value = arg.clone();
*arg.as_mut() *= value.as_ref();
}
exercises\19_smart_pointers\rc1.rs
maybe a little bit too easy? The solution is to blindly use the same code pattern as above.exercises\19_smart_pointers\arc1.rs
20_threads
.numbers
doesn't get mutated (and because Vec<u32>
implements Send
/Sync
):
// Because we are using threads, our values need to be thread-safe. Therefore,
// we are using Arc. We need to make a change in each of the two TODOs.
The reason we need Arcs
is because thread::spawn
requires that F: FnOnce() -> T + Send + 'static
. This explanation is probably too confusing for beginners.
exercises\19_smart_pointers\cow1.rs
Result
as a return type in tests. :)Cow
is a bit uncommon. The function abs_all
can be simplified:
fn abs_all<'a>(mut input: Cow<'a, [i32]>) -> Cow<'a, [i32]> {
for i in 0..input.len() {
let v = input[i];
if v < 0 {
// Clones into a vector if not already owned.
input.to_mut()[i] = -v;
}
}
input
}
Especially in the first exercises, add a one-liner comment:
Here are some examples:
exercises\02_functions\functions1.rs
: Add // don't change this line
after call_me();
. Make it clear to write the function (and not to remove the call).exercises\01_functions
and exercises\02_functions
have no instructions. Maybe add // Make me compile!
?exercises\06_move_semantics\move_semantics2.rs
: Maybe make it clear when it is okay to change the unit tests and when not.exercises\12_options\options1.rs
: Make it more clear that unwrap
is the desired solution in the unit test raw_value
by stating that you should not modify the assert_eq!(icecreams, 5);
line.exercises\13_error_handling\errors1.rs
: Instead of // Don't change this line
, say // Don't change the tests below
.exercises\13_error_handling\errors2.rs
: Unless I am missing something, the success case is correct.
Right now, this function isn't handling the error case at all (and isn't handling the success case properly either).
exercises\19_smart_pointers
: The files are not sorted in the correct order. Rename exercises\19_smart_pointers\box1.rs
to exercises\19_smart_pointers\01_box.rs
, etc., instead?exercises\23_conversions
: Same as for 19_smart_pointers
above, the files are not in order.There are some compiler/clippy warnings that might be overwhelming at the start.
exercises\08_enums\enums3.rs
:
warning: used `assert_eq!` with a literal bool
--> exercises/08_enums/enums3.rs:77:9
|
77 | assert_eq!(state.quit, true);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
= note: `#[warn(clippy::bool_assert_comparison)]` on by default
help: replace it with `assert!(..)`
|
77 - assert_eq!(state.quit, true);
77 + assert!(state.quit);
|
exercises\12_options\options3.rs
change the y; // Fix without deleting this line.
line to let _y = y; // Fix without deleting this line.
so that the compiler warning goes away.exercises\13_error_handling\errors6.rs
:
warning: redundant guard
--> exercises/13_error_handling/errors6.rs:49:18
|
49 | x if x == 0 => Err(CreationError::Zero),
| ^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards
= note: `#[warn(clippy::redundant_guards)]` on by default
help: try
|
49 - x if x == 0 => Err(CreationError::Zero),
49 + 0 => Err(CreationError::Zero),
|
exercises\14_generics\generics1.rs
:
warning: calls to `push` immediately after creation
--> exercises/14_generics/generics1.rs:5:5
|
5 | / let mut shopping_list: Vec<_> = Vec::new();
6 | | shopping_list.push("milk");
| |_______________________________^ help: consider using the `vec![]` macro: `let shopping_list: Vec<_> = vec![..];`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#vec_init_then_push
= note: `#[warn(clippy::vec_init_then_push)]` on by default
exercises\19_smart_pointers\rc1.rs
has some warning
warning: field `0` is never read
--> exercises/19_smart_pointers/rc1.rs:16:13
|
16 | Mercury(Rc<Sun>),
| ------- ^^^^^^^
| |
| field in this variant
|
= note: `#[warn(dead_code)]` on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
|
16 | Mercury(()),
| ~~
exercises\20_threads\threads3.rs
()
in fn send_tx(q: Queue, tx: mpsc::Sender<u32>) -> () {
use std::sync::Arc;
Hi Jan @dotjpg3141, thank you very much for your very valuable detailed feedback. I can't express how much it means to me, thank you for your time 🤗🤗🤗
I will probably need days to fix all the issues that you mentioned and give you a detailed reply.
@orhun Respecting the target-dir
option is done by https://github.com/rust-lang/rustlings/commit/c82c3673245ca11d455b067c97fadda4a8406cb9. You can try the new beta version beta.4
:D
Now I'm getting this:
$ rustlings init
error: could not find `Cargo.toml` in `/tmp/tmp.N6HnsDD5Fw` or any parent directory
Error: Failed to read the field `target_directory` from the `cargo metadata` output
Caused by:
EOF while parsing a value at line 1 column 0
I think it requires to be run in a Cargo project directory where Cargo.toml
is present. Is that really needed for initialization?
@orhun Oh well, this one is embarrassing… I shouldn't release anything that late in the night and should definitely add more tests. Anyway, it should work in beta.5
now 😅
No worries, all seems good now. I haven't tested the exercises but the the prompt/TUI is working smoothly for me. Great job!
I can look into this more in depth in the following days probably.
@dotjpg3141
1)
rustlings watch
doesn't work
Fixed
2) Encoding/Display error
This is a problem with the used terminal (cmd.exe
?). Users are supposed to use a modern terminal like the new Windows Terminal. I added a note to the README about the recommended terminal.
3) Invisible input text
This is very weird, but I hope that it doesn't happen in a modern terminal like Windows Terminal. Could you please try it out?
Missing output when unit tests are failing
Fixed
4) Rust-Analyzer
Not all files with compile errors are highlighted by Rust Analyzer. Workarounds:
* Save file (without changes) * Reload VS Code
I am afraid that we can't do anything about this. The most important thing is that Rust-Analyzer provides autocompletion, goto definition, rename and so on. Warnings and errors are shown by Rustlings anyway.
5) Quiz
exercises\quizzes\quiz3.rs
was the first quiz I got after completing15_traits
. I neither gotquiz1.rs
norquiz2.rs
.6) Progress bar
This is the output after I solved the exercises in order. Note: I didn't got to
quiz1.rs
orquiz2.rs
.Output Hello and welcome to... _ _ _ _ __ _ _ ___| |_| (_)_ __ __ _ ___ | '__| | | / __| __| | | '_ \ / _` / __| | | | |_| \__ \ |_| | | | | | (_| \__ \ |_| \__,_|___/\__|_|_|_| |_|\__, |___/ |___/ This exercise compiles successfully. The remaining exercises contain a compiler or logic error. The central concept behind Rustlings is to fix these errors and solve the exercises. Good luck! The file of this exercise is `exercises/00_intro/intro1.rs`. Have a look! The current exercise path is shown under the progress bar in the watch mode. Exercise done ✓ When you are done experimenting, enter `n` or `next` to go to the next exercise 🦀 A solution file can be found at solutions/00_intro/intro1.rs Progress: [#######################################################################################################################################################################################>-----------------------] 85/96 exercises Current exercise: exercises/00_intro/intro1.rs
I tried to reproduce these two issues related to the order of exercises but I couldn't. What happens if you enter n
when you see the above output? What happens when you restart Rustlings and then try to enter n
?
Could you please post the content of the hidden file .rustlings-state.txt
? A screenshot of all exercises in the list would be alse very helpful. You can open the list by entering l
.
I will fix the things that you pointed out about the exercises and Clippy later. Thank you again for your very valuable feedback 🥰
Love the new direction rustlings is taking! One issue I'm having: After starting rustlings, I get an "invalid argument" for running the intro1 command and rustlings exists.
I used rustlings@6.0.0-beta.6
This is a problem with the used terminal (exe.cmd?).
Yep. This seems to be an issue of cmd
.
This is very weird, but I hope that it doesn't happen in a modern terminal like Windows Terminal. Could you please try it out?
That doesn't seem to make a difference.
https://github.com/rust-lang/rustlings/assets/8530833/9dc7fab9-f372-4631-ac93-e3d62b40c46f
I tried to reproduce these two issues related to the order of exercises but I couldn't. What happens if you enter n when you see the above output? What happens when you restart Rustlings and then try to enter n?
Could you please post the content of the hidden file .rustlings-state.txt? A screenshot of all exercises in the list would be alse very helpful. You can open the list by entering l.
This are my local files (after cargo clean
and removing the .git
directory).
This happened when I pressed next
+ Enter three times:
https://github.com/rust-lang/rustlings/assets/8530833/f869437a-5812-47be-8450-60c04b7920b9
Would it be possible to keep around nix as an installation method in v6?
Would it be possible to keep around nix as an installation method in v6?
No, because I don't use Nix and will not maintain it. You can package it then because v6 will be a standalone binary that you can install with cargo install rustlings
.
exercises\02_functions\functions1.rs
: Add// don't change this line
aftercall_me();
. Make it clear to write the function (and not to remove the call).
I was taking a look at exercises/02_functions/functions1.rs
just now and I'm glad you said this. It wasn't clear what the reader is expected to do.
It might also be helpful to have an "ideal solution" for each exercise.
It might also be helpful to have an "ideal solution" for each exercise.
This is one of the main features of v6 :D
Handling solutions is already implemented. I just need to find some time to write the solutions: https://github.com/rust-lang/rustlings/tree/v6/solutions
It might also be helpful to have an "ideal solution" for each exercise.
This is one of the main features of v6 :D
Handling solutions is already implemented. I just need to find some time to write the solutions: https://github.com/rust-lang/rustlings/tree/v6/solutions
Oh, nice! I think I can try contributing to that if it goes in a pull request.
Also, I think it'd be neat if users had an option to automatically open the next exercise in their editor after completing the current one.
Oh, nice! I think I can try contributing to that if it goes in a pull request.
I plan to write them myself first and then improvements are welcome :D
Also, I think it'd be neat if users had an option to automatically open the next exercise in their editor after completing the current one.
This should also be partially solved since v6 shows you the path of the next exercise as a link in your terminal. Clicking on the link opens the file in your editor. The idea of automatically opening the current file is discarded because it can't work in terminal editor like Helix for example.
3) Invisible input text
I didn't find a way to really fix it, but now (beta.8
) Rustlings expects a single character as input. This means that entering h
will not show you that h
was entered, but it will react to it and show you the hint. You don't have to press ENTER anymore on Windows.
5) Quiz / 6) Progress bar
Thank you for sharing all the info. This looks good to me! (not a bug, but a source of confusion) Rustlings tells you that some exercises are still pending and goes back to them to let you finish them.
The reason why some exercises like quiz1
were not shown to you in the right order is that you jumped to the next file without entering n
for telling Rustlings to go to the next exercise.
For example, your list shows that if3
and quiz1
are pending. quiz1
comes directly after if3
, but you probably didn't enter n
after finishing if3
and instead started editing the file for primitive_types1
. Rustlings jumps to the file that was lastly saved.
This was fine before having the interactive list. But now that the list exists and allows you to opt into skipping an exercise, I think we should disable skipping on saving the file of a later exercise. Going back is fine though. I will implement this in the next beta version :)
Thank you again @dotjpg3141 🥰
But now that the list exists and allows you to opt into skipping an exercise, I think we should disable skipping on saving the file of a later exercise. Going back is fine though.
Done in beta.9
:D
Love the new direction rustlings is taking! One issue I'm having: After starting rustlings, I get an "invalid argument" for running the intro1 command and rustlings exists.
@vgroenewold I don't have enough information to reproduce this. Could you please tell me what command you tried to run and in which directory? Could you please share the exact error message? Thanks 😊
The reason why some exercises like
quiz1
were not shown to you in the right order is that you jumped to the next file without entering n for telling Rustlings to go to the next exercise.
That makes a lot of sense. This is probably what happened.
Version 6 is released now. Thank you all for your feedback 🥰
After about a month of intensive work, I am happy announce the beta release of version 6 🎉
It is a full rewrite of the command line tool. Therefore, I hope to find some people willing to test it and provide some feedback here 🥰
You can try it by following the instructions in the README of the
v6
branch. NOTE: You don't need to clone the Rustlings repository anymore.Your feedback is welcome, as detailed as you want 🥰 But don't focus on the exercises. These didn't really change in v6.
Points to consider in the feedback
cargo install
rustlings/
directoryrustlings
inside therustlings/
directory):h
orhint
)l
orlist
in the watch mode):c
)solutions/
directory after the exercise is done--help
Known issues
intro1
doesn't make a lot of sense anymore