Fix assorted warnings

This commit is contained in:
Maybe Waffle 2024-03-21 14:42:45 +01:00
parent cedf223b0d
commit b8c45110a3
28 changed files with 50 additions and 99 deletions

View file

@ -12,7 +12,7 @@ use url::Url;
use crate::{
payloads::GetMe,
requests::{HasPayload, Request, Requester},
types::{Me, Recipient, *},
types::*,
};
/// `get_me` cache.

View file

@ -11,7 +11,7 @@ use crate::{
},
prelude::Requester,
requests::{HasPayload, Output, Request},
types::{InputFile, ParseMode, Recipient, *},
types::*,
};
/// Default parse mode adaptor, see

View file

@ -61,7 +61,7 @@
html_logo_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png",
html_favicon_url = "https://cdn.discordapp.com/attachments/224881373326999553/798598120760934410/logo.png"
)]
#![forbid(unsafe_code)]
//
// we pass "--cfg docsrs" when building docs to add `This is supported on feature="..." only.`
//
// To properly build docs of this crate run
@ -78,16 +78,29 @@
)]
#![cfg_attr(feature = "nightly", feature(type_alias_impl_trait))]
#![cfg_attr(all(feature = "full", docsrs), deny(rustdoc::broken_intra_doc_links))]
//
// Lint levels
#![forbid(unsafe_code)]
//#![deny(missing_docs)]
#![warn(clippy::print_stdout, clippy::dbg_macro)]
#![allow(clippy::let_and_return)]
#![allow(clippy::bool_assert_comparison)]
// Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
#![allow(clippy::return_self_not_must_use)]
// Workaround for CI
#![allow(rustdoc::bare_urls)]
// FIXME: deal with these lints
#![allow(
// Sometimes it's more readable to assign to a variable and return it immediately
clippy::let_and_return,
// When you are testing ->bool functions, it makes sense to `assert_eq!(f(..), false)`
clippy::bool_assert_comparison,
// Unless this becomes machine applicable, I'm not adding 334 #[must_use]s (waffle)
clippy::return_self_not_must_use,
// This is dumb. `T: ?Sized where T: Trait` IMO makes perfect sense
clippy::multiple_bound_locations,
// Workaround for CI
// FIXME: do we still need this?
rustdoc::bare_urls,
// FIXME: deal with these lints
clippy::collapsible_str_replace,
clippy::borrow_deref_ref,
clippy::unnecessary_lazy_evaluations,

View file

@ -49,7 +49,7 @@ impl<R> From<TelegramResponse<R>> for ResponseResult<R> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{errors::ApiError, types::Update};
use crate::types::Update;
#[test]
fn parse_terminated_by_other_get_updates() {

View file

@ -20,4 +20,3 @@ mod payload;
mod request;
mod requester;
mod requester_ext;
mod utils;

View file

@ -3,11 +3,7 @@
use url::Url;
use crate::{
payloads::{GetMe, SendMessage, *},
requests::Request,
types::*,
};
use crate::{payloads::*, requests::Request, types::*};
/// Telegram Bot API client.
///

View file

@ -1,16 +0,0 @@
use bytes::{Bytes, BytesMut};
use tokio_util::codec::Decoder;
struct FileDecoder;
impl Decoder for FileDecoder {
type Item = Bytes;
type Error = std::io::Error;
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
if src.is_empty() {
return Ok(None);
}
Ok(Some(src.split().freeze()))
}
}

View file

@ -268,16 +268,12 @@ pub use user_id::*;
use serde::Serialize;
/// Converts an `i64` timestump to a `choro::DateTime`, producing serde error
/// for invalid timestumps
/// Converts an `i64` timestamp to a `choro::DateTime`, producing serde error
/// for invalid timestamps
pub(crate) fn serde_timestamp<E: serde::de::Error>(
timestamp: i64,
) -> Result<chrono::DateTime<chrono::Utc>, E> {
use chrono::{DateTime, NaiveDateTime, Utc};
NaiveDateTime::from_timestamp_opt(timestamp, 0)
.ok_or_else(|| E::custom("invalid timestump"))
.map(|naive| DateTime::from_naive_utc_and_offset(naive, Utc))
chrono::DateTime::from_timestamp(timestamp, 0).ok_or_else(|| E::custom("invalid timestump"))
}
pub(crate) mod serde_opt_date_from_unix_timestamp {
@ -313,10 +309,7 @@ pub(crate) mod serde_opt_date_from_unix_timestamp {
{
let json = r#"{"date":1}"#;
let expected = DateTime::from_naive_utc_and_offset(
chrono::NaiveDateTime::from_timestamp_opt(1, 0).unwrap(),
Utc,
);
let expected = DateTime::from_timestamp(1, 0).unwrap();
let Struct { date } = serde_json::from_str(json).unwrap();
assert_eq!(date, Some(expected));

View file

@ -36,8 +36,6 @@ pub struct Animation {
#[cfg(test)]
mod tests {
use crate::types::FileMeta;
use super::*;
#[test]

View file

@ -36,8 +36,6 @@ pub struct Audio {
#[cfg(test)]
mod tests {
use crate::types::{FileMeta, Seconds};
use super::*;
#[test]

View file

@ -702,7 +702,7 @@ mod tests {
can_invite_users: true,
can_pin_messages: true,
until_date: UntilDate::Date(
chrono::NaiveDateTime::from_timestamp_opt(1620000000, 0).unwrap().and_utc(),
chrono::DateTime::from_timestamp(1620000000, 0).unwrap(),
),
}),
};

View file

@ -15,15 +15,8 @@ use tokio::{
use tokio_util::codec::{Decoder, FramedRead};
use std::{
borrow::Cow,
convert::{Infallible, TryFrom},
fmt,
future::Future,
io, iter, mem,
path::PathBuf,
pin::Pin,
sync::Arc,
task,
borrow::Cow, convert::Infallible, fmt, future::Future, io, iter, mem, path::PathBuf, pin::Pin,
sync::Arc, task,
};
use crate::types::InputSticker;

View file

@ -1748,7 +1748,7 @@ mod tests {
Message {
id: MessageId(198283),
thread_id: None,
date: chrono::NaiveDateTime::from_timestamp_opt(1567927221, 0).unwrap().and_utc(),
date: chrono::DateTime::from_timestamp(1567927221, 0).unwrap(),
chat: Chat {
id: ChatId(250918540),
kind: ChatKind::Private(ChatPrivate {

View file

@ -264,7 +264,6 @@ pub enum MessageEntityKind {
mod tests {
use super::*;
use cool_asserts::assert_matches;
use MessageEntity;
use MessageEntityKind::*;
#[test]

View file

@ -2,10 +2,7 @@
// (for built ins there no warnings, but for (De)Serialize, there are)
#![allow(deprecated)]
use std::{
convert::{TryFrom, TryInto},
str::FromStr,
};
use std::str::FromStr;
use serde::{Deserialize, Serialize};
@ -184,8 +181,8 @@ impl FromStr for ParseMode {
}
#[cfg(test)]
#[allow(deprecated)]
mod tests {
#![allow(deprecated)]
use super::*;

View file

@ -20,7 +20,6 @@ pub enum ResponseParameters {
#[cfg(test)]
mod tests {
use super::*;
use crate::types::{ChatId, Seconds};
#[test]
fn migrate_to_chat_id_deserialization() {

View file

@ -26,8 +26,11 @@ impl Seconds {
}
/// Returns [`chrono::Duration`] equivalent of this duration.
// FIXME: rename to `time_delta` (the new name of `chrono::Duration`)?
pub fn chrono_duration(self) -> chrono::Duration {
chrono::Duration::seconds(self.seconds() as i64)
// Unwrap: `self.seconds()` is a `u32`, which is always between `-i64::MAX/1000`
// and `i64::MAX/1000`
chrono::Duration::try_seconds(self.seconds() as i64).unwrap()
}
}

View file

@ -1,4 +1,4 @@
use std::{convert::TryFrom, ops::Deref};
use std::ops::Deref;
use serde::{Deserialize, Serialize};

View file

@ -384,16 +384,13 @@ mod test {
MessageId, MessageKind, Update, UpdateId, UpdateKind, User, UserId,
};
use chrono::{DateTime, NaiveDateTime, Utc};
use chrono::DateTime;
// TODO: more tests for deserialization
#[test]
fn message() {
let timestamp = 1_569_518_342;
let date = DateTime::from_naive_utc_and_offset(
NaiveDateTime::from_timestamp_opt(timestamp, 0).unwrap(),
Utc,
);
let date = DateTime::from_timestamp(timestamp, 0).unwrap();
let json = r#"{
"update_id":892252934,

View file

@ -1,5 +1,3 @@
use std::iter::FromIterator;
pub(crate) struct Unzip<A, B>(pub A, pub B);
impl<A, B, T, U> FromIterator<(T, U)> for Unzip<A, B>

View file

@ -129,9 +129,11 @@ async fn mute_user(bot: Bot, msg: Message, time: Duration) -> ResponseResult<()>
// Calculates time of user restriction.
fn calc_restrict_time(time: u64, unit: UnitOfTime) -> Duration {
// FIXME: actually handle the case of too big integers correctly, instead of
// unwrapping
match unit {
UnitOfTime::Hours => Duration::hours(time as i64),
UnitOfTime::Minutes => Duration::minutes(time as i64),
UnitOfTime::Seconds => Duration::seconds(time as i64),
UnitOfTime::Hours => Duration::try_hours(time as i64).unwrap(),
UnitOfTime::Minutes => Duration::try_minutes(time as i64).unwrap(),
UnitOfTime::Seconds => Duration::try_seconds(time as i64).unwrap(),
}
}

View file

@ -1,9 +1,4 @@
use teloxide::{
dispatching::Dispatcher,
prelude::*,
types::{ChatMemberUpdated, ParseMode, Update},
utils::html,
};
use teloxide::{prelude::*, types::ParseMode, utils::html};
use teloxide_core::adaptors::DefaultParseMode;
/// We use a type alias to be able to write just `bot: Bot` in handlers, instead

View file

@ -3,11 +3,7 @@
use rand::Rng;
use teloxide::{
prelude::*,
types::{Dice, Update, UserId},
utils::command::BotCommands,
};
use teloxide::{prelude::*, types::Dice, utils::command::BotCommands};
#[tokio::main]
async fn main() {

View file

@ -3,7 +3,6 @@ use teloxide::{
types::{
InlineQueryResult, InlineQueryResultArticle, InputMessageContent, InputMessageContentText,
},
Bot,
};
#[tokio::main]

View file

@ -1,8 +1,4 @@
use std::{
fmt::Debug,
marker::{Send, Sync},
sync::Arc,
};
use std::{fmt::Debug, sync::Arc};
use futures::future::BoxFuture;
use teloxide_core::types::ChatId;

View file

@ -1,5 +1,4 @@
use std::{
convert::TryInto,
future::Future,
mem,
pin::Pin,

View file

@ -115,8 +115,6 @@ pub fn user_mention_or_link(user: &User) -> String {
#[cfg(test)]
mod tests {
use teloxide_core::types::UserId;
use super::*;
#[test]

View file

@ -157,7 +157,6 @@ pub fn user_mention_or_link(user: &User) -> String {
#[cfg(test)]
mod tests {
use super::*;
use teloxide_core::types::{User, UserId};
#[test]
fn test_bold() {