Skip to content

Commit 1d7b9a3

Browse files
committed
Don't error on long lines rustfmt can't handle; change width to 100
1 parent 080599a commit 1d7b9a3

File tree

15 files changed

+133
-35
lines changed

15 files changed

+133
-35
lines changed

.rustfmt.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ generics_indent = "Block"
66
fn_call_style = "Block"
77
combine_control_expr = true
88
fn_args_paren_newline = false
9-
max_width = 118
9+
max_width = 100
10+
error_on_line_overflow = false

build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ fn main() {
1111
if env::var("PROFILE") == Ok("debug".into()) {
1212
let _ = dotenv();
1313
if let Ok(database_url) = env::var("TEST_DATABASE_URL") {
14-
let connection = PgConnection::establish(&database_url).expect("Could not connect to TEST_DATABASE_URL");
14+
let connection = PgConnection::establish(&database_url).expect(
15+
"Could not connect to TEST_DATABASE_URL",
16+
);
1517
run_pending_migrations(&connection).expect("Error running migrations");
1618
}
1719
}

src/bin/update-downloads.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ mod test {
161161
use cargo_registry::{Version, Crate, User, Model, env};
162162

163163
fn conn() -> postgres::Connection {
164-
postgres::Connection::connect(&env("TEST_DATABASE_URL")[..], postgres::TlsMode::None).unwrap()
164+
postgres::Connection::connect(&env("TEST_DATABASE_URL")[..], postgres::TlsMode::None)
165+
.unwrap()
165166
}
166167

167168
fn user(conn: &postgres::transaction::Transaction) -> User {

src/categories.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ struct Category {
1313
}
1414

1515
impl Category {
16-
fn from_parent(slug: &str, name: &str, description: &str, parent: Option<&Category>) -> Category {
16+
fn from_parent(
17+
slug: &str,
18+
name: &str,
19+
description: &str,
20+
parent: Option<&Category>,
21+
) -> Category {
1722
match parent {
1823
Some(parent) => {
1924
Category {
@@ -46,7 +51,10 @@ fn optional_string_from_toml<'a>(toml: &'a toml::Table, key: &str) -> &'a str {
4651
toml.get(key).and_then(toml::Value::as_str).unwrap_or("")
4752
}
4853

49-
fn categories_from_toml(categories: &toml::Table, parent: Option<&Category>) -> CargoResult<Vec<Category>> {
54+
fn categories_from_toml(
55+
categories: &toml::Table,
56+
parent: Option<&Category>,
57+
) -> CargoResult<Vec<Category>> {
5058
let mut result = vec![];
5159

5260
for (slug, details) in categories {
@@ -87,7 +95,8 @@ pub fn sync() -> CargoResult<()> {
8795
"Could not parse categories.toml",
8896
);
8997

90-
let categories = categories_from_toml(&toml, None).expect("Could not convert categories from TOML");
98+
let categories =
99+
categories_from_toml(&toml, None).expect("Could not convert categories from TOML");
91100

92101
for category in &categories {
93102
tx.execute(

src/category.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ impl Category {
9898
}
9999
}
100100

101-
pub fn update_crate<'a>(conn: &PgConnection, krate: &Crate, slugs: &[&'a str]) -> QueryResult<Vec<&'a str>> {
101+
pub fn update_crate<'a>(
102+
conn: &PgConnection,
103+
krate: &Crate,
104+
slugs: &[&'a str],
105+
) -> QueryResult<Vec<&'a str>> {
102106
use diesel::expression::dsl::any;
103107

104108
conn.transaction(|| {
@@ -202,7 +206,12 @@ impl Category {
202206
Ok(rows.iter().next().unwrap().get("count"))
203207
}
204208

205-
pub fn toplevel(conn: &PgConnection, sort: &str, limit: i64, offset: i64) -> QueryResult<Vec<Category>> {
209+
pub fn toplevel(
210+
conn: &PgConnection,
211+
sort: &str,
212+
limit: i64,
213+
offset: i64,
214+
) -> QueryResult<Vec<Category>> {
206215
use diesel::select;
207216
use diesel::expression::dsl::*;
208217

@@ -227,7 +236,12 @@ impl Category {
227236
))).load(conn)
228237
}
229238

230-
pub fn toplevel_old(conn: &GenericConnection, sort: &str, limit: i64, offset: i64) -> CargoResult<Vec<Category>> {
239+
pub fn toplevel_old(
240+
conn: &GenericConnection,
241+
sort: &str,
242+
limit: i64,
243+
offset: i64,
244+
) -> CargoResult<Vec<Category>> {
231245

232246
let sort_sql = match sort {
233247
"crates" => "ORDER BY crates_cnt DESC",
@@ -413,7 +427,8 @@ mod tests {
413427

414428
fn pg_connection() -> PgConnection {
415429
let _ = dotenv();
416-
let database_url = env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests");
430+
let database_url =
431+
env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests");
417432
let conn = PgConnection::establish(&database_url).unwrap();
418433
// These tests deadlock if run concurrently
419434
conn.batch_execute("BEGIN; LOCK categories IN ACCESS EXCLUSIVE MODE")

src/db.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ pub fn tls_handshake() -> Box<TlsHandshake + Sync + Send> {
5959
// better solution in the future for certificate verification...
6060

6161
impl TlsHandshake for MyHandshake {
62-
fn tls_handshake(&self, _domain: &str, stream: Stream) -> Result<Box<TlsStream>, Box<Error + Send + Sync>> {
62+
fn tls_handshake(
63+
&self,
64+
_domain: &str,
65+
stream: Stream,
66+
) -> Result<Box<TlsStream>, Box<Error + Send + Sync>> {
6367
let stream = self.0
6468
.danger_connect_without_providing_domain_for_certificate_verification_and_server_name_indication(
6569
stream,
@@ -102,7 +106,10 @@ pub fn pool(url: &str, config: r2d2::Config<postgres::Connection, r2d2_postgres:
102106
r2d2::Pool::new(config, mgr).unwrap()
103107
}
104108

105-
pub fn diesel_pool(url: &str, config: r2d2::Config<PgConnection, r2d2_diesel::Error>) -> DieselPool {
109+
pub fn diesel_pool(
110+
url: &str,
111+
config: r2d2::Config<PgConnection, r2d2_diesel::Error>,
112+
) -> DieselPool {
106113
let mut url = Url::parse(url).expect("Invalid database URL");
107114
if env::var("HEROKU").is_ok() && !url.query_pairs().any(|(k, _)| k == "sslmode") {
108115
url.query_pairs_mut().append_pair("sslmode", "require");
@@ -142,7 +149,9 @@ impl Transaction {
142149
}
143150
}
144151

145-
pub fn conn(&self) -> CargoResult<&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>> {
152+
pub fn conn(
153+
&self,
154+
) -> CargoResult<&r2d2::PooledConnection<r2d2_postgres::PostgresConnectionManager>> {
146155
if !self.slot.filled() {
147156
let conn = self.app.database.get().map_err(|e| {
148157
internal(&format_args!("failed to get a database connection: {}", e))

src/dependency.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ pub fn add_dependencies(
180180
})
181181
.collect::<Result<Vec<_>, _>>()?;
182182

183-
let (git_deps, new_dependencies): (Vec<_>, Vec<_>) = git_and_new_dependencies.into_iter().unzip();
183+
let (git_deps, new_dependencies): (Vec<_>, Vec<_>) =
184+
git_and_new_dependencies.into_iter().unzip();
184185

185186
insert(&new_dependencies)
186187
.into(dependencies::table)

src/krate.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,13 @@ impl Crate {
625625
Ok(owners)
626626
}
627627

628-
pub fn owner_add(&self, app: &App, conn: &PgConnection, req_user: &User, login: &str) -> CargoResult<()> {
628+
pub fn owner_add(
629+
&self,
630+
app: &App,
631+
conn: &PgConnection,
632+
req_user: &User,
633+
login: &str,
634+
) -> CargoResult<()> {
629635
let owner = match Owner::find_by_login(conn, login) {
630636
Ok(owner @ Owner::User(_)) => owner,
631637
Ok(Owner::Team(team)) => {
@@ -663,7 +669,12 @@ impl Crate {
663669
Ok(())
664670
}
665671

666-
pub fn owner_remove(&self, conn: &PgConnection, _req_user: &User, login: &str) -> CargoResult<()> {
672+
pub fn owner_remove(
673+
&self,
674+
conn: &PgConnection,
675+
_req_user: &User,
676+
login: &str,
677+
) -> CargoResult<()> {
667678
let owner = Owner::find_by_login(conn, login).map_err(|_| {
668679
human(&format_args!("could not find owner with login `{}`", login))
669680
})?;

src/owner.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ pub enum Rights {
7474

7575
impl Team {
7676
/// Tries to create the Team in the DB (assumes a `:` has already been found).
77-
pub fn create(app: &App, conn: &PgConnection, login: &str, req_user: &User) -> CargoResult<Self> {
77+
pub fn create(
78+
app: &App,
79+
conn: &PgConnection,
80+
login: &str,
81+
req_user: &User,
82+
) -> CargoResult<Self> {
7883
// must look like system:xxxxxxx
7984
let mut chunks = login.split(':');
8085
match chunks.next().unwrap() {

src/tests/all.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,12 @@ fn new_dependency(conn: &PgConnection, version: &Version, krate: &Crate) -> Depe
409409
.unwrap()
410410
}
411411

412-
fn mock_dep(req: &mut Request, version: &Version, krate: &Crate, target: Option<&str>) -> Dependency {
412+
fn mock_dep(
413+
req: &mut Request,
414+
version: &Version,
415+
krate: &Crate,
416+
target: Option<&str>,
417+
) -> Dependency {
413418
Dependency::insert(
414419
req.tx().unwrap(),
415420
version.id,
@@ -462,7 +467,12 @@ fn new_req(app: Arc<App>, krate: &str, version: &str) -> MockRequest {
462467
new_req_full(app, ::krate(krate), version, Vec::new())
463468
}
464469

465-
fn new_req_full(app: Arc<App>, krate: Crate, version: &str, deps: Vec<u::CrateDependency>) -> MockRequest {
470+
fn new_req_full(
471+
app: Arc<App>,
472+
krate: Crate,
473+
version: &str,
474+
deps: Vec<u::CrateDependency>,
475+
) -> MockRequest {
466476
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
467477
req.with_body(&new_req_body(
468478
krate,
@@ -475,7 +485,12 @@ fn new_req_full(app: Arc<App>, krate: Crate, version: &str, deps: Vec<u::CrateDe
475485
return req;
476486
}
477487

478-
fn new_req_with_keywords(app: Arc<App>, krate: Crate, version: &str, kws: Vec<String>) -> MockRequest {
488+
fn new_req_with_keywords(
489+
app: Arc<App>,
490+
krate: Crate,
491+
version: &str,
492+
kws: Vec<String>,
493+
) -> MockRequest {
479494
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
480495
req.with_body(&new_req_body(
481496
krate,
@@ -488,7 +503,12 @@ fn new_req_with_keywords(app: Arc<App>, krate: Crate, version: &str, kws: Vec<St
488503
return req;
489504
}
490505

491-
fn new_req_with_categories(app: Arc<App>, krate: Crate, version: &str, cats: Vec<String>) -> MockRequest {
506+
fn new_req_with_categories(
507+
app: Arc<App>,
508+
krate: Crate,
509+
version: &str,
510+
cats: Vec<String>,
511+
) -> MockRequest {
492512
let mut req = ::req(app, Method::Put, "/api/v1/crates/new");
493513
req.with_body(&new_req_body(
494514
krate,

src/tests/badge.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ fn set_up() -> (Arc<App>, Crate, BadgeRef) {
6464
String::from("rust-lang/rust"),
6565
);
6666

67-
let isitmaintained_open_issues = Badge::IsItMaintainedOpenIssues { repository: String::from("rust-lang/rust") };
67+
let isitmaintained_open_issues =
68+
Badge::IsItMaintainedOpenIssues { repository: String::from("rust-lang/rust") };
6869
let mut badge_attributes_isitmaintained_open_issues = HashMap::new();
69-
badge_attributes_isitmaintained_open_issues.insert(String::from("repository"), String::from("rust-lang/rust"));
70+
badge_attributes_isitmaintained_open_issues.insert(
71+
String::from(
72+
"repository",
73+
),
74+
String::from(
75+
"rust-lang/rust",
76+
),
77+
);
7078

7179
let codecov = Badge::Codecov {
7280
service: Some(String::from("github")),
@@ -96,7 +104,8 @@ fn set_up() -> (Arc<App>, Crate, BadgeRef) {
96104
gitlab: gitlab,
97105
gitlab_attributes: badge_attributes_gitlab,
98106
isitmaintained_issue_resolution: isitmaintained_issue_resolution,
99-
isitmaintained_issue_resolution_attributes: badge_attributes_isitmaintained_issue_resolution,
107+
isitmaintained_issue_resolution_attributes:
108+
badge_attributes_isitmaintained_issue_resolution,
100109
isitmaintained_open_issues: isitmaintained_open_issues,
101110
isitmaintained_open_issues_attributes: badge_attributes_isitmaintained_open_issues,
102111
codecov: codecov,

src/tests/team.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ fn body_for_team_x() -> &'static str {
3737
#[test]
3838
fn not_github() {
3939
let (_b, app, middle) = ::app();
40-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_not_github");
40+
let mut req =
41+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_not_github");
4142

4243
let body = r#"{"users":["dropbox:foo:foo"]}"#;
4344
let json = bad_resp!(
@@ -57,7 +58,8 @@ fn not_github() {
5758
#[test]
5859
fn weird_name() {
5960
let (_b, app, middle) = ::app();
60-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_weird_name");
61+
let mut req =
62+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_weird_name");
6163

6264
let body = r#"{"users":["github:foo/../bar:wut"]}"#;
6365
let json = bad_resp!(
@@ -100,7 +102,8 @@ fn one_colon() {
100102
#[test]
101103
fn nonexistent_team() {
102104
let (_b, app, middle) = ::app();
103-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_nonexistent");
105+
let mut req =
106+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_nonexistent");
104107

105108
let body = r#"{"users":["github:crates-test-org:this-does-not-exist"]}"#;
106109
let json = bad_resp!(
@@ -123,7 +126,8 @@ fn nonexistent_team() {
123126
#[test]
124127
fn add_team_as_member() {
125128
let (_b, app, middle) = ::app();
126-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_team_member");
129+
let mut req =
130+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_team_member");
127131

128132
let body = body_for_team_x();
129133
ok_resp!(
@@ -139,7 +143,8 @@ fn add_team_as_member() {
139143
#[test]
140144
fn add_team_as_non_member() {
141145
let (_b, app, middle) = ::app();
142-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_only_x(), "foo_team_non_member");
146+
let mut req =
147+
::request_with_user_and_mock_crate(&app, mock_user_on_only_x(), "foo_team_non_member");
143148

144149
let body = body_for_team_y();
145150
let json = bad_resp!(
@@ -159,7 +164,8 @@ fn add_team_as_non_member() {
159164
#[test]
160165
fn remove_team_as_named_owner() {
161166
let (_b, app, middle) = ::app();
162-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_remove_team");
167+
let mut req =
168+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_remove_team");
163169

164170
let body = body_for_team_x();
165171
ok_resp!(
@@ -202,7 +208,8 @@ fn remove_team_as_named_owner() {
202208
#[test]
203209
fn remove_team_as_team_owner() {
204210
let (_b, app, middle) = ::app();
205-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_remove_team_owner");
211+
let mut req =
212+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_remove_team_owner");
206213

207214
let body = body_for_team_x();
208215
ok_resp!(
@@ -283,7 +290,8 @@ fn publish_not_owned() {
283290
#[test]
284291
fn publish_owned() {
285292
let (_b, app, middle) = ::app();
286-
let mut req = ::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_team_owned");
293+
let mut req =
294+
::request_with_user_and_mock_crate(&app, mock_user_on_x_and_y(), "foo_team_owned");
287295

288296
let body = body_for_team_x();
289297
ok_resp!(

src/user/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ mod tests {
429429

430430
fn connection() -> PgConnection {
431431
let _ = dotenv();
432-
let database_url = env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests");
432+
let database_url =
433+
env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests");
433434
let conn = PgConnection::establish(&database_url).unwrap();
434435
conn.begin_test_transaction().unwrap();
435436
conn

src/util/errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ impl CargoError for Unauthorized {
255255
fn response(&self) -> Option<Response> {
256256
let mut response = json_response(&Bad {
257257
errors: vec![
258-
StringError { detail: "must be logged in to perform that action".to_string() },
258+
StringError {
259+
detail: "must be logged in to perform that action".to_string(),
260+
},
259261
],
260262
});
261263
response.status = (403, "Forbidden");

0 commit comments

Comments
 (0)