Skip to content

Enable Rust 2018 Edition #1571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.2.2"
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/crates.io"
description = "Backend of crates.io"
edition = "2018"

[workspace]

Expand Down
4 changes: 0 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
extern crate diesel;
extern crate diesel_migrations;
extern crate dotenv;

use diesel::prelude::*;
use diesel_migrations::run_pending_migrations;
use dotenv::dotenv;
Expand Down
17 changes: 7 additions & 10 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
//! Application-wide components in a struct accessible from each request

use std::env;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::time::Duration;
use crate::{db, util::CargoResult, Config, Env};
use std::{
env,
path::PathBuf,
sync::{Arc, Mutex},
time::Duration,
};

use diesel::r2d2;
use git2;
use oauth2;
use reqwest;
use scheduled_thread_pool::ScheduledThreadPool;

use util::CargoResult;
use {db, Config, Env};

/// The `App` struct holds the main components of the application like
/// the database connection pool and configurations
// The db, oauth, and git2 types don't implement debug.
Expand Down
15 changes: 6 additions & 9 deletions src/bin/delete-crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@

#![deny(warnings)]

extern crate cargo_registry;
extern crate diesel;
use cargo_registry::{db, models::Crate, schema::crates};
use std::{
env,
io::{self, prelude::*},
};

use diesel::prelude::*;
use std::env;
use std::io;
use std::io::prelude::*;

use cargo_registry::models::Crate;
use cargo_registry::schema::crates;

fn main() {
let conn = cargo_registry::db::connect_now().unwrap();
let conn = db::connect_now().unwrap();
conn.transaction::<_, diesel::result::Error, _>(|| {
delete(&conn);
Ok(())
Expand Down
19 changes: 10 additions & 9 deletions src/bin/delete-version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@

#![deny(warnings)]

extern crate cargo_registry;
extern crate diesel;
use cargo_registry::{
db,
models::{Crate, Version},
schema::versions,
};
use std::{
env,
io::{self, prelude::*},
};

use diesel::prelude::*;
use std::env;
use std::io;
use std::io::prelude::*;

use cargo_registry::models::{Crate, Version};
use cargo_registry::schema::versions;

fn main() {
let conn = cargo_registry::db::connect_now().unwrap();
let conn = db::connect_now().unwrap();
conn.transaction::<_, diesel::result::Error, _>(|| {
delete(&conn);
Ok(())
Expand Down
7 changes: 2 additions & 5 deletions src/bin/on_call/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
extern crate cargo_registry;
extern crate reqwest;

use self::reqwest::{header, StatusCode as Status};
use cargo_registry::util::{internal, CargoResult};
use std::env;

use self::cargo_registry::util::*;
use reqwest::{header, StatusCode as Status};

#[derive(Serialize, Debug)]
#[serde(rename_all = "snake_case", tag = "event_type")]
Expand Down
10 changes: 3 additions & 7 deletions src/bin/populate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@

#![deny(warnings)]

extern crate cargo_registry;
extern crate diesel;
extern crate rand;
use cargo_registry::{db, schema::version_downloads};
use std::env;

use diesel::prelude::*;
use rand::{Rng, StdRng};
use std::env;

use cargo_registry::schema::version_downloads;

fn main() {
let conn = cargo_registry::db::connect_now().unwrap();
let conn = db::connect_now().unwrap();
conn.transaction(|| update(&conn)).unwrap();
}

Expand Down
33 changes: 11 additions & 22 deletions src/bin/render-readmes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,21 @@
#[macro_use]
extern crate serde_derive;

extern crate cargo_registry;
extern crate chrono;
extern crate diesel;
extern crate docopt;
extern crate flate2;
extern crate itertools;
extern crate reqwest;
extern crate tar;
extern crate toml;
use cargo_registry::{
db,
models::Version,
render::readme_to_html,
schema::{crates, readme_renderings, versions},
Config,
};
use std::{io::Read, path::Path, thread};

use chrono::{TimeZone, Utc};
use diesel::dsl::any;
use diesel::prelude::*;
use diesel::{dsl::any, prelude::*};
use docopt::Docopt;
use flate2::read::GzDecoder;
use itertools::Itertools;
use std::io::Read;
use std::path::Path;
use std::thread;
use tar::Archive;

use cargo_registry::render::readme_to_html;
use cargo_registry::Config;

use cargo_registry::models::Version;
use cargo_registry::schema::*;
use tar::{self, Archive};

const DEFAULT_PAGE_SIZE: usize = 25;
const USAGE: &str = "
Expand All @@ -59,7 +48,7 @@ fn main() {
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
let config = Config::default();
let conn = cargo_registry::db::connect_now().unwrap();
let conn = db::connect_now().unwrap();

let start_time = Utc::now();

Expand Down
25 changes: 11 additions & 14 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
#![deny(warnings)]

extern crate cargo_registry;
extern crate civet;
extern crate env_logger;
extern crate git2;
use cargo_registry::{boot, build_handler, env, git, App, Config, Env};
use std::{
env,
fs::{self, File},
sync::{mpsc::channel, Arc},
};

use cargo_registry::{env, Env};
use civet::Server;
use std::env;
use std::fs::{self, File};
use std::sync::mpsc::channel;
use std::sync::Arc;

fn main() {
// Initialize logging
env_logger::init();
let config = cargo_registry::Config::default();
let config = Config::default();

// If there isn't a git checkout containing the crate index repo at the path specified
// by `GIT_REPO_CHECKOUT`, delete that directory and clone the repo specified by `GIT_REPO_URL`
Expand All @@ -28,7 +25,7 @@ fn main() {
let _ = fs::remove_dir_all(&config.git_repo_checkout);
fs::create_dir_all(&config.git_repo_checkout).unwrap();
let mut cb = git2::RemoteCallbacks::new();
cb.credentials(cargo_registry::git::credentials);
cb.credentials(git::credentials);
let mut opts = git2::FetchOptions::new();
opts.remote_callbacks(cb);
git2::build::RepoBuilder::new()
Expand All @@ -44,13 +41,13 @@ fn main() {
cfg.set_str("user.name", "bors").unwrap();
cfg.set_str("user.email", "[email protected]").unwrap();

let app = cargo_registry::App::new(&config);
let app = cargo_registry::build_handler(Arc::new(app));
let app = App::new(&config);
let app = build_handler(Arc::new(app));

// On every server restart, ensure the categories available in the database match
// the information in *src/categories.toml*.
let categories_toml = include_str!("../boot/categories.toml");
cargo_registry::boot::categories::sync(categories_toml).unwrap();
boot::categories::sync(categories_toml).unwrap();

let heroku = env::var("HEROKU").is_ok();
let port = if heroku {
Expand Down
22 changes: 12 additions & 10 deletions src/bin/transfer-crates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@

#![deny(warnings)]

extern crate cargo_registry;
extern crate diesel;
use cargo_registry::{
db,
models::{Crate, OwnerKind, User},
schema::{crate_owners, crates, users},
};
use std::{
env,
io::{self, prelude::*},
process::exit,
};

use diesel::prelude::*;
use std::env;
use std::io;
use std::io::prelude::*;

use cargo_registry::models::{Crate, OwnerKind, User};
use cargo_registry::schema::*;

fn main() {
let conn = cargo_registry::db::connect_now().unwrap();
let conn = db::connect_now().unwrap();
conn.transaction::<_, diesel::result::Error, _>(|| {
transfer(&conn);
Ok(())
Expand Down Expand Up @@ -97,6 +99,6 @@ fn get_confirm(msg: &str) {
let mut line = String::new();
io::stdin().read_line(&mut line).unwrap();
if !line.starts_with('y') {
std::process::exit(0);
exit(0);
}
}
Loading