Skip to content

Commit

Permalink
Use workspace lints. Resolve new nightly warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed May 20, 2024
1 parent bb48a4d commit 3079dbf
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 66 deletions.
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,18 @@ members = [
"contrib/ws/",
"docs/tests",
]

[workspace.lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(nightly)'] }
rust_2018_idioms = "warn"
async_fn_in_trait = "allow"
refining_impl_trait = "allow"
# unreachable_pub = "warn"
# single_use_lifetimes = "warn"
# missing_docs = "warn"

[workspace.lints.clippy]
type_complexity = "allow"
module_inception = "allow"
multiple_bound_locations = "allow"
manual_range_contains = "allow"
3 changes: 3 additions & 0 deletions contrib/db_pools/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rust-version = "1.75"
[lib]
proc-macro = true

[lints]
workspace = true

[dependencies]
devise = "0.4"
quote = "1"
Expand Down
3 changes: 3 additions & 0 deletions contrib/db_pools/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rust-version = "1.75"
[package.metadata.docs.rs]
all-features = true

[lints]
workspace = true

[features]
# deadpool features
deadpool_postgres = ["deadpool-postgres", "deadpool"]
Expand Down
5 changes: 2 additions & 3 deletions contrib/dyn_templates/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.75"

[lints.clippy]
type_complexity = "allow"
multiple_bound_locations = "allow"
[lints]
workspace = true

[features]
tera = ["dep:tera"]
Expand Down
3 changes: 3 additions & 0 deletions contrib/sync_db_pools/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ rust-version = "1.75"
[lib]
proc-macro = true

[lints]
workspace = true

[dependencies]
quote = "1.0"
devise = "0.4"
Expand Down
3 changes: 3 additions & 0 deletions contrib/sync_db_pools/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.75"

[lints]
workspace = true

[features]
diesel_sqlite_pool = ["diesel/sqlite", "diesel/r2d2"]
diesel_postgres_pool = ["diesel/postgres", "diesel/r2d2"]
Expand Down
4 changes: 2 additions & 2 deletions contrib/sync_db_pools/lib/tests/databases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ mod databases_tests {
struct PrimaryDb(diesel::PgConnection);
}

#[cfg(all(feature = "databases", feature = "sqlite_pool"))]
#[cfg(test)]
#[cfg(all(feature = "sqlite_pool"))]
mod rusqlite_integration_test {
use rocket_sync_db_pools::{rusqlite, database};

Expand Down Expand Up @@ -58,13 +58,13 @@ mod rusqlite_integration_test {
}

#[cfg(test)]
#[cfg(feature = "databases")]
mod sentinel_and_runtime_test {
use rocket::{Rocket, Build};
use r2d2::{ManageConnection, Pool};
use rocket_sync_db_pools::{database, Poolable, PoolResult};
use tokio::runtime::Runtime;

#[allow(dead_code)]
struct ContainsRuntime(Runtime);
struct TestConnection;

Expand Down
3 changes: 3 additions & 0 deletions contrib/ws/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.75"

[lints]
workspace = true

[features]
default = ["tungstenite"]
tungstenite = ["tokio-tungstenite"]
Expand Down
7 changes: 3 additions & 4 deletions core/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.75"

[lints]
workspace = true

[lib]
proc-macro = true

[lints.clippy]
manual_range_contains = "allow"
large_enum_variant = "allow"

[dependencies]
indexmap = "2"
quote = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/src/syn_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl TypeExt for syn::Type {
fn is_concrete(&self, generics: &[&Ident]) -> bool {
struct ConcreteVisitor<'i>(bool, &'i [&'i Ident]);

impl<'a, 'i> Visit<'a> for ConcreteVisitor<'i> {
impl<'a> Visit<'a> for ConcreteVisitor<'_> {
fn visit_type(&mut self, ty: &'a syn::Type) {
use syn::Type::*;

Expand Down
14 changes: 7 additions & 7 deletions core/codegen/tests/catcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use rocket::local::blocking::Client;
use rocket::http::Status;

#[catch(404)] fn not_found_0() -> &'static str { "404-0" }
#[catch(404)] fn not_found_1(_: &Request) -> &'static str { "404-1" }
#[catch(404)] fn not_found_2(_: Status, _: &Request) -> &'static str { "404-2" }
#[catch(default)] fn all(_: Status, r: &Request) -> String { r.uri().to_string() }
#[catch(404)] fn not_found_1(_: &Request<'_>) -> &'static str { "404-1" }
#[catch(404)] fn not_found_2(_: Status, _: &Request<'_>) -> &'static str { "404-2" }
#[catch(default)] fn all(_: Status, r: &Request<'_>) -> String { r.uri().to_string() }

#[test]
fn test_simple_catchers() {
Expand All @@ -37,10 +37,10 @@ fn test_simple_catchers() {
}

#[get("/<code>")] fn forward(code: u16) -> Status { Status::new(code) }
#[catch(400)] fn forward_400(status: Status, _: &Request) -> String { status.code.to_string() }
#[catch(404)] fn forward_404(status: Status, _: &Request) -> String { status.code.to_string() }
#[catch(444)] fn forward_444(status: Status, _: &Request) -> String { status.code.to_string() }
#[catch(500)] fn forward_500(status: Status, _: &Request) -> String { status.code.to_string() }
#[catch(400)] fn forward_400(status: Status, _: &Request<'_>) -> String { status.code.to_string() }
#[catch(404)] fn forward_404(status: Status, _: &Request<'_>) -> String { status.code.to_string() }
#[catch(444)] fn forward_444(status: Status, _: &Request<'_>) -> String { status.code.to_string() }
#[catch(500)] fn forward_500(status: Status, _: &Request<'_>) -> String { status.code.to_string() }

#[test]
fn test_status_param() {
Expand Down
52 changes: 26 additions & 26 deletions core/codegen/tests/from_form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,23 +243,23 @@ fn field_renaming() {
}

let form_string = &["single=123", "some_case=hi_im_here"].join("&");
let form: Option<MultiName> = strict(&form_string).ok();
let form: Option<MultiName<'_>> = strict(&form_string).ok();
assert_eq!(form, Some(MultiName { single: 123, some_case: "hi_im_here", }));

let form_string = &["single=123", "SomeCase=HiImHere"].join("&");
let form: Option<MultiName> = strict(&form_string).ok();
let form: Option<MultiName<'_>> = strict(&form_string).ok();
assert_eq!(form, Some(MultiName { single: 123, some_case: "HiImHere", }));

let form_string = &["single=123", "some_case=hi_im_here", "SomeCase=HiImHere"].join("&");
let form: Option<MultiName> = strict(&form_string).ok();
let form: Option<MultiName<'_>> = strict(&form_string).ok();
assert!(form.is_none());

let form_string = &["single=123", "some_case=hi_im_here", "SomeCase=HiImHere"].join("&");
let form: Option<MultiName> = lenient(&form_string).ok();
let form: Option<MultiName<'_>> = lenient(&form_string).ok();
assert_eq!(form, Some(MultiName { single: 123, some_case: "hi_im_here", }));

let form_string = &["single=123", "SomeCase=HiImHere", "some_case=hi_im_here"].join("&");
let form: Option<MultiName> = lenient(&form_string).ok();
let form: Option<MultiName<'_>> = lenient(&form_string).ok();
assert_eq!(form, Some(MultiName { single: 123, some_case: "HiImHere", }));

#[derive(Debug, PartialEq, FromForm)]
Expand All @@ -273,19 +273,19 @@ fn field_renaming() {
}

let form_string = &["HeLLO=123", "sOMECASe=hi_im_here"].join("&");
let form: Option<CaseInsensitive> = strict(&form_string).ok();
let form: Option<CaseInsensitive<'_>> = strict(&form_string).ok();
assert_eq!(form, Some(CaseInsensitive { hello: 123, some_case: "hi_im_here", }));

let form_string = &["hello=456", "SomeCase=HiImHere"].join("&");
let form: Option<CaseInsensitive> = strict(&form_string).ok();
let form: Option<CaseInsensitive<'_>> = strict(&form_string).ok();
assert_eq!(form, Some(CaseInsensitive { hello: 456, some_case: "HiImHere", }));

let form_string = &["helLO=789", "some_case=hi_there"].join("&");
let form: Option<CaseInsensitive> = strict(&form_string).ok();
let form: Option<CaseInsensitive<'_>> = strict(&form_string).ok();
assert_eq!(form, Some(CaseInsensitive { hello: 789, some_case: "hi_there", }));

let form_string = &["hello=123", "SOme_case=hi_im_here"].join("&");
let form: Option<CaseInsensitive> = strict(&form_string).ok();
let form: Option<CaseInsensitive<'_>> = strict(&form_string).ok();
assert!(form.is_none());
}

Expand Down Expand Up @@ -479,7 +479,7 @@ fn test_multi() {
more_dogs: HashMap<&'r str, Dog>,
}

let multi: Multi = strict("checks=true&checks=false&checks=false\
let multi: Multi<'_> = strict("checks=true&checks=false&checks=false\
&names=Sam&names[]=Smith&names[]=Bob\
&news[]=Here&news[]=also here\
&dogs[fido].barks=true&dogs[George].barks=false\
Expand Down Expand Up @@ -545,17 +545,17 @@ struct Person<'r> {

#[test]
fn test_nested_multi() {
let person: Person = lenient("sitting.barks=true&sitting.trained=true").unwrap();
let person: Person<'_> = lenient("sitting.barks=true&sitting.trained=true").unwrap();
assert_eq!(person, Person {
sitting: Dog { barks: true, trained: true },
cats: vec![],
dogs: vec![],
});

let person = strict::<Person>("sitting.barks=true&sitting.trained=true");
let person = strict::<Person<'_>>("sitting.barks=true&sitting.trained=true");
assert!(person.is_err());

let person: Person = lenient("sitting.barks=true&sitting.trained=true\
let person: Person<'_> = lenient("sitting.barks=true&sitting.trained=true\
&dogs[0].name=fido&dogs[0].pet.trained=yes&dogs[0].age=7&dogs[0].pet.barks=no\
").unwrap();
assert_eq!(person, Person {
Expand All @@ -568,11 +568,11 @@ fn test_nested_multi() {
}]
});

let person = strict::<Person>("sitting.barks=true&sitting.trained=true\
let person = strict::<Person<'_>>("sitting.barks=true&sitting.trained=true\
&dogs[0].name=fido&dogs[0].pet.trained=yes&dogs[0].age=7&dogs[0].pet.barks=no");
assert!(person.is_err());

let person: Person = lenient("sitting.trained=no&sitting.barks=true\
let person: Person<'_> = lenient("sitting.trained=no&sitting.barks=true\
&dogs[0].name=fido&dogs[0].pet.trained=yes&dogs[0].age=7&dogs[0].pet.barks=no\
&dogs[1].pet.barks=true&dogs[1].name=Bob&dogs[1].pet.trained=no&dogs[1].age=1\
").unwrap();
Expand All @@ -593,7 +593,7 @@ fn test_nested_multi() {
]
});

let person: Person = strict("sitting.barks=true&sitting.trained=no\
let person: Person<'_> = strict("sitting.barks=true&sitting.trained=no\
&dogs[0].name=fido&dogs[0].pet.trained=yes&dogs[0].age=7&dogs[0].pet.barks=no\
&dogs[1].pet.barks=true&dogs[1].name=Bob&dogs[1].pet.trained=no&dogs[1].age=1\
&cats[george].pet.nip=paws&cats[george].name=George&cats[george].age=2\
Expand Down Expand Up @@ -636,7 +636,7 @@ fn test_multipart() {
}

#[rocket::post("/", data = "<form>")]
fn form(form: Form<MyForm>) {
fn form(form: Form<MyForm<'_>>) {
assert_eq!(form.names, &["abcd", "123"]);
assert_eq!(form.file.name(), Some("foo"));
}
Expand Down Expand Up @@ -797,11 +797,11 @@ fn test_defaults() {
}

// `field2` has no default.
assert!(lenient::<FormWithDefaults>("").is_err());
assert!(lenient::<FormWithDefaults<'_>>("").is_err());

// every other field should.
let form_string = &["field2=102"].join("&");
let form1: Option<FormWithDefaults> = lenient(&form_string).ok();
let form1: Option<FormWithDefaults<'_>> = lenient(&form_string).ok();
assert_eq!(form1, Some(FormWithDefaults {
field1: 100,
field2: 102,
Expand Down Expand Up @@ -834,12 +834,12 @@ fn test_defaults() {
),
}));

let form2: Option<FormWithDefaults> = strict(&form_string).ok();
let form2: Option<FormWithDefaults<'_>> = strict(&form_string).ok();
assert!(form2.is_none());

// Ensure actual form field values take precedence.
let form_string = &["field1=101", "field2=102", "field3=true", "field5=true"].join("&");
let form3: Option<FormWithDefaults> = lenient(&form_string).ok();
let form3: Option<FormWithDefaults<'_>> = lenient(&form_string).ok();
assert_eq!(form3, Some(FormWithDefaults {
field1: 101,
field2: 102,
Expand All @@ -852,7 +852,7 @@ fn test_defaults() {
// And that strict parsing still works.
let form = form3.unwrap();
let form_string = format!("{}", &form as &dyn UriDisplay<Query>);
let form4: form::Result<'_, FormWithDefaults> = strict(&form_string);
let form4: form::Result<'_, FormWithDefaults<'_>> = strict(&form_string);
assert_eq!(form4, Ok(form), "parse from {}", form_string);

#[derive(FromForm, UriDisplayQuery, PartialEq, Debug)]
Expand Down Expand Up @@ -940,22 +940,22 @@ struct TokenOwned(String);

#[test]
fn wrapper_works() {
let form: Option<Token> = lenient("").ok();
let form: Option<Token<'_>> = lenient("").ok();
assert_eq!(form, Some(Token("some default hello")));

let form: Option<TokenOwned> = lenient("").ok();
assert_eq!(form, Some(TokenOwned("123456".into())));

let errors = strict::<Token>("").unwrap_err();
let errors = strict::<Token<'_>>("").unwrap_err();
assert!(errors.iter().any(|e| matches!(e.kind, ErrorKind::Missing)));

let form: Option<Token> = lenient("=hi there").ok();
let form: Option<Token<'_>> = lenient("=hi there").ok();
assert_eq!(form, Some(Token("hi there")));

let form: Option<TokenOwned> = strict_encoded("=2318").ok();
assert_eq!(form, Some(TokenOwned("2318".into())));

let errors = lenient::<Token>("=hi").unwrap_err();
let errors = lenient::<Token<'_>>("=hi").unwrap_err();
assert!(errors.iter().any(|e| matches!(e.kind, ErrorKind::InvalidLength { .. })));

let errors = lenient::<TokenOwned>("=hellothere").unwrap_err();
Expand Down
9 changes: 5 additions & 4 deletions core/codegen/tests/responder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,20 @@ async fn generic_responder() {
let local_req = client.get("/");
let req = local_req.inner();

let v: MyResult<_, (), ContentType, Cookie<'static>> = MyResult::Ok(Json("hi"));
let v: MyResult<'_, _, (), ContentType, Cookie<'static>> = MyResult::Ok(Json("hi"));
let mut r = v.respond_to(req).unwrap();
assert_eq!(r.status(), Status::Ok);
assert_eq!(r.content_type().unwrap(), ContentType::JSON);
assert_eq!(r.body_mut().to_string().await.unwrap(), "\"hi\"");

let v: MyResult<(), &[u8], _, _> = MyResult::Err(&[7, 13, 23], ContentType::JPEG, Accept::Text);
let bytes = &[7, 13, 23];
let v: MyResult<'_, (), &[u8], _, _> = MyResult::Err(bytes, ContentType::JPEG, Accept::Text);
let mut r = v.respond_to(req).unwrap();
assert_eq!(r.status(), Status::NotFound);
assert_eq!(r.content_type().unwrap(), ContentType::JPEG);
assert_eq!(r.body_mut().to_bytes().await.unwrap(), vec![7, 13, 23]);
assert_eq!(r.body_mut().to_bytes().await.unwrap(), bytes);

let v: MyResult<(), &[u8], ContentType, Accept> = MyResult::Other("beep beep");
let v: MyResult<'_, (), &[u8], ContentType, Accept> = MyResult::Other("beep beep");
let mut r = v.respond_to(req).unwrap();
assert_eq!(r.status(), Status::InternalServerError);
assert_eq!(r.content_type().unwrap(), ContentType::Text);
Expand Down
2 changes: 1 addition & 1 deletion core/codegen/tests/route-raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn swap(r#raw: String, bare: String) -> String {
}

#[catch(400)]
fn catch(r#raw: &rocket::Request) -> String {
fn catch(r#raw: &rocket::Request<'_>) -> String {
format!("{}", raw.method())
}

Expand Down
8 changes: 3 additions & 5 deletions core/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ categories = ["web-programming"]
edition = "2021"
rust-version = "1.75"

[lints]
workspace = true

[features]
default = []
serde = ["dep:serde", "uncased/with-serde-alloc"]
uuid = ["dep:uuid"]

[lints.clippy]
module_inception = "allow"
multiple_bound_locations = "allow"
manual_range_contains = "allow"

[dependencies]
tinyvec = { version = "1.6", features = ["std", "rustc_1_57"] }
percent-encoding = "2"
Expand Down
Loading

0 comments on commit 3079dbf

Please sign in to comment.