rustlings icon indicating copy to clipboard operation
rustlings copied to clipboard

cow1.rs last test is missing to_mut

Open quidnu opened this issue 1 year ago • 8 comments

cow1.rs last test owned_mutation is missing to_mut as described in the comment. As is it is identical to the previous test, owned_no_mutation

quidnu avatar Aug 05 '23 18:08 quidnu

@quidnu @mkovaxx I'm getting this type error and I'm not sure what the intended fix is? Am I only supposed to add code under //TODO?

⚠️  Compiling of exercises/smart_pointers/cow1.rs failed! Please try again. Here's the output:
error[E0308]: mismatched types
  --> exercises/smart_pointers/cow1.rs:74:23
   |
74 |         match abs_all(&mut input) {
   |               ------- ^^^^^^^^^^ expected `&mut Cow<'_, [i32]>`, found `&mut &mut Vec<{integer}>`
   |               |
   |               arguments to this function are incorrect
   |
   = note: expected mutable reference `&mut std::borrow::Cow<'_, [i32]>`
              found mutable reference `&mut &mut Vec<{integer}>`
note: function defined here
  --> exercises/smart_pointers/cow1.rs:19:4
   |
19 | fn abs_all<'a, 'b>(input: &'a mut Cow<'b, [i32]>) -> &'a mut Cow<'b, [i32]> {
   |    ^^^^^^^         -----------------------------

error: aborting due to previous error

wh5a avatar Sep 07 '23 08:09 wh5a

In fact, I think we should not add to_mut, as the comment is actually referring to the to_mut call inside the abs_all function. owned_mutation isn't identical to owned_no_mutation if you look more closely at the input vector.

wh5a avatar Sep 07 '23 08:09 wh5a

This should have been checked before merging. #1620 has presented a regression. @shadows-withal could you please reopen this issue.

pchilds avatar Sep 18 '23 04:09 pchilds

My bad! I'll push a patch release to address this regression.

shadows-withal avatar Sep 18 '23 08:09 shadows-withal

Also, I'll keep this issue open, but @wh5a said it correctly: The comment is correct, the abs_all function presents a special behaviour when processing a negative number.

shadows-withal avatar Sep 18 '23 08:09 shadows-withal

Isn't this already fixed by someone else?

wh5a avatar Sep 18 '23 08:09 wh5a

In 33a4f4e454031ea7b318c855625553b413b8afcd, yeah. I'm just keeping the issue open in case anyone else runs into confusion.

shadows-withal avatar Sep 18 '23 08:09 shadows-withal

In 33a4f4e, yeah. I'm just keeping the issue open in case anyone else runs into confusion.

And thank you for that -- was really confused on what to change at this point working through the exercises! Good to read through the thread and figure it out.

PranavJayachand avatar Sep 20 '23 01:09 PranavJayachand

Further improved in https://github.com/rust-lang/rustlings/commit/9d7b973a62d3c0181be386752d72fa0722fe6135

mo8it avatar Jul 07 '24 15:07 mo8it