Commit 3c52b722 authored by Robert Czechowski's avatar Robert Czechowski
Browse files

New clippy fixes

parent 68d2b546
Pipeline #929 failed with stages
in 6 minutes and 34 seconds
...@@ -20,7 +20,7 @@ format: src/db_conn_postgres.rs ...@@ -20,7 +20,7 @@ format: src/db_conn_postgres.rs
cargo +nightly fmt cargo +nightly fmt
clippy: src/db_conn_postgres.rs clippy: src/db_conn_postgres.rs
cargo clippy --all-targets --features 'complete debug' -- -D warnings -A clippy::type-complexity -A clippy::option-map-unit-fn -A clippy::len-zero -A clippy::option-as-ref-deref -A clippy::or-fun-call cargo clippy --all-targets --features 'complete debug' -- -D warnings -A clippy::type-complexity -A clippy::option-map-unit-fn -A clippy::len-zero -A clippy::option-as-ref-deref -A clippy::or-fun-call -A clippy::comparison-to-empty -A clippy::unnecessary-wraps -A clippy::result-unit-err
src/db_conn_postgres.rs: src/db_conn_warning_header.txt src/db_conn_sqlite_new.header.rs src/db_conn_postgres.header.rs src/db_conn.base.rs src/db_conn_postgres.rs: src/db_conn_warning_header.txt src/db_conn_sqlite_new.header.rs src/db_conn_postgres.header.rs src/db_conn.base.rs
cd src; ./generate_connectors.sh cd src; ./generate_connectors.sh
......
...@@ -587,8 +587,7 @@ pub fn signup<T: MedalConnection>(conn: &T, session_token: Option<String>, signu ...@@ -587,8 +587,7 @@ pub fn signup<T: MedalConnection>(conn: &T, session_token: Option<String>, signu
pub fn signupdata(query_string: Option<String>) -> json_val::Map<String, json_val::Value> { pub fn signupdata(query_string: Option<String>) -> json_val::Map<String, json_val::Value> {
let mut data = json_val::Map::new(); let mut data = json_val::Map::new();
if let Some(query) = query_string { if let Some(query) = query_string {
if query.starts_with("status=") { if let Some(status) = query.strip_prefix("status=") {
let status: &str = &query[7..];
if ["EmailTaken", "UsernameTaken", "UserLoggedIn", "EmptyFields"].contains(&status) { if ["EmailTaken", "UsernameTaken", "UserLoggedIn", "EmptyFields"].contains(&status) {
data.insert((status).to_string(), to_json(&true)); data.insert((status).to_string(), to_json(&true));
} }
...@@ -978,8 +977,7 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: ...@@ -978,8 +977,7 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
data.insert("ownprofile".into(), to_json(&true)); data.insert("ownprofile".into(), to_json(&true));
if let Some(query) = query_string { if let Some(query) = query_string {
if query.starts_with("status=") { if let Some(status) = query.strip_prefix("status=") {
let status: &str = &query[7..];
if ["NothingChanged", if ["NothingChanged",
"DataChanged", "DataChanged",
"PasswordChanged", "PasswordChanged",
...@@ -1043,8 +1041,7 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: ...@@ -1043,8 +1041,7 @@ pub fn show_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id:
data.insert("ownprofile".into(), to_json(&false)); data.insert("ownprofile".into(), to_json(&false));
if let Some(query) = query_string { if let Some(query) = query_string {
if query.starts_with("status=") { if let Some(status) = query.strip_prefix("status=") {
let status: &str = &query[7..];
if ["NothingChanged", "DataChanged", "PasswordChanged", "PasswordMissmatch"].contains(&status) { if ["NothingChanged", "DataChanged", "PasswordChanged", "PasswordMissmatch"].contains(&status) {
data.insert((status).to_string(), to_json(&true)); data.insert((status).to_string(), to_json(&true));
} }
...@@ -1063,8 +1060,8 @@ pub enum ProfileStatus { ...@@ -1063,8 +1060,8 @@ pub enum ProfileStatus {
PasswordChanged, PasswordChanged,
PasswordMissmatch, PasswordMissmatch,
} }
impl std::convert::Into<String> for ProfileStatus { impl From<ProfileStatus> for String {
fn into(self) -> String { format!("{:?}", self) } fn from(s: ProfileStatus) -> String { format!("{:?}", s) }
} }
pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<i32>, csrf_token: &str, pub fn edit_profile<T: MedalConnection>(conn: &T, session_token: &str, user_id: Option<i32>, csrf_token: &str,
......
...@@ -65,9 +65,9 @@ use webfw_iron::start_server; ...@@ -65,9 +65,9 @@ use webfw_iron::start_server;
use config::Config; use config::Config;
use structopt::StructOpt; use structopt::StructOpt;
use std::path::{Path, PathBuf}; use std::path::Path;
fn read_contest(p: &PathBuf) -> Option<Contest> { fn read_contest(p: &Path) -> Option<Contest> {
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
...@@ -81,7 +81,7 @@ fn read_contest(p: &PathBuf) -> Option<Contest> { ...@@ -81,7 +81,7 @@ fn read_contest(p: &PathBuf) -> Option<Contest> {
} }
fn get_all_contest_info(task_dir: &str) -> Vec<Contest> { fn get_all_contest_info(task_dir: &str) -> Vec<Contest> {
fn walk_me_recursively(p: &PathBuf, contests: &mut Vec<Contest>) { fn walk_me_recursively(p: &Path, contests: &mut Vec<Contest>) {
if let Ok(paths) = std::fs::read_dir(p) { if let Ok(paths) = std::fs::read_dir(p) {
for path in paths { for path in paths {
let p = path.unwrap().path(); let p = path.unwrap().path();
...@@ -92,7 +92,7 @@ fn get_all_contest_info(task_dir: &str) -> Vec<Contest> { ...@@ -92,7 +92,7 @@ fn get_all_contest_info(task_dir: &str) -> Vec<Contest> {
if p.file_name().unwrap().to_string_lossy().to_string().ends_with(".yaml") { if p.file_name().unwrap().to_string_lossy().to_string().ends_with(".yaml") {
read_contest(p).map(|contest| contests.push(contest)); read_contest(p).map(|contest| contests.push(contest));
}; };
}; }
let mut contests = Vec::new(); let mut contests = Vec::new();
match std::fs::read_dir(task_dir) { match std::fs::read_dir(task_dir) {
......
...@@ -99,7 +99,7 @@ impl AfterMiddleware for ErrorShower { ...@@ -99,7 +99,7 @@ impl AfterMiddleware for ErrorShower {
Ok(match response.status { Ok(match response.status {
Some(s) => { Some(s) => {
let n = s.to_u16(); let n = s.to_u16();
if n >= 400 && n <= 599 { if (400..=599).contains(&n) {
response.set((mime!(Text / Html), response.set((mime!(Text / Html),
format!("<h1>{} {}</h1>", n, s.canonical_reason().unwrap_or("(Unknown error)")))) format!("<h1>{} {}</h1>", n, s.canonical_reason().unwrap_or("(Unknown error)"))))
} else { } else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment