Warn, explain, or remove _variables

I thought I’d bring this up since I just mentored another solution in sublist where the student kept the variable names as _first_list and _second_list.

Sublist
#[derive(Debug, PartialEq, Eq)]
pub enum Comparison {
    Equal,
    Sublist,
    Superlist,
    Unequal,
}

pub fn sublist<T: PartialEq>(_first_list: &[T], _second_list: &[T]) -> Comparison {
    todo!("Determine if the first list is equal to, sublist of, superlist of or unequal to the second list.");
}

Many exercises in the track seem to be attempting to provide code that has no compiler warnings. I can understand situations where multiple functions need to be implemented and you want to be able to test one without getting warnings from another, but in cases where it’s a single function I don’t see the point to starting variable names with _.

But maybe we should add a comment or automated feedback? (clippy doesn’t seem to mind this)

standard practice is to refer to the input args in the todo string. that’s mute the unused warning and the prefix _ can be removed. feel free to open a pr for this exercise.

If you give me the go-ahead, I’ll go through the rest of the exercises and update them.

1 Like

Sure, go ahead. I think there are some exercises where there are other factors involved. If the return type is an impl Trait the todo macro won’t compile. Maybe it’s impossible, maybe you can find a creative solution.