Fix various generated and direct clippy warnings.

This commit is contained in:
Sergio Benitez 2021-06-08 02:52:47 -07:00
parent 4c6562cd29
commit 1a42009e9f
11 changed files with 37 additions and 43 deletions

View File

@ -51,7 +51,7 @@ impl EntryAttr for Launch {
#[allow(dead_code)] #f
#vis #sig {
::rocket::async_main(async move { let _ = #rocket.launch().await; })
::rocket::async_main(async move { let _res = #rocket.launch().await; })
}
))
}

View File

@ -12,8 +12,8 @@ fn fields_map<F>(fields: Fields<'_>, map_f: F) -> Result<TokenStream>
for field in fields.iter() {
let (ident, ty) = (field.ident(), field.stripped_ty());
let field_context = quote_spanned!(ty.span() => {
let _o = __c.__opts;
__c.#ident.get_or_insert_with(|| <#ty as #_form::FromForm<'__f>>::init(_o))
let __o = __c.__opts;
__c.#ident.get_or_insert_with(|| <#ty as #_form::FromForm<'__f>>::init(__o))
});
let field_names = field.field_names()?;
@ -32,7 +32,7 @@ fn fields_map<F>(fields: Fields<'_>, map_f: F) -> Result<TokenStream>
match __f.name.key_lossy().as_str() {
#(#matchers,)*
_k if _k == "_method" || !__c.__opts.strict => { /* ok */ },
__k if __k == "_method" || !__c.__opts.strict => { /* ok */ },
_ => __c.__errors.push(__f.unexpected()),
}
})
@ -205,7 +205,7 @@ pub fn derive_from_form(input: proc_macro::TokenStream) -> TokenStream {
Ok(quote_spanned! { fields.span() =>
#(let #ident = match #finalize_field {
#_ok(#ident) => #_some(#ident),
#_err(_e) => { __c.__errors.extend(_e); #_none }
#_err(__e) => { __c.__errors.extend(__e); #_none }
};)*
if !__c.__errors.is_empty() {
@ -215,8 +215,8 @@ pub fn derive_from_form(input: proc_macro::TokenStream) -> TokenStream {
let #o = Self { #(#ident: #ident.unwrap()),* };
#(
if let #_err(_e) = #validate {
__c.__errors.extend(_e.with_name(#name_view));
if let #_err(__e) = #validate {
__c.__errors.extend(__e.with_name(#name_view));
}
)*
@ -240,24 +240,19 @@ pub fn derive_from_form(input: proc_macro::TokenStream) -> TokenStream {
let __name = #name_view;
let __opts = __c.__opts;
__c.#ident
.map(<#ty as #_form::FromForm<'__f>>::finalize)
.unwrap_or_else(|| {
#default.ok_or_else(|| #_form::ErrorKind::Missing.into())
})
.map_or_else(
|| #default.ok_or_else(|| #_form::ErrorKind::Missing.into()),
<#ty as #_form::FromForm<'__f>>::finalize
)
.and_then(|#ident| {
let mut __es = #_form::Errors::new();
#(if let #_err(__e) = #validator { __es.extend(__e); })*
match __es.is_empty() {
true => #_Ok(#ident),
false => #_Err(__es)
}
__es.is_empty().then(|| #ident).ok_or(__es)
})
.map_err(|__e| __e.with_name(__name))
.map_err(|__e| match __e.is_empty() {
true => #_form::ErrorKind::Unknown.into(),
false => __e,
})
.map_err(|__e| __e.is_empty()
.then(|| #_form::ErrorKind::Unknown.into())
.unwrap_or(__e))
}})
})
)

View File

@ -46,7 +46,7 @@ async fn events(queue: &State<Sender<Message>>, mut end: Shutdown) -> EventStrea
#[post("/message", data = "<form>")]
fn post(form: Form<Message>, queue: &State<Sender<Message>>) {
// A send 'fails' if there are no active subscribers. That's okay.
let _ = queue.send(form.into_inner());
let _res = queue.send(form.into_inner());
}
#[launch]

View File

@ -23,13 +23,13 @@ type Result<T, E = Debug<rusqlite::Error>> = std::result::Result<T, E>;
#[post("/", data = "<post>")]
async fn create(db: Db, post: Json<Post>) -> Result<Created<Json<Post>>> {
let qpost = post.clone();
let item = post.clone();
db.run(move |conn| {
conn.execute("INSERT INTO posts (title, text) VALUES (?1, ?2)",
params![qpost.title, qpost.text])
params![item.title, item.text])
}).await?;
Ok(Created::new("/").body(Json(post.into_inner())))
Ok(Created::new("/").body(post))
}
#[get("/")]

View File

@ -63,7 +63,7 @@ struct Submit<'v> {
}
#[get("/")]
fn index<'r>() -> Template {
fn index() -> Template {
Template::render("index", &Context::default())
}

View File

@ -5,7 +5,7 @@ use std::env;
use rocket::{Request, Route, Catcher, route, catcher};
use rocket::data::{Data, ToByteUnit};
use rocket::http::{Status, Method::*};
use rocket::http::{Status, Method::{Get, Post}};
use rocket::response::{Responder, status::Custom};
use rocket::outcome::{try_outcome, IntoOutcome};
use rocket::tokio::fs::File;
@ -18,17 +18,17 @@ fn hi<'r>(req: &'r Request, _: Data<'r>) -> route::BoxFuture<'r> {
route::Outcome::from(req, "Hello!").pin()
}
fn name<'a>(req: &'a Request, _: Data<'r>) -> route::BoxFuture<'a> {
let param = req.param::<&'a str>(0)
.and_then(|res| res.ok())
.unwrap_or("unnamed".into());
fn name<'r>(req: &'r Request, _: Data<'r>) -> route::BoxFuture<'r> {
let param = req.param::<&'r str>(0)
.and_then(Result::ok)
.unwrap_or("unnamed");
route::Outcome::from(req, param).pin()
}
fn echo_url<'r>(req: &'r Request, _: Data<'r>) -> route::BoxFuture<'r> {
let param_outcome = req.param::<&str>(1)
.and_then(|res| res.ok())
.and_then(Result::ok)
.into_outcome(Status::BadRequest);
Box::pin(async move {
@ -63,8 +63,8 @@ fn get_upload<'r>(req: &'r Request, _: Data<'r>) -> route::BoxFuture<'r> {
}
fn not_found_handler<'r>(_: Status, req: &'r Request) -> catcher::BoxFuture<'r> {
let res = Custom(Status::NotFound, format!("Couldn't find: {}", req.uri()));
Box::pin(async move { res.respond_to(req) })
let responder = Custom(Status::NotFound, format!("Couldn't find: {}", req.uri()));
Box::pin(async move { responder.respond_to(req) })
}
#[derive(Clone)]
@ -83,7 +83,7 @@ impl route::Handler for CustomHandler {
async fn handle<'r>(&self, req: &'r Request<'_>, data: Data<'r>) -> route::Outcome<'r> {
let self_data = self.data;
let id = req.param::<&str>(0)
.and_then(|res| res.ok())
.and_then(Result::ok)
.or_forward(data);
route::Outcome::from(req, format!("{} - {}", self_data, try_outcome!(id)))

View File

@ -39,10 +39,9 @@ impl<'a> FromParam<'a> for PasteId<'a> {
type Error = &'a str;
fn from_param(param: &'a str) -> Result<Self, Self::Error> {
match param.chars().all(|c| c.is_ascii_alphanumeric()) {
true => Ok(PasteId(param.into())),
false => Err(param)
}
param.chars().all(|c| c.is_ascii_alphanumeric())
.then(|| PasteId(param.into()))
.ok_or(param)
}
}

View File

@ -49,7 +49,7 @@ fn many_his() -> TextStream![&'static str] {
#[get("/stream/hi/<n>")]
fn one_hi_per_ms(mut shutdown: Shutdown, n: u8) -> TextStream![&'static str] {
TextStream! {
let mut interval = time::interval(Duration::from_millis(n as u64));
let mut interval = time::interval(Duration::from_millis(n.into()));
loop {
select! {
_ = interval.tick() => yield "hi",

View File

@ -39,7 +39,7 @@ async fn update(id: Id, message: Json<Message<'_>>, list: Messages<'_>) -> Optio
}
#[get("/<id>", format = "json")]
async fn get<'r>(id: Id, list: Messages<'r>) -> Option<Json<Message<'r>>> {
async fn get(id: Id, list: Messages<'_>) -> Option<Json<Message<'_>>> {
let list = list.lock().await;
Some(Json(Message {

View File

@ -13,7 +13,7 @@ fn get(id: usize) -> MsgPack<Message<'static>> {
}
#[post("/", data = "<data>", format = "msgpack")]
fn echo<'r>(data: MsgPack<Message<'r>>) -> &'r str {
fn echo(data: MsgPack<Message<'_>>) -> &str {
data.message
}

View File

@ -9,9 +9,9 @@ struct People(HashMap<Uuid, &'static str>);
#[get("/people/<id>")]
fn people(id: Uuid, people: &State<People>) -> Result<String, String> {
Ok(people.0.get(&id)
people.0.get(&id)
.map(|person| format!("We found: {}", person))
.ok_or_else(|| format!("Missing person for UUID: {}", id))?)
.ok_or_else(|| format!("Missing person for UUID: {}", id))
}
pub fn stage() -> rocket::fairing::AdHoc {