mirror of
https://github.com/rust-lang/rustlings.git
synced 2025-12-31 15:59:18 +00:00
fix: showing unnecessary x is never used warnings
This commit is contained in:
parent
2b7caf6fcb
commit
9f15c1bfee
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn bigger(a: i32, b: i32) -> i32 {
|
fn bigger(a: i32, b: i32) -> i32 {
|
||||||
// TODO: Complete this function to return the bigger number!
|
// TODO: Complete this function to return the bigger number!
|
||||||
// If both numbers are equal, any of them can be returned.
|
// If both numbers are equal, any of them can be returned.
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// TODO: Fix the compiler error on this function.
|
// TODO: Fix the compiler error on this function.
|
||||||
fn foo_if_fizz(fizzish: &str) -> &str {
|
fn foo_if_fizz(fizzish: &str) -> &str {
|
||||||
if fizzish == "fizz" {
|
if fizzish == "fizz" {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn animal_habitat(animal: &str) -> &str {
|
fn animal_habitat(animal: &str) -> &str {
|
||||||
// TODO: Fix the compiler error in the statement below.
|
// TODO: Fix the compiler error in the statement below.
|
||||||
let identifier = if animal == "crab" {
|
let identifier = if animal == "crab" {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
fn array_and_vec() -> ([i32; 4], Vec<i32>) {
|
||||||
let a = [10, 20, 30, 40]; // Array
|
let a = [10, 20, 30, 40]; // Array
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn vec_loop(input: &[i32]) -> Vec<i32> {
|
fn vec_loop(input: &[i32]) -> Vec<i32> {
|
||||||
let mut output = Vec::new();
|
let mut output = Vec::new();
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// TODO: Fix the compiler error in this function.
|
// TODO: Fix the compiler error in this function.
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||||
let vec = vec;
|
let vec = vec;
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||||
let mut vec = vec;
|
let mut vec = vec;
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// TODO: Fix the compiler error in the function without adding any new line.
|
// TODO: Fix the compiler error in the function without adding any new line.
|
||||||
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {
|
||||||
vec.push(88);
|
vec.push(88);
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
struct ColorRegularStruct {
|
struct ColorRegularStruct {
|
||||||
// TODO: Add the fields that the test `regular_structs` expects.
|
// TODO: Add the fields that the test `regular_structs` expects.
|
||||||
// What types should the fields have? What are the minimum and maximum values for RGB colors?
|
// What types should the fields have? What are the minimum and maximum values for RGB colors?
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Order {
|
struct Order {
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// Structs contain data, but can also have logic. In this exercise, we have
|
// Structs contain data, but can also have logic. In this exercise, we have
|
||||||
// defined the `Package` struct, and we want to test some logic attached to it.
|
// defined the `Package` struct, and we want to test some logic attached to it.
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
x: u64,
|
x: u64,
|
||||||
y: u64,
|
y: u64,
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// We're collecting different fruits to bake a delicious fruit cake. For this,
|
// We're collecting different fruits to bake a delicious fruit cake. For this,
|
||||||
// we have a basket, which we'll represent in the form of a hash map. The key
|
// we have a basket, which we'll represent in the form of a hash map. The key
|
||||||
// represents the name of each fruit we collect and the value represents how
|
// represents the name of each fruit we collect and the value represents how
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// A list of scores (one per line) of a soccer match is given. Each line is of
|
// A list of scores (one per line) of a soccer match is given. Each line is of
|
||||||
// the form "<team_1_name>,<team_2_name>,<team_1_goals>,<team_2_goals>"
|
// the form "<team_1_name>,<team_2_name>,<team_1_goals>,<team_2_goals>"
|
||||||
// Example: "England,France,4,2" (England scored 4 goals, France 2).
|
// Example: "England,France,4,2" (England scored 4 goals, France 2).
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// TODO: This function refuses to generate text to be printed on a nametag if
|
// TODO: This function refuses to generate text to be printed on a nametag if
|
||||||
// you pass it an empty string. It'd be nicer if it explained what the problem
|
// you pass it an empty string. It'd be nicer if it explained what the problem
|
||||||
// was instead of just returning `None`. Thankfully, Rust has a similar
|
// was instead of just returning `None`. Thankfully, Rust has a similar
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
enum CreationError {
|
enum CreationError {
|
||||||
Negative,
|
Negative,
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// Using catch-all error types like `Box<dyn Error>` isn't recommended for
|
// Using catch-all error types like `Box<dyn Error>` isn't recommended for
|
||||||
// library code where callers might want to make decisions based on the error
|
// library code where callers might want to make decisions based on the error
|
||||||
// content instead of printing it out or propagating it further. Here, we define
|
// content instead of printing it out or propagating it further. Here, we define
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// This powerful wrapper provides the ability to store a positive integer value.
|
// This powerful wrapper provides the ability to store a positive integer value.
|
||||||
// TODO: Rewrite it using a generic so that it supports wrapping ANY type.
|
// TODO: Rewrite it using a generic so that it supports wrapping ANY type.
|
||||||
struct Wrapper {
|
struct Wrapper {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
trait AppendBar {
|
trait AppendBar {
|
||||||
fn append_bar(self) -> Self;
|
fn append_bar(self) -> Self;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// Tests are important to ensure that your code does what you think it should
|
// Tests are important to ensure that your code does what you think it should
|
||||||
// do.
|
// do.
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// Calculates the power of 2 using a bit shift.
|
// Calculates the power of 2 using a bit shift.
|
||||||
// `1 << n` is equivalent to "2 to the power of n".
|
// `1 << n` is equivalent to "2 to the power of n".
|
||||||
fn power_of_2(n: u8) -> u64 {
|
fn power_of_2(n: u8) -> u64 {
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
struct Rectangle {
|
struct Rectangle {
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
enum DivisionError {
|
enum DivisionError {
|
||||||
// Example: 42 / 0
|
// Example: 42 / 0
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// This exercise explores the `Cow` (Clone-On-Write) smart pointer. It can
|
// This exercise explores the `Cow` (Clone-On-Write) smart pointer. It can
|
||||||
// enclose and provide immutable access to borrowed data and clone the data
|
// enclose and provide immutable access to borrowed data and clone the data
|
||||||
// lazily when mutation or ownership is required. The type is designed to work
|
// lazily when mutation or ownership is required. The type is designed to work
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// In this exercise, we want to express the concept of multiple owners via the
|
// In this exercise, we want to express the concept of multiple owners via the
|
||||||
// `Rc<T>` type. This is a model of our solar system - there is a `Sun` type and
|
// `Rc<T>` type. This is a model of our solar system - there is a `Sun` type and
|
||||||
// multiple `Planet`s. The planets take ownership of the sun, indicating that
|
// multiple `Planet`s. The planets take ownership of the sun, indicating that
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// This is a quiz for the following sections:
|
// This is a quiz for the following sections:
|
||||||
// - Variables
|
// - Variables
|
||||||
// - Functions
|
// - Functions
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// This is a quiz for the following sections:
|
// This is a quiz for the following sections:
|
||||||
// - Strings
|
// - Strings
|
||||||
// - Vecs
|
// - Vecs
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
// This quiz tests:
|
// This quiz tests:
|
||||||
// - Generics
|
// - Generics
|
||||||
// - Traits
|
// - Traits
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user