Fix warnings

This commit is contained in:
mo8it 2024-07-04 13:38:35 +02:00
parent a4c07ca948
commit b87aa98634
18 changed files with 28 additions and 8 deletions

View file

@ -1,3 +1,5 @@
#![allow(clippy::ptr_arg)]
// TODO: Fix the compiler errors without changing anything except adding or
// removing references (the character `&`).

View file

@ -1,3 +1,4 @@
#[allow(dead_code)]
#[derive(Debug)]
enum Message {
// TODO: Define the different variants used below.
@ -5,7 +6,7 @@ enum Message {
impl Message {
fn call(&self) {
println!("{:?}", self);
println!("{self:?}");
}
}

View file

@ -1,6 +1,7 @@
// You can bring module paths into scopes and provide new names for them with
// the `use` and `as` keywords.
#[allow(dead_code)]
mod delicious_snacks {
// TODO: Add the following two `use` statements after fixing them.
// use self::fruits::PEAR as ???;

View file

@ -1,3 +1,5 @@
#![allow(clippy::comparison_chain)]
#[derive(PartialEq, Debug)]
enum CreationError {
Negative,

View file

@ -35,7 +35,7 @@ impl PositiveNonzeroInteger {
fn new(value: i64) -> Result<Self, CreationError> {
match value {
x if x < 0 => Err(CreationError::Negative),
x if x == 0 => Err(CreationError::Zero),
0 => Err(CreationError::Zero),
x => Ok(Self(x as u64)),
}
}
@ -55,7 +55,6 @@ fn main() {
#[cfg(test)]
mod test {
use super::*;
use std::num::IntErrorKind;
#[test]
fn test_parse_error() {

View file

@ -1,3 +1,5 @@
#![allow(dead_code)]
trait Licensed {
// TODO: Add a default implementation for `licensing_info` so that
// implementors like the two structs below can share that default behavior

View file

@ -8,6 +8,7 @@ use std::rc::Rc;
#[derive(Debug)]
struct Sun;
#[allow(dead_code)]
#[derive(Debug)]
enum Planet {
Mercury(Rc<Sun>),

View file

@ -1,3 +1,5 @@
#![allow(clippy::needless_late_init)]
fn main() {
// Reading uninitialized variables isn't allowed in Rust!
// Therefore, we need to assign a value first.

View file

@ -1,3 +1,5 @@
#![allow(clippy::ptr_arg)]
fn main() {
let data = "Rust is great!".to_string();

View file

@ -1,3 +1,4 @@
#[allow(dead_code)]
#[derive(Debug)]
enum Message {
Move { x: i64, y: i64 },
@ -8,7 +9,7 @@ enum Message {
impl Message {
fn call(&self) {
println!("{:?}", self);
println!("{self:?}");
}
}

View file

@ -1,3 +1,4 @@
#[allow(dead_code)]
mod delicious_snacks {
// Added `pub` and used the expected alias after `as`.
pub use self::fruits::PEAR as fruit;

View file

@ -28,13 +28,13 @@ fn build_scores_table(results: &str) -> HashMap<&str, Team> {
let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap();
// Insert the default with zeros if a team doesn't exist yet.
let mut team_1 = scores.entry(team_1_name).or_insert_with(|| Team::default());
let team_1 = scores.entry(team_1_name).or_insert_with(Team::default);
// Update the values.
team_1.goals_scored += team_1_score;
team_1.goals_conceded += team_2_score;
// Similarely for the second team.
let mut team_2 = scores.entry(team_2_name).or_insert_with(|| Team::default());
let team_2 = scores.entry(team_2_name).or_insert_with(Team::default);
team_2.goals_scored += team_2_score;
team_2.goals_conceded += team_1_score;
}

View file

@ -16,6 +16,7 @@
use std::num::ParseIntError;
#[allow(unused_variables)]
fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
let processing_fee = 1;
let cost_per_item = 5;

View file

@ -1,3 +1,5 @@
#![allow(clippy::comparison_chain)]
#[derive(PartialEq, Debug)]
enum CreationError {
Negative,

View file

@ -36,7 +36,7 @@ impl PositiveNonzeroInteger {
fn new(value: i64) -> Result<Self, CreationError> {
match value {
x if x < 0 => Err(CreationError::Negative),
x if x == 0 => Err(CreationError::Zero),
0 => Err(CreationError::Zero),
x => Ok(Self(x as u64)),
}
}
@ -57,7 +57,6 @@ fn main() {
#[cfg(test)]
mod test {
use super::*;
use std::num::IntErrorKind;
#[test]
fn test_parse_error() {

View file

@ -1,3 +1,5 @@
#![allow(dead_code)]
trait Licensed {
fn licensing_info(&self) -> String {
"Default license".to_string()

View file

@ -8,6 +8,7 @@ use std::rc::Rc;
#[derive(Debug)]
struct Sun;
#[allow(dead_code)]
#[derive(Debug)]
enum Planet {
Mercury(Rc<Sun>),

View file

@ -4,6 +4,7 @@
// type itself. You can read more about it in the documentation:
// https://doc.rust-lang.org/std/convert/trait.TryFrom.html
#![allow(clippy::useless_vec)]
use std::convert::{TryFrom, TryInto};
#[derive(Debug, PartialEq)]