mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-11-08 09:09:17 +01:00
Fix warnings
This commit is contained in:
parent
a4c07ca948
commit
b87aa98634
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::ptr_arg)]
|
||||||
|
|
||||||
// TODO: Fix the compiler errors without changing anything except adding or
|
// TODO: Fix the compiler errors without changing anything except adding or
|
||||||
// removing references (the character `&`).
|
// removing references (the character `&`).
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Message {
|
enum Message {
|
||||||
// TODO: Define the different variants used below.
|
// TODO: Define the different variants used below.
|
||||||
@ -5,7 +6,7 @@ enum Message {
|
|||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
fn call(&self) {
|
fn call(&self) {
|
||||||
println!("{:?}", self);
|
println!("{self:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// You can bring module paths into scopes and provide new names for them with
|
// You can bring module paths into scopes and provide new names for them with
|
||||||
// the `use` and `as` keywords.
|
// the `use` and `as` keywords.
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
mod delicious_snacks {
|
mod delicious_snacks {
|
||||||
// TODO: Add the following two `use` statements after fixing them.
|
// TODO: Add the following two `use` statements after fixing them.
|
||||||
// use self::fruits::PEAR as ???;
|
// use self::fruits::PEAR as ???;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::comparison_chain)]
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
enum CreationError {
|
enum CreationError {
|
||||||
Negative,
|
Negative,
|
||||||
|
@ -35,7 +35,7 @@ impl PositiveNonzeroInteger {
|
|||||||
fn new(value: i64) -> Result<Self, CreationError> {
|
fn new(value: i64) -> Result<Self, CreationError> {
|
||||||
match value {
|
match value {
|
||||||
x if x < 0 => Err(CreationError::Negative),
|
x if x < 0 => Err(CreationError::Negative),
|
||||||
x if x == 0 => Err(CreationError::Zero),
|
0 => Err(CreationError::Zero),
|
||||||
x => Ok(Self(x as u64)),
|
x => Ok(Self(x as u64)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -55,7 +55,6 @@ fn main() {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::num::IntErrorKind;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_error() {
|
fn test_parse_error() {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
trait Licensed {
|
trait Licensed {
|
||||||
// TODO: Add a default implementation for `licensing_info` so that
|
// TODO: Add a default implementation for `licensing_info` so that
|
||||||
// implementors like the two structs below can share that default behavior
|
// implementors like the two structs below can share that default behavior
|
||||||
|
@ -8,6 +8,7 @@ use std::rc::Rc;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Sun;
|
struct Sun;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Planet {
|
enum Planet {
|
||||||
Mercury(Rc<Sun>),
|
Mercury(Rc<Sun>),
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::needless_late_init)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Reading uninitialized variables isn't allowed in Rust!
|
// Reading uninitialized variables isn't allowed in Rust!
|
||||||
// Therefore, we need to assign a value first.
|
// Therefore, we need to assign a value first.
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::ptr_arg)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let data = "Rust is great!".to_string();
|
let data = "Rust is great!".to_string();
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Message {
|
enum Message {
|
||||||
Move { x: i64, y: i64 },
|
Move { x: i64, y: i64 },
|
||||||
@ -8,7 +9,7 @@ enum Message {
|
|||||||
|
|
||||||
impl Message {
|
impl Message {
|
||||||
fn call(&self) {
|
fn call(&self) {
|
||||||
println!("{:?}", self);
|
println!("{self:?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#[allow(dead_code)]
|
||||||
mod delicious_snacks {
|
mod delicious_snacks {
|
||||||
// Added `pub` and used the expected alias after `as`.
|
// Added `pub` and used the expected alias after `as`.
|
||||||
pub use self::fruits::PEAR as fruit;
|
pub use self::fruits::PEAR as fruit;
|
||||||
|
@ -28,13 +28,13 @@ fn build_scores_table(results: &str) -> HashMap<&str, Team> {
|
|||||||
let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap();
|
let team_2_score: u8 = split_iterator.next().unwrap().parse().unwrap();
|
||||||
|
|
||||||
// Insert the default with zeros if a team doesn't exist yet.
|
// 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.
|
// Update the values.
|
||||||
team_1.goals_scored += team_1_score;
|
team_1.goals_scored += team_1_score;
|
||||||
team_1.goals_conceded += team_2_score;
|
team_1.goals_conceded += team_2_score;
|
||||||
|
|
||||||
// Similarely for the second team.
|
// 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_scored += team_2_score;
|
||||||
team_2.goals_conceded += team_1_score;
|
team_2.goals_conceded += team_1_score;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
|
#[allow(unused_variables)]
|
||||||
fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
||||||
let processing_fee = 1;
|
let processing_fee = 1;
|
||||||
let cost_per_item = 5;
|
let cost_per_item = 5;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(clippy::comparison_chain)]
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
enum CreationError {
|
enum CreationError {
|
||||||
Negative,
|
Negative,
|
||||||
|
@ -36,7 +36,7 @@ impl PositiveNonzeroInteger {
|
|||||||
fn new(value: i64) -> Result<Self, CreationError> {
|
fn new(value: i64) -> Result<Self, CreationError> {
|
||||||
match value {
|
match value {
|
||||||
x if x < 0 => Err(CreationError::Negative),
|
x if x < 0 => Err(CreationError::Negative),
|
||||||
x if x == 0 => Err(CreationError::Zero),
|
0 => Err(CreationError::Zero),
|
||||||
x => Ok(Self(x as u64)),
|
x => Ok(Self(x as u64)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,7 +57,6 @@ fn main() {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::num::IntErrorKind;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_error() {
|
fn test_parse_error() {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
trait Licensed {
|
trait Licensed {
|
||||||
fn licensing_info(&self) -> String {
|
fn licensing_info(&self) -> String {
|
||||||
"Default license".to_string()
|
"Default license".to_string()
|
||||||
|
@ -8,6 +8,7 @@ use std::rc::Rc;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Sun;
|
struct Sun;
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Planet {
|
enum Planet {
|
||||||
Mercury(Rc<Sun>),
|
Mercury(Rc<Sun>),
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
// type itself. You can read more about it in the documentation:
|
// type itself. You can read more about it in the documentation:
|
||||||
// https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
// https://doc.rust-lang.org/std/convert/trait.TryFrom.html
|
||||||
|
|
||||||
|
#![allow(clippy::useless_vec)]
|
||||||
use std::convert::{TryFrom, TryInto};
|
use std::convert::{TryFrom, TryInto};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
|
Loading…
Reference in New Issue
Block a user