Commit fd2fd64d authored by Robert Czechowski's avatar Robert Czechowski

Clean up some clippy lints

parent 51477dcd
Pipeline #735 failed with stage
in 1 minute and 37 seconds
......@@ -20,7 +20,7 @@ format: src/db_conn_postgres.rs
cargo +nightly fmt
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
cd src; ./generate_connectors.sh
......
......@@ -237,7 +237,7 @@ fn generate_subtaskstars(tg: &Taskgroup, grade: &Grade, ast: Option<i32>) -> Vec
let linktext = format!("{}{}",
str::repeat("★", 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);
}
......@@ -427,7 +427,7 @@ pub fn show_contest_results<T: MedalConnection>(conn: &T, contest_id: i32, sessi
userresults.push(format!("{}", g));
summe += g;
} 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
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));
......@@ -577,7 +577,7 @@ pub fn save_submission<T: MedalConnection>(conn: &T, task_id: i32, session_token
let submission = Submission { id: None,
session_user: session.id,
task: task_id,
grade: grade,
grade,
validated: false,
nonvalidated_grade: grade,
needs_validation: true,
......@@ -747,11 +747,11 @@ pub fn add_group<T: MedalConnection>(conn: &T, session_token: &str, csrf_token:
return Err(MedalError::CsrfCheckFailed);
}
let group_code = helpers::make_group_code();
let groupcode = helpers::make_group_code();
// TODO: check for collisions
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);
......
......@@ -573,7 +573,7 @@ impl MedalConnection for Connection {
ORDER BY id DESC
LIMIT 1";
self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session.id,
grade: row.get(1),
validated: row.get(2),
......@@ -594,7 +594,7 @@ impl MedalConnection for Connection {
LIMIT 1";
self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| {
Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session.id,
grade: row.get(1),
validated: row.get(2),
......@@ -616,7 +616,7 @@ impl MedalConnection for Connection {
WHERE task = $1
AND session = $2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session_id,
grade: row.get(1),
validated: row.get(2),
......
......@@ -52,7 +52,7 @@ impl Queryable for Connection {
fn exists(&self, sql: &str, params: &[&dyn postgres::types::ToSql]) -> bool {
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> {
......
......@@ -65,7 +65,7 @@ impl Queryable for Connection {
fn exists(&self, sql: &str, params: &[&dyn postgres::types::ToSql]) -> bool {
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> {
......@@ -685,7 +685,7 @@ impl MedalConnection for Connection {
ORDER BY id DESC
LIMIT 1";
self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session.id,
grade: row.get(1),
validated: row.get(2),
......@@ -706,7 +706,7 @@ impl MedalConnection for Connection {
LIMIT 1";
self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| {
Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session.id,
grade: row.get(1),
validated: row.get(2),
......@@ -728,7 +728,7 @@ impl MedalConnection for Connection {
WHERE task = $1
AND session = $2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session_id,
grade: row.get(1),
validated: row.get(2),
......
......@@ -685,7 +685,7 @@ impl MedalConnection for Connection {
ORDER BY id DESC
LIMIT 1";
self.query_map_one(query, &[&task, &session.id], |row| Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session.id,
grade: row.get(1),
validated: row.get(2),
......@@ -706,7 +706,7 @@ impl MedalConnection for Connection {
LIMIT 1";
self.query_map_one(query, &[&task, &session.id, &subtask_id], |row| {
Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session.id,
grade: row.get(1),
validated: row.get(2),
......@@ -728,7 +728,7 @@ impl MedalConnection for Connection {
WHERE task = ?1
AND session = ?2";
self.query_map_many(query, &[&task, &session_id], |row| Submission { id: Some(row.get(0)),
task: task,
task,
session_user: session_id,
grade: row.get(1),
validated: row.get(2),
......
......@@ -172,18 +172,18 @@ impl Contest {
-> Self
{
Contest { id: None,
location: location,
filename: filename,
name: name,
duration: duration,
public: public,
start: start,
end: end,
min_grade: min_grade,
max_grade: max_grade,
positionalnumber: positionalnumber,
requires_login: requires_login,
secret: secret,
location,
filename,
name,
duration,
public,
start,
end,
min_grade,
max_grade,
positionalnumber,
requires_login,
secret,
taskgroups: Vec::new() }
}
}
......@@ -191,9 +191,9 @@ impl Contest {
impl SessionUser {
pub fn minimal(id: i32, session_token: String, csrf_token: String) -> Self {
SessionUser {
id: id,
id,
session_token: Some(session_token),
csrf_token: csrf_token,
csrf_token,
last_login: None,
last_activity: None, // now?
// müssen die überhaupt außerhalb der datenbankabstraktion sichtbar sein?
......@@ -317,16 +317,16 @@ impl Taskgroup {
pub fn new(name: String, positionalnumber: Option<i32>) -> Self {
Taskgroup { id: None,
contest: 0,
name: name,
name,
active: true,
positionalnumber: positionalnumber,
positionalnumber,
tasks: Vec::new() }
}
}
impl Task {
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 {
let mut config = config::read_config_from_file(Path::new("thisfileshoudnotexist"));
config.port = Some(port);
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
start_tx.send(()).unwrap();
......@@ -396,14 +397,12 @@ mod tests {
fn login(port: u16, client: &reqwest::Client, username: &str, password: &str) -> reqwest::Response {
let params = [("username", username), ("password", password)];
let resp = client.post(&format!("http://localhost:{}/login", port)).form(&params).send().unwrap();
resp
client.post(&format!("http://localhost:{}/login", port)).form(&params).send().unwrap()
}
fn login_code(port: u16, client: &reqwest::Client, code: &str) -> reqwest::Response {
let params = [("code", code)];
let resp = client.post(&format!("http://localhost:{}/clogin", port)).form(&params).send().unwrap();
resp
client.post(&format!("http://localhost:{}/clogin", port)).form(&params).send().unwrap()
}
#[test]
......
......@@ -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];
match result {
Ok(data) => Ok(Response::with((status::Ok, mime!(Application / Json), format!("{}", data)))),
Err(_) => Ok(Response::with((status::BadRequest, mime!(Application / Json), format!("{{}}")))),
Ok(data) => Ok(Response::with((status::Ok, mime!(Application / Json), data.to_string()))),
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