Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix clippy warnings #1998

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ fn drop_no_double_frees() {
use std::cell::Cell;
struct DropCounter<'a>(&'a Cell<usize>);

impl<'a> Drop for DropCounter<'a> {
impl Drop for DropCounter<'_> {
fn drop(&mut self) {
let num = self.0.get();
self.0.set(num + 1);
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/grep/tests/grep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ impl<'a> Files<'a> {
}
}

impl<'a> Drop for Files<'a> {
impl Drop for Files<'_> {
fn drop(&mut self) {
for file_name in self.file_names {
std::fs::remove_file(file_name)
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/luhn-from/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ impl Luhn {

/// Here is the example of how the From trait could be implemented
/// for the &str type. Naturally, you can implement this trait
/// by hand for the every other type presented in the test suite,
/// by hand for every other type presented in the test suite,
/// but your solution will fail if a new type is presented.
/// Perhaps there exists a better solution for this problem?
impl<'a> From<&'a str> for Luhn {
fn from(input: &'a str) -> Self {
impl From<&str> for Luhn {
fn from(input: &str) -> Self {
todo!("From the given input '{input}' create a new Luhn struct.");
}
}
2 changes: 1 addition & 1 deletion exercises/practice/luhn-trait/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Luhn for String {
}
}

impl<'a> Luhn for &'a str {
impl Luhn for &str {
fn valid_luhn(&self) -> bool {
String::from(*self).valid_luhn()
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/luhn-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ pub trait Luhn {

/// Here is the example of how to implement custom Luhn trait
/// for the &str type. Naturally, you can implement this trait
/// by hand for the every other type presented in the test suite,
/// by hand for every other type presented in the test suite,
/// but your solution will fail if a new type is presented.
/// Perhaps there exists a better solution for this problem?
impl<'a> Luhn for &'a str {
impl Luhn for &str {
fn valid_luhn(&self) -> bool {
todo!("Determine if '{self}' is a valid credit card number.");
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/matching-brackets/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct Brackets {
pairs: MatchingBrackets,
}

impl<'a> From<&'a str> for Brackets {
impl From<&str> for Brackets {
fn from(i: &str) -> Self {
Brackets::new(i, None)
}
Expand Down
12 changes: 6 additions & 6 deletions exercises/practice/poker/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl fmt::Display for Suit {
}
}

impl<'a> TryFrom<&'a str> for Suit {
impl TryFrom<&str> for Suit {
type Error = &'static str;

fn try_from(source: &str) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -115,7 +115,7 @@ impl PartialOrd for Rank {
}
}

impl<'a> TryFrom<&'a str> for Rank {
impl TryFrom<&str> for Rank {
type Error = &'static str;

fn try_from(source: &str) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -160,7 +160,7 @@ impl fmt::Display for Card {
}
}

impl<'a> TryFrom<&'a str> for Card {
impl TryFrom<&str> for Card {
type Error = &'static str;

fn try_from(source: &str) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -262,7 +262,7 @@ struct Hand<'a> {
hand_type: PokerHand,
}

impl<'a> Hand<'a> {
impl Hand<'_> {
fn cmp_high_card(&self, other: &Hand, card: usize) -> Ordering {
let mut ordering = self.cards[card]
.rank
Expand Down Expand Up @@ -312,13 +312,13 @@ impl<'a> Hand<'a> {
}
}

impl<'a> fmt::Display for Hand<'a> {
impl fmt::Display for Hand<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.source)
}
}

impl<'a> PartialOrd for Hand<'a> {
impl PartialOrd for Hand<'_> {
fn partial_cmp(&self, other: &Hand) -> Option<Ordering> {
Some(self.hand_type.cmp(&other.hand_type).then_with(|| {
use crate::PokerHand::*;
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/react/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<'a, T: Copy + PartialEq> Reactor<'a, T> {
}
}

impl<'a, T: Copy + PartialEq> Default for Reactor<'a, T> {
impl<T: Copy + PartialEq> Default for Reactor<'_, T> {
fn default() -> Self {
Self::new()
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/rectangles/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Area for RealArea {
struct TransposedArea<'a>(&'a RealArea);

// For vertical scanning
impl<'a> Area for TransposedArea<'a> {
impl Area for TransposedArea<'_> {
#[allow(clippy::misnamed_getters)]
fn width(&self) -> usize {
self.0.height
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/xorcism/.meta/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ where
}
}

impl<'a, W> Write for Writer<'a, W>
impl<W> Write for Writer<'_, W>
where
W: Write,
{
Expand Down Expand Up @@ -149,7 +149,7 @@ where
}
}

impl<'a, R> Read for Reader<'a, R>
impl<R> Read for Reader<'_, R>
where
R: Read,
{
Expand Down