Skip to content

Commit 8fb4001

Browse files
917: Add lints to require Debug and Copy on all types that can be r=sgrif @sgrif I thought you had said that the lint would know if it wasn't possible to derive Debug.... that doesn't appear to be the case 😢 Soo I'm allowing it in places!
2 parents 1f8c2ef + 9f47965 commit 8fb4001

20 files changed

+45
-16
lines changed

src/app.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use {db, Config};
1616

1717
/// The `App` struct holds the main components of the application like
1818
/// the database connection pool and configurations
19+
// The db, oauth, and git2 types don't implement debug.
20+
#[allow(missing_debug_implementations)]
1921
pub struct App {
2022
/// The database connection pool
2123
pub database: db::Pool,
@@ -40,6 +42,8 @@ pub struct App {
4042
}
4143

4244
/// The `AppMiddleware` injects an `App` instance into the `Request` extensions
45+
// Can't derive Debug because `App` can't.
46+
#[allow(missing_debug_implementations)]
4347
pub struct AppMiddleware {
4448
app: Arc<App>,
4549
}

src/badge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub enum Badge {
4242
Maintenance { value: MaintenanceValue },
4343
}
4444

45-
#[derive(Debug, PartialEq, Clone, Deserialize, Serialize)]
45+
#[derive(Debug, PartialEq, Clone, Copy, Deserialize, Serialize)]
4646
#[serde(rename_all = "kebab-case")]
4747
pub enum MaintenanceValue {
4848
ActivelyDeveloped,
@@ -81,7 +81,7 @@ impl Badge {
8181
) -> QueryResult<Vec<&'a str>> {
8282
use diesel::{insert, delete};
8383

84-
#[derive(Insertable)]
84+
#[derive(Insertable, Debug)]
8585
#[table_name = "badges"]
8686
struct NewBadge<'a> {
8787
crate_id: i32,

src/category.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Category {
2222
pub created_at: Timespec,
2323
}
2424

25-
#[derive(Associations, Insertable, Identifiable, Debug)]
25+
#[derive(Associations, Insertable, Identifiable, Debug, Clone, Copy)]
2626
#[belongs_to(Category)]
2727
#[belongs_to(Crate)]
2828
#[table_name = "crates_categories"]

src/db.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,11 @@ pub fn diesel_pool(
128128
r2d2::Pool::new(config, manager).unwrap()
129129
}
130130

131+
#[derive(Clone, Copy, Debug)]
131132
pub struct TransactionMiddleware;
132133

134+
// Can't derive Debug because of LazyCell and App.
135+
#[allow(missing_debug_implementations)]
133136
pub struct Transaction {
134137
// fields are destructed top-to-bottom so ensure we destroy them in the
135138
// right order.

src/dist.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use conduit_middleware::AroundMiddleware;
66

77
use util::RequestProxy;
88

9+
// Can't derive debug because of Handler and Static.
10+
#[allow(missing_debug_implementations)]
911
pub struct Middleware {
1012
handler: Option<Box<Handler>>,
1113
dist: Static,

src/download.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use Model;
88
use schema::version_downloads;
99
use version::Version;
1010

11-
#[derive(Queryable, Identifiable, Associations, Debug)]
11+
#[derive(Queryable, Identifiable, Associations, Debug, Clone, Copy)]
1212
#[belongs_to(Version)]
1313
pub struct VersionDownload {
1414
pub id: i32,
@@ -19,7 +19,7 @@ pub struct VersionDownload {
1919
pub processed: bool,
2020
}
2121

22-
#[derive(Insertable, Debug)]
22+
#[derive(Insertable, Debug, Clone, Copy)]
2323
#[table_name = "version_downloads"]
2424
struct NewVersionDownload(
2525
#[column_name(version_id)]

src/keyword.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct Keyword {
2222
pub created_at: Timespec,
2323
}
2424

25-
#[derive(Associations, Insertable, Identifiable, Debug)]
25+
#[derive(Associations, Insertable, Identifiable, Debug, Clone, Copy)]
2626
#[belongs_to(Keyword)]
2727
#[belongs_to(Crate)]
2828
#[table_name = "crates_keywords"]
@@ -51,7 +51,7 @@ impl Keyword {
5151
use diesel::pg::upsert::*;
5252
use diesel::expression::dsl::any;
5353

54-
#[derive(Insertable)]
54+
#[derive(Insertable, Debug, Clone, Copy)]
5555
#[table_name = "keywords"]
5656
struct NewKeyword<'a> {
5757
keyword: &'a str,
@@ -198,7 +198,7 @@ mod tests {
198198
use diesel;
199199
use diesel::connection::SimpleConnection;
200200

201-
#[derive(Insertable)]
201+
#[derive(Insertable, Debug, Clone, Copy)]
202202
#[table_name = "keywords"]
203203
struct NewKeyword<'a> {
204204
keyword: &'a str,

src/krate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use {Model, User, Keyword, Version, Category, Badge, Replica};
4444
/// and are possibly of malicious intent e.g. ad tracking networks, etc.
4545
const DOCUMENTATION_BLACKLIST: [&'static str; 1] = ["rust-ci.org"];
4646

47-
#[derive(Debug, Insertable, Queryable, Identifiable, Associations, AsChangeset)]
47+
#[derive(Debug, Insertable, Queryable, Identifiable, Associations, AsChangeset, Clone, Copy)]
4848
#[belongs_to(Crate)]
4949
#[primary_key(crate_id, date)]
5050
#[table_name = "crate_downloads"]
@@ -1381,7 +1381,7 @@ pub fn downloads(req: &mut Request) -> CargoResult<Response> {
13811381
}))
13821382
}
13831383

1384-
#[derive(Insertable, Queryable, Identifiable, Associations)]
1384+
#[derive(Insertable, Queryable, Identifiable, Associations, Clone, Copy, Debug)]
13851385
#[belongs_to(User)]
13861386
#[primary_key(user_id, crate_id)]
13871387
#[table_name = "follows"]

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! [krate](krate/index.html), [user](user/index.html) and [version](version/index.html) modules.
66
77
#![deny(warnings)]
8+
#![deny(missing_debug_implementations, missing_copy_implementations)]
89
#![cfg_attr(feature = "clippy", feature(plugin))]
910
#![cfg_attr(feature = "clippy", plugin(clippy))]
1011

src/owner.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use schema::*;
88
use util::{CargoResult, human};
99
use {Model, User, Crate};
1010

11-
#[derive(Insertable, Associations, Identifiable, Debug)]
11+
#[derive(Insertable, Associations, Identifiable, Debug, Clone, Copy)]
1212
#[belongs_to(Crate)]
1313
#[belongs_to(User, foreign_key = "owner_id")]
1414
#[belongs_to(Team, foreign_key = "owner_id")]
@@ -21,7 +21,7 @@ pub struct CrateOwner {
2121
pub owner_kind: i32,
2222
}
2323

24-
#[derive(Debug)]
24+
#[derive(Debug, Clone, Copy)]
2525
#[repr(u32)]
2626
pub enum OwnerKind {
2727
User = 0,
@@ -74,7 +74,7 @@ pub struct EncodableOwner {
7474

7575
/// Access rights to the crate (publishing and ownership management)
7676
/// NOTE: The order of these variants matters!
77-
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug)]
77+
#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)]
7878
pub enum Rights {
7979
None,
8080
Publish,

src/token.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct ApiToken {
2323
}
2424

2525
/// The serialization format for the `ApiToken` model without its token value.
26-
#[derive(Deserialize, Serialize)]
26+
#[derive(Deserialize, Serialize, Debug)]
2727
pub struct EncodableApiToken {
2828
pub id: i32,
2929
pub name: String,
@@ -34,7 +34,7 @@ pub struct EncodableApiToken {
3434
/// The serialization format for the `ApiToken` model with its token value.
3535
/// This should only be used when initially creating a new token to minimize
3636
/// the chance of token leaks.
37-
#[derive(Deserialize, Serialize)]
37+
#[derive(Deserialize, Serialize, Debug)]
3838
pub struct EncodableApiTokenWithToken {
3939
pub id: i32,
4040
pub name: String,
@@ -47,7 +47,7 @@ impl ApiToken {
4747
/// Generates a new named API token for a user
4848
pub fn insert(conn: &PgConnection, user_id: i32, name: &str) -> QueryResult<ApiToken> {
4949
#[table_name = "api_tokens"]
50-
#[derive(Insertable, AsChangeset)]
50+
#[derive(Insertable, AsChangeset, Debug)]
5151
struct NewApiToken<'a> {
5252
user_id: i32,
5353
name: &'a str,

src/uploaders.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ impl Uploader {
169169
}
170170
}
171171

172+
// Can't derive Debug because of App.
173+
#[allow(missing_debug_implementations)]
172174
pub struct Bomb {
173175
app: Arc<App>,
174176
pub path: Option<String>,

src/user/middleware.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use db::RequestTransaction;
99
use super::User;
1010
use util::errors::{CargoResult, Unauthorized, ChainError, std_error};
1111

12+
#[derive(Debug, Clone, Copy)]
1213
pub struct Middleware;
1314

1415
#[derive(Debug, Copy, Clone, Eq, PartialEq)]

src/util/errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ impl CargoError for ConcreteCargoError {
223223
}
224224
}
225225

226+
#[derive(Debug, Clone, Copy)]
226227
pub struct NotFound;
227228

228229
impl CargoError for NotFound {
@@ -245,6 +246,7 @@ impl fmt::Display for NotFound {
245246
}
246247
}
247248

249+
#[derive(Debug, Clone, Copy)]
248250
pub struct Unauthorized;
249251

250252
impl CargoError for Unauthorized {

src/util/hasher.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::io::prelude::*;
22
use std::io;
33
use openssl::hash::{Hasher, MessageDigest};
44

5+
// Can't derive debug because of Hasher.
6+
#[allow(missing_debug_implementations)]
57
pub struct HashingReader<R> {
68
inner: R,
79
hasher: Hasher,

src/util/head.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use conduit_middleware::AroundMiddleware;
66

77
use util::RequestProxy;
88

9+
// Can't derive debug because of Handler.
10+
#[allow(missing_debug_implementations)]
911
#[derive(Default)]
1012
pub struct Head {
1113
handler: Option<Box<Handler>>,

src/util/io_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::io::prelude::*;
22
use std::io;
33
use std::mem;
44

5+
#[derive(Debug)]
56
pub struct LimitErrorReader<R> {
67
inner: io::Take<R>,
78
}

src/util/lazy_cell.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use std::cell::RefCell;
1212
use std::mem;
1313

14+
// Don't want to only be able to store T: Debug things.
15+
#[allow(missing_debug_implementations)]
1416
pub struct LazyCell<T> {
1517
inner: RefCell<Option<T>>,
1618
}

src/util/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ impl<'a> RequestUtils for Request + 'a {
102102
}
103103
}
104104

105+
// Can't Copy or Debug the fn.
106+
#[allow(missing_debug_implementations, missing_copy_implementations)]
105107
pub struct C(pub fn(&mut Request) -> CargoResult<Response>);
106108

107109
impl Handler for C {
@@ -122,6 +124,7 @@ impl Handler for C {
122124
}
123125
}
124126

127+
#[derive(Debug)]
125128
pub struct R<H>(pub Arc<H>);
126129

127130
impl<H: Handler> Handler for R<H> {
@@ -136,6 +139,8 @@ impl<H: Handler> Handler for R<H> {
136139
}
137140
}
138141

142+
// Can't derive Debug because of RouteBuilder.
143+
#[allow(missing_debug_implementations)]
139144
pub struct R404(pub RouteBuilder);
140145

141146
impl Handler for R404 {

src/util/request_proxy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use conduit;
55
use conduit::Request;
66
use semver;
77

8+
// Can't derive Debug because of Request.
9+
#[allow(missing_debug_implementations)]
810
pub struct RequestProxy<'a> {
911
pub other: &'a mut (Request + 'a),
1012
pub path: Option<&'a str>,

0 commit comments

Comments
 (0)