Commit afbbefdd authored by Robert Czechowski's avatar Robert Czechowski Committed by Robert Czechowski
Browse files

Clean up some clippy lints

parent de4d0a11
...@@ -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::redundant_field_names -A clippy::useless_format -A clippy::let_and_return -A clippy::type_complexity -A clippy::option_map_unit_fn -A clippy::identity_conversion -A clippy::expect_fun_call -A clippy::option-as-ref-deref cargo clippy --all-targets --features 'complete debug' -- -D warnings -A clippy::type-complexity -A clippy::option-map-unit-fn -A clippy::len-zero
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
......
...@@ -237,7 +237,7 @@ fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<i32>) -> Vec ...@@ -237,7 +237,7 @@ fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<i32>) -> Vec
let linktext = format!("{}{}", let linktext = format!("{}{}",
str::repeat("★", blackstars as usize), str::repeat("★", blackstars as usize),
str::repeat("☆", st.stars as usize - blackstars as usize)); str::repeat("☆", st.stars as usize - blackstars as usize));
let si = SubTaskInfo { id: st.id.unwrap(), linktext: linktext, active, greyout }; let si = SubTaskInfo { id: st.id.unwrap(), linktext, active, greyout };
subtaskinfos.push(si); subtaskinfos.push(si);
} }
...@@ -427,7 +427,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi ...@@ -427,7 +427,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
userresults.push(format!("{}", g)); userresults.push(format!("{}", g));
summe += g; summe += g;
} else { } else {
userresults.push(format!("–")); userresults.push("–".to_string());
} }
} }
...@@ -440,7 +440,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi ...@@ -440,7 +440,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
userresults)) userresults))
} }
results.push((format!("{}", group.name), group.id.unwrap_or(0), groupresults)); results.push((group.name.to_string(), group.id.unwrap_or(0), groupresults));
} }
data.insert("taskname".to_string(), to_json(&tasknames)); data.insert("taskname".to_string(), to_json(&tasknames));
...@@ -577,7 +577,7 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: i32, session_token ...@@ -577,7 +577,7 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: i32, session_token
let submission = Submission { id: None, let submission = Submission { id: None,
session_user: session.id, session_user: session.id,
task: task_id, task: task_id,
grade: grade, grade,
validated: false, validated: false,
nonvalidated_grade: grade, nonvalidated_grade: grade,
needs_validation: true, needs_validation: true,
...@@ -747,11 +747,11 @@ pub fn add_group<T: MedalConnection>(conn: &T, session_token: &str, csrf_token: ...@@ -747,11 +747,11 @@ pub fn add_group<T: MedalConnection>(conn: &T, session_token: &str, csrf_token:
return Err(MedalError::CsrfCheckFailed); return Err(MedalError::CsrfCheckFailed);
} }
let group_code = helpers::make_group_code(); let groupcode = helpers::make_group_code();
// TODO: check for collisions // TODO: check for collisions
let mut group = let mut group =
Group { id: None, name: name, groupcode: group_code, tag: tag, admin: session.id, members: Vec::new() }; Group { id: None, name, groupcode, tag, admin: session.id, members: Vec::new() };
conn.add_group(&mut group); conn.add_group(&mut group);
......
...@@ -573,7 +573,7 @@ impl MedalConnection for Connection { ...@@ -573,7 +573,7 @@ impl MedalConnection for Connection {
ORDER BY id DESC ORDER BY id DESC
LIMIT 1"; LIMIT 1";
self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)), self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)),
task: task, task,
session_user: session.id, session_user: session.id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
...@@ -594,7 +594,7 @@ impl MedalConnection for Connection { ...@@ -594,7 +594,7 @@ impl MedalConnection for Connection {
LIMIT 1"; LIMIT 1";
self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| { self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| {
Submission { id: Some(row.get(0)), Submission { id: Some(row.get(0)),
task: task, task,
session_user: session.id, session_user: session.id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
...@@ -616,7 +616,7 @@ impl MedalConnection for Connection { ...@@ -616,7 +616,7 @@ impl MedalConnection for Connection {
WHERE task = $1 WHERE task = $1
AND session = $2"; AND session = $2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)), self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task, task,
session_user: session_id, session_user: session_id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
......
...@@ -52,7 +52,7 @@ impl Queryable for Connection { ...@@ -52,7 +52,7 @@ impl Queryable for Connection {
fn exists(&self, sql: &str, params: &[&dyn postgres::types::ToSql]) -> bool { fn exists(&self, sql: &str, params: &[&dyn postgres::types::ToSql]) -> bool {
let stmt = self.prepare(sql).unwrap(); let stmt = self.prepare(sql).unwrap();
!stmt.query(params).unwrap().is_empty() stmt.query(params).unwrap().len() > 0
} }
fn get_last_id(&self) -> Option<i32> { fn get_last_id(&self) -> Option<i32> {
......
...@@ -65,7 +65,7 @@ impl Queryable for Connection { ...@@ -65,7 +65,7 @@ impl Queryable for Connection {
fn exists(&self, sql: &str, params: &[&dyn postgres::types::ToSql]) -> bool { fn exists(&self, sql: &str, params: &[&dyn postgres::types::ToSql]) -> bool {
let stmt = self.prepare(sql).unwrap(); let stmt = self.prepare(sql).unwrap();
!stmt.query(params).unwrap().is_empty() stmt.query(params).unwrap().len() > 0
} }
fn get_last_id(&self) -> Option<i32> { fn get_last_id(&self) -> Option<i32> {
...@@ -685,7 +685,7 @@ impl MedalConnection for Connection { ...@@ -685,7 +685,7 @@ impl MedalConnection for Connection {
ORDER BY id DESC ORDER BY id DESC
LIMIT 1"; LIMIT 1";
self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)), self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)),
task: task, task,
session_user: session.id, session_user: session.id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
...@@ -706,7 +706,7 @@ impl MedalConnection for Connection { ...@@ -706,7 +706,7 @@ impl MedalConnection for Connection {
LIMIT 1"; LIMIT 1";
self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| { self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| {
Submission { id: Some(row.get(0)), Submission { id: Some(row.get(0)),
task: task, task,
session_user: session.id, session_user: session.id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
...@@ -728,7 +728,7 @@ impl MedalConnection for Connection { ...@@ -728,7 +728,7 @@ impl MedalConnection for Connection {
WHERE task = $1 WHERE task = $1
AND session = $2"; AND session = $2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)), self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task, task,
session_user: session_id, session_user: session_id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
......
...@@ -685,7 +685,7 @@ impl MedalConnection for Connection { ...@@ -685,7 +685,7 @@ impl MedalConnection for Connection {
ORDER BY id DESC ORDER BY id DESC
LIMIT 1"; LIMIT 1";
self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)), self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)),
task: task, task,
session_user: session.id, session_user: session.id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
...@@ -706,7 +706,7 @@ impl MedalConnection for Connection { ...@@ -706,7 +706,7 @@ impl MedalConnection for Connection {
LIMIT 1"; LIMIT 1";
self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| { self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| {
Submission { id: Some(row.get(0)), Submission { id: Some(row.get(0)),
task: task, task,
session_user: session.id, session_user: session.id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
...@@ -728,7 +728,7 @@ impl MedalConnection for Connection { ...@@ -728,7 +728,7 @@ impl MedalConnection for Connection {
WHERE task = ?1 WHERE task = ?1
AND session = ?2"; AND session = ?2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)), self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task, task,
session_user: session_id, session_user: session_id,
grade: row.get(1), grade: row.get(1),
validated: row.get(2), validated: row.get(2),
......
...@@ -172,18 +172,18 @@ impl Contest { ...@@ -172,18 +172,18 @@ impl Contest {
-> Self -> Self
{ {
Contest { id: None, Contest { id: None,
location: location, location,
filename: filename, filename,
name: name, name,
duration: duration, duration,
public: public, public,
start: start, start,
end: end, end,
min_grade: min_grade, min_grade,
max_grade: max_grade, max_grade,
positionalnumber: positionalnumber, positionalnumber,
requires_login: requires_login, requires_login,
secret: secret, secret,
taskgroups: Vec::new() } taskgroups: Vec::new() }
} }
} }
...@@ -191,9 +191,9 @@ impl Contest { ...@@ -191,9 +191,9 @@ impl Contest {
impl SessionUser { impl SessionUser {
pub fn minimal(id: i32, session_token: String, csrf_token: String) -> Self { pub fn minimal(id: i32, session_token: String, csrf_token: String) -> Self {
SessionUser { SessionUser {
id: id, id,
session_token: Some(session_token), session_token: Some(session_token),
csrf_token: csrf_token, csrf_token,
last_login: None, last_login: None,
last_activity: None, // now? last_activity: None, // now?
// müssen die überhaupt außerhalb der datenbankabstraktion sichtbar sein? // müssen die überhaupt außerhalb der datenbankabstraktion sichtbar sein?
...@@ -317,16 +317,16 @@ impl Taskgroup { ...@@ -317,16 +317,16 @@ impl Taskgroup {
pub fn new(name: String, positionalnumber: Option<i32>) -> Self { pub fn new(name: String, positionalnumber: Option<i32>) -> Self {
Taskgroup { id: None, Taskgroup { id: None,
contest: 0, contest: 0,
name: name, name,
active: true, active: true,
positionalnumber: positionalnumber, positionalnumber,
tasks: Vec::new() } tasks: Vec::new() }
} }
} }
impl Task { impl Task {
pub fn new(location: String, stars: i32) -> Self { pub fn new(location: String, stars: i32) -> Self {
Task { id: None, taskgroup: 0, location: location, stars: stars } Task { id: None, taskgroup: 0, location, stars }
} }
} }
......
...@@ -372,7 +372,8 @@ mod tests { ...@@ -372,7 +372,8 @@ mod tests {
let mut config = config::read_config_from_file(Path::new("thisfileshoudnotexist")); let mut config = config::read_config_from_file(Path::new("thisfileshoudnotexist"));
config.port = Some(port); config.port = Some(port);
config.cookie_signing_secret = Some("testtesttesttesttesttesttesttest".to_string()); config.cookie_signing_secret = Some("testtesttesttesttesttesttesttest".to_string());
let mut srvr = start_server(conn, config).expect(&format!("Could not start server on port {}", port)); let message = format!("Could not start server on port {}", port);
let mut srvr = start_server(conn, config).expect(&message);
// Message server started // Message server started
start_tx.send(()).unwrap(); start_tx.send(()).unwrap();
...@@ -396,14 +397,12 @@ mod tests { ...@@ -396,14 +397,12 @@ mod tests {
fn login(port: u16, client: &reqwest::Client, username: &str, password: &str) -> reqwest::Response { fn login(port: u16, client: &reqwest::Client, username: &str, password: &str) -> reqwest::Response {
let params = [("username", username), ("password", password)]; let params = [("username", username), ("password", password)];
let resp = client.post(&format!("http://localhost:{}/login", port)).form(&params).send().unwrap(); client.post(&format!("http://localhost:{}/login", port)).form(&params).send().unwrap()
resp
} }
fn login_code(port: u16, client: &reqwest::Client, code: &str) -> reqwest::Response { fn login_code(port: u16, client: &reqwest::Client, code: &str) -> reqwest::Response {
let params = [("code", code)]; let params = [("code", code)];
let resp = client.post(&format!("http://localhost:{}/clogin", port)).form(&params).send().unwrap(); client.post(&format!("http://localhost:{}/clogin", port)).form(&params).send().unwrap()
resp
} }
#[test] #[test]
......
...@@ -603,8 +603,8 @@ fn submission<C>(req: &mut Request) -> IronResult<Response> ...@@ -603,8 +603,8 @@ fn submission<C>(req: &mut Request) -> IronResult<Response>
let result = with_conn![core::load_submission, C, req, task_id, &session_token, subtask]; let result = with_conn![core::load_submission, C, req, task_id, &session_token, subtask];
match result { match result {
Ok(data) => Ok(Response::with((status::Ok, mime!(Application / Json), format!("{}", data)))), Ok(data) => Ok(Response::with((status::Ok, mime!(Application / Json), data.to_string()))),
Err(_) => Ok(Response::with((status::BadRequest, mime!(Application / Json), format!("{{}}")))), Err(_) => Ok(Response::with((status::BadRequest, mime!(Application / Json), "{}".to_string()))),
} }
} }
......
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