Skip to content

Apply Option A naming for smart_pointers and conversions exercises#2393

Open
foxfromworld wants to merge 2 commits intorust-lang:mainfrom
foxfromworld:issue-2023-rename-exercises
Open

Apply Option A naming for smart_pointers and conversions exercises#2393
foxfromworld wants to merge 2 commits intorust-lang:mainfrom
foxfromworld:issue-2023-rename-exercises

Conversation

@foxfromworld
Copy link
Copy Markdown

Following the maintainer’s guidance in issue #2023, applied Option A for exercises in smart_pointers and conversions.

Changes:

  • Renamed exercises and solutions with numeric prefixes (Option A)
  • Updated rustlings-macros/info.toml accordingly
  • Adjusted dev/Cargo.toml to reflect new exercise names

For clarity, here’s the rename mapping:

19_smart_pointers
box1.rs -> smart_pointers1.rs
rc1.rs -> smart_pointers2.rs
arc1.rs -> smart_pointers3.rs
cow1.rs -> smart_pointers4.rs

23_conversions
using_as.rs -> conversions1.rs
from_into.rs -> conversions2.rs
from_str.rs -> conversions3.rs
try_from_into.rs -> conversions4.rs
as_ref_mut.rs -> conversions5.rs

Verification:

All exercises load and run successfully, and cargo verify passes without errors.

Screenshots and logs attached for reference:

Rancargo check

image

Ran cargo test

image

Ran cargo run --bin rustlings

image

Ran cargo run -- run smart_pointers1
Ran cargo run -- run smart_pointers2
Ran cargo run -- run smart_pointers3
Ran cargo run -- run smart_pointers4
Ran cargo run -- run conversions1
Ran cargo run -- run conversions2
Ran cargo run -- run conversions3
Ran cargo run -- run conversions4
Ran cargo run -- run conversions5

$ cargo run -- run smart_pointers1
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run smart_pointers1`
error[E0072]: recursive type `List` has infinite size
  --> ../exercises/19_smart_pointers/smart_pointers1.rs:14:1
   |
14 | enum List {
   | ^^^^^^^^^
15 |     Cons(i32, List),
   |               ---- recursive without indirection
   |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
   |
15 |     Cons(i32, Box<List>),
   |               ++++    +

error[E0391]: cycle detected when computing drop-check constraints for `List`
  --> ../exercises/19_smart_pointers/smart_pointers1.rs:14:1
   |
14 | enum List {
   | ^^^^^^^^^
   |
   = note: ...which immediately requires computing drop-check constraints for `List` again
   = note: cycle used when computing dropck types for `List`
   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

error[E0391]: cycle detected when computing when `List` needs drop
  --> ../exercises/19_smart_pointers/smart_pointers1.rs:14:1
   |
14 | enum List {
   | ^^^^^^^^^
   |
   = note: ...which immediately requires computing when `List` needs drop again
   = note: cycle used when computing whether `List` needs drop
   = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information

Some errors have detailed explanations: E0072, E0391.
For more information about an error, try `rustc --explain E0072`.
error: could not compile `exercises` (bin "smart_pointers1") due to 3 previous errors

Ran exercises/19_smart_pointers/smart_pointers1.rs with errors
$ cargo run -- run smart_pointers2
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run smart_pointers2`

running 1 test
test tests::rc1 ... FAILED

failures:

---- tests::rc1 stdout ----
reference count = 1
reference count = 2
Hi from Mercury(Sun)!
reference count = 3
Hi from Venus(Sun)!
reference count = 4
Hi from Earth(Sun)!
reference count = 5
Hi from Mars(Sun)!
reference count = 6
Hi from Jupiter(Sun)!
reference count = 6
Hi from Saturn(Sun)!
reference count = 6
Hi from Uranus(Sun)!
reference count = 6
Hi from Neptune(Sun)!

thread 'tests::rc1' (405570) panicked at ../exercises/19_smart_pointers/smart_pointers2.rs:77:9:
assertion `left == right` failed
  left: 6
 right: 9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests::rc1

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

error: test failed, to rerun pass `--bin smart_pointers2`

Output

Ran exercises/19_smart_pointers/smart_pointers2.rs with errors
$ cargo run -- run smart_pointers3
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run smart_pointers3`
error[E0425]: cannot find value `child_numbers` in this scope
  --> ../exercises/19_smart_pointers/smart_pointers3.rs:35:28
   |
35 |             let sum: u32 = child_numbers.iter().filter(|&&n| n % 8 == offset).sum();
   |                            ^^^^^^^^^^^^^ not found in this scope

error: unused import: `sync::Arc`
  --> ../exercises/19_smart_pointers/smart_pointers3.rs:20:11
   |
20 | use std::{sync::Arc, thread};
   |           ^^^^^^^^^
   |
note: the lint level is defined here
  --> ../exercises/19_smart_pointers/smart_pointers3.rs:19:11
   |
19 | #![forbid(unused_imports)]
   |           ^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0425`.
error: could not compile `exercises` (bin "smart_pointers3") due to 2 previous errors

Ran exercises/19_smart_pointers/smart_pointers3.rs with errors
$ cargo run -- run smart_pointers4
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run smart_pointers4`
error[E0532]: expected a pattern, found a function call
  --> ../exercises/19_smart_pointers/smart_pointers4.rs:42:33
   |
42 |         assert!(matches!(input, todo!()));
   |                                 ^^^^^^^ not a tuple struct or tuple variant
   |
   = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0532]: expected a pattern, found a function call
  --> ../exercises/19_smart_pointers/smart_pointers4.rs:55:33
   |
55 |         assert!(matches!(input, todo!()));
   |                                 ^^^^^^^ not a tuple struct or tuple variant
   |
   = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0532]: expected a pattern, found a function call
  --> ../exercises/19_smart_pointers/smart_pointers4.rs:67:33
   |
67 |         assert!(matches!(input, todo!()));
   |                                 ^^^^^^^ not a tuple struct or tuple variant
   |
   = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch19-00-patterns.html>
   = note: this error originates in the macro `todo` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0532`.
error: could not compile `exercises` (bin "smart_pointers4" test) due to 3 previous errors

Output

Ran exercises/19_smart_pointers/smart_pointers4.rs with errors
$ cargo run -- run conversions1
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run conversions1`
error[E0277]: cannot divide `f64` by `usize`
 --> ../exercises/23_conversions/conversions1.rs:8:11
  |
8 |     total / values.len()
  |           ^ no implementation for `f64 / usize`
  |
  = help: the trait `Div<usize>` is not implemented for `f64`
help: the following other types implement trait `Div<Rhs>`
 --> /rustc/254b59607d4417e9dffbc307138ae5c86280fe4c/library/core/src/ops/arith.rs:526:1
  |
  = note: `&f64` implements `Div<f64>`
  |
  = note: `&f64` implements `Div`
  |
  = note: `f64` implements `Div<&f64>`
  |
  = note: `f64` implements `Div`
  = note: this error originates in the macro `div_impl_float` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0277`.
error: could not compile `exercises` (bin "conversions1") due to 1 previous error

Ran exercises/23_conversions/conversions1.rs with errors
$ cargo run -- run conversions2
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run conversions2`
error[E0308]: mismatched types
  --> ../exercises/23_conversions/conversions2.rs:37:25
   |
37 |     fn from(s: &str) -> Self {}
   |        ----             ^^^^ expected `Person`, found `()`
   |        |
   |        implicitly returns `()` as its body has no tail or `return` expression

For more information about this error, try `rustc --explain E0308`.
error: could not compile `exercises` (bin "conversions2") due to 1 previous error

Ran exercises/23_conversions/conversions2.rs with errors
$ cargo run -- run conversions3
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run conversions3`
error[E0308]: mismatched types
  --> ../exercises/23_conversions/conversions3.rs:44:29
   |
44 |     fn from_str(s: &str) -> Result<Self, Self::Err> {}
   |        --------             ^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<Person, ParsePersonError>`, found `()`
   |        |
   |        implicitly returns `()` as its body has no tail or `return` expression
   |
   = note:   expected enum `Result<Person, ParsePersonError>`
           found unit type `()`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `exercises` (bin "conversions3") due to 1 previous error

Ran exercises/23_conversions/conversions3.rs with errors
$ cargo run -- run conversions4
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run conversions4`
error[E0308]: mismatched types
  --> ../exercises/23_conversions/conversions4.rs:31:44
   |
31 |     fn try_from(tuple: (i16, i16, i16)) -> Result<Self, Self::Error> {}
   |        --------                            ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<Color, IntoColorError>`, found `()`
   |        |
   |        implicitly returns `()` as its body has no tail or `return` expression
   |
   = note:   expected enum `Result<Color, IntoColorError>`
           found unit type `()`

error[E0308]: mismatched types
  --> ../exercises/23_conversions/conversions4.rs:38:35
   |
38 |     fn try_from(arr: [i16; 3]) -> Result<Self, Self::Error> {}
   |        --------                   ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<Color, IntoColorError>`, found `()`
   |        |
   |        implicitly returns `()` as its body has no tail or `return` expression
   |
   = note:   expected enum `Result<Color, IntoColorError>`
           found unit type `()`

error[E0308]: mismatched types
  --> ../exercises/23_conversions/conversions4.rs:46:35
   |
46 |     fn try_from(slice: &[i16]) -> Result<Self, Self::Error> {}
   |        --------                   ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Result<Color, IntoColorError>`, found `()`
   |        |
   |        implicitly returns `()` as its body has no tail or `return` expression
   |
   = note:   expected enum `Result<Color, IntoColorError>`
           found unit type `()`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `exercises` (bin "conversions4") due to 3 previous errors

Ran exercises/23_conversions/conversions4.rs with errors
$ cargo run -- run conversions5
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.05s
     Running `target/debug/rustlings run conversions5`
error[E0599]: no method named `as_ref` found for type parameter `T` in the current scope
 --> ../exercises/23_conversions/conversions5.rs:9:9
  |
8 | fn byte_counter<T>(arg: T) -> usize {
  |                 - method `as_ref` not found for this type parameter
9 |     arg.as_ref().len()
  |         ^^^^^^ method not found in `T`
  |
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `as_ref`, perhaps you need to restrict type parameter `T` with it:
  |
8 | fn byte_counter<T: AsRef</* T */>>(arg: T) -> usize {
  |                  ++++++++++++++++

error[E0599]: no method named `as_ref` found for type parameter `T` in the current scope
  --> ../exercises/23_conversions/conversions5.rs:15:9
   |
14 | fn char_counter<T>(arg: T) -> usize {
   |                 - method `as_ref` not found for this type parameter
15 |     arg.as_ref().chars().count()
   |         ^^^^^^ method not found in `T`
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `as_ref`, perhaps you need to restrict type parameter `T` with it:
   |
14 | fn char_counter<T: AsRef</* T */>>(arg: T) -> usize {
   |                  ++++++++++++++++

warning: unused variable: `arg`
  --> ../exercises/23_conversions/conversions5.rs:20:14
   |
20 | fn num_sq<T>(arg: &mut T) {
   |              ^^^ help: if this is intentional, prefix it with an underscore: `_arg`
   |
   = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default

For more information about this error, try `rustc --explain E0599`.
error: could not compile `exercises` (bin "conversions5") due to 2 previous errors; 1 warning emitted

Ran exercises/23_conversions/conversions5.rs with errors

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.

1 participant