diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32d8f443..9fab6bea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ env: # - crates/teloxide-core/src/codegen.rs # - rust-toolchain.toml # - below in the test matrix - rust_nightly: nightly-2024-03-20 + rust_nightly: nightly-2024-07-03 # When updating this, also update: # - **/README.md # - **/src/lib.rs @@ -105,7 +105,7 @@ jobs: toolchain: beta features: "--features full" - rust: nightly - toolchain: nightly-2024-03-20 + toolchain: nightly-2024-07-03 features: "--features full nightly" - rust: msrv toolchain: 1.70.0 diff --git a/crates/teloxide-core/Cargo.toml b/crates/teloxide-core/Cargo.toml index c2cb2ac2..669abaea 100644 --- a/crates/teloxide-core/Cargo.toml +++ b/crates/teloxide-core/Cargo.toml @@ -112,6 +112,9 @@ pre-release-replacements = [ { file = "CHANGELOG.md", search = "## unreleased", replace = "## unreleased\n\n## {{version}} - {{date}}", exactly = 1 }, ] +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(dep_docsrs)'] } + [[example]] name = "self_info" required-features = ["tokio/macros", "tokio/rt-multi-thread"] diff --git a/crates/teloxide-core/src/codegen.rs b/crates/teloxide-core/src/codegen.rs index 316b5436..36f0c1f2 100644 --- a/crates/teloxide-core/src/codegen.rs +++ b/crates/teloxide-core/src/codegen.rs @@ -23,7 +23,7 @@ use xshell::{cmd, Shell}; fn ensure_rustfmt(sh: &Shell) { // FIXME(waffle): find a better way to set toolchain - let toolchain = "nightly-2024-03-20"; + let toolchain = "nightly-2024-07-03"; let version = cmd!(sh, "rustup run {toolchain} rustfmt --version").read().unwrap_or_default(); @@ -36,7 +36,7 @@ fn ensure_rustfmt(sh: &Shell) { } pub fn reformat(text: String) -> String { - let toolchain = "nightly-2024-03-20"; + let toolchain = "nightly-2024-07-03"; let sh = Shell::new().unwrap(); ensure_rustfmt(&sh); @@ -89,7 +89,7 @@ pub fn ensure_files_contents<'a>( err_count += 1; - let display_path = path.strip_prefix(&project_root()).unwrap_or(path); + let display_path = path.strip_prefix(project_root()).unwrap_or(path); eprintln!( "\n\x1b[31;1merror\x1b[0m: {} was not up-to-date, updating\n", display_path.display() diff --git a/crates/teloxide-core/src/codegen/convert.rs b/crates/teloxide-core/src/codegen/convert.rs index a31b3e88..1e368b26 100644 --- a/crates/teloxide-core/src/codegen/convert.rs +++ b/crates/teloxide-core/src/codegen/convert.rs @@ -1,6 +1,7 @@ use crate::codegen::schema::Type; pub enum Convert { + #[allow(dead_code)] Id(Type), Into(Type), Collect(Type), diff --git a/crates/teloxide-core/src/types/chat_member.rs b/crates/teloxide-core/src/types/chat_member.rs index 715e8d53..23328ea7 100644 --- a/crates/teloxide-core/src/types/chat_member.rs +++ b/crates/teloxide-core/src/types/chat_member.rs @@ -361,6 +361,7 @@ impl ChatMemberKind { /// - is the owner of the chat /// - is an administrator in the given chat and has [`can_manage_chat`] /// privilege. + /// /// Returns `false` otherwise. /// /// [`can_manage_chat`]: Administrator::can_manage_chat @@ -379,6 +380,7 @@ impl ChatMemberKind { /// - is the owner of the chat (even if the chat is not a channel) /// - is an administrator in the given chat and has [`can_post_messages`] /// privilege. + /// /// Returns `false` otherwise. /// /// [`can_post_messages`]: Administrator::can_post_messages @@ -398,6 +400,7 @@ impl ChatMemberKind { /// - is the owner of the chat (even if the chat is not a channel) /// - is an administrator in the given chat and has the /// [`can_edit_messages`] privilege. + /// /// Returns `false` otherwise. /// /// [`can_edit_messages`]: Administrator::can_edit_messages @@ -416,6 +419,7 @@ impl ChatMemberKind { /// - is the owner of the chat /// - is an administrator in the given chat and has the /// [`can_delete_messages`] privilege. + /// /// Returns `false` otherwise. /// /// [`can_delete_messages`]: Administrator::can_delete_messages @@ -434,6 +438,7 @@ impl ChatMemberKind { /// - is the owner of the chat /// - is an administrator in the given chat and has the /// [`can_manage_video_chats`] privilege. + /// /// Returns `false` otherwise. /// /// [`can_manage_video_chats`]: Administrator::can_manage_video_chats @@ -454,6 +459,7 @@ impl ChatMemberKind { /// - is the owner of the chat /// - is an administrator in the given chat and has the /// [`can_restrict_members`] privilege. + /// /// Returns `false` otherwise. /// /// [`can_restrict_members`]: Administrator::can_restrict_members @@ -477,6 +483,7 @@ impl ChatMemberKind { /// - is the owner of the chat (even if the chat is not a channel) /// - is an administrator in the given chat and has the /// [`can_promote_members`] privilege. + /// /// Returns `false` otherwise. /// /// [`can_promote_members`]: Administrator::can_promote_members diff --git a/crates/teloxide-core/src/types/message.rs b/crates/teloxide-core/src/types/message.rs index e2de607f..7df5e3d7 100644 --- a/crates/teloxide-core/src/types/message.rs +++ b/crates/teloxide-core/src/types/message.rs @@ -1009,17 +1009,16 @@ mod getters { #[must_use] pub fn caption(&self) -> Option<&str> { match &self.kind { - Common(MessageCommon { media_kind, .. }) => match media_kind { - MediaKind::Animation(MediaAnimation { caption, .. }) - | MediaKind::Audio(MediaAudio { caption, .. }) - | MediaKind::Document(MediaDocument { caption, .. }) - | MediaKind::Photo(MediaPhoto { caption, .. }) - | MediaKind::Video(MediaVideo { caption, .. }) - | MediaKind::Voice(MediaVoice { caption, .. }) => { - caption.as_ref().map(Deref::deref) - } - _ => None, - }, + Common(MessageCommon { + media_kind: + MediaKind::Animation(MediaAnimation { caption, .. }) + | MediaKind::Audio(MediaAudio { caption, .. }) + | MediaKind::Document(MediaDocument { caption, .. }) + | MediaKind::Photo(MediaPhoto { caption, .. }) + | MediaKind::Video(MediaVideo { caption, .. }) + | MediaKind::Voice(MediaVoice { caption, .. }), + .. + }) => caption.as_ref().map(Deref::deref), _ => None, } } diff --git a/crates/teloxide/Cargo.toml b/crates/teloxide/Cargo.toml index 8d26b8a5..823d4099 100644 --- a/crates/teloxide/Cargo.toml +++ b/crates/teloxide/Cargo.toml @@ -165,6 +165,12 @@ name = "postgres" path = "tests/postgres.rs" required-features = ["postgres-storage-nativetls", "cbor-serializer", "bincode-serializer"] +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = [ + 'cfg(CI_POSTGRES)', + 'cfg(CI_REDIS)', +] } + [[example]] name = "admin" required-features = ["macros", "ctrlc_handler"] diff --git a/crates/teloxide/src/dispatching.rs b/crates/teloxide/src/dispatching.rs index 5c048e23..1caa197b 100644 --- a/crates/teloxide/src/dispatching.rs +++ b/crates/teloxide/src/dispatching.rs @@ -91,8 +91,7 @@ //! several techniques: //! //! - **Branching:** `a.branch(b)` roughly means "try to handle an update with -//! `a`, then, if it -//! neglects the update, try `b`". +//! `a`, then, if it neglects the update, try `b`". //! - **Pattern matching:** We also use the [`dptree::case!`] macro //! extensively, which acts as a filter on an enumeration: if it is of a //! certain variant, it passes the variant's payload down the handler chain; diff --git a/crates/teloxide/src/dispatching/dialogue/storage/postgres_storage.rs b/crates/teloxide/src/dispatching/dialogue/storage/postgres_storage.rs index ceb4f2a8..f5f78a42 100644 --- a/crates/teloxide/src/dispatching/dialogue/storage/postgres_storage.rs +++ b/crates/teloxide/src/dispatching/dialogue/storage/postgres_storage.rs @@ -44,9 +44,8 @@ impl PostgresStorage { /// - database_url: full url to the postgres database, for example /// `"postgres://postgres:password@localhost/test")` /// - max_connections: number of connections in creating connection pool. Be - /// mindful of the connection limits for your database, each - /// connection established with the Postgres creates a new process on the - /// server side + /// mindful of the connection limits for your database, each connection + /// established with the Postgres creates a new process on the server side /// - serializer: what [`Serializer`] will be used to encode the dialogue /// data. Available ones are: [`Json`], [`Bincode`], [`Cbor`] /// diff --git a/crates/teloxide/src/dispatching/dialogue/storage/redis_storage.rs b/crates/teloxide/src/dispatching/dialogue/storage/redis_storage.rs index de9294d8..b5919d2f 100644 --- a/crates/teloxide/src/dispatching/dialogue/storage/redis_storage.rs +++ b/crates/teloxide/src/dispatching/dialogue/storage/redis_storage.rs @@ -89,7 +89,7 @@ where Box::pin(async move { let dialogue = self.serializer.serialize(&dialogue).map_err(RedisStorageError::SerdeError)?; - self.conn.lock().await.set::<_, Vec, _>(chat_id, dialogue).await?; + () = self.conn.lock().await.set::<_, Vec, _>(chat_id, dialogue).await?; Ok(()) }) } diff --git a/crates/teloxide/src/dispatching/handler_ext.rs b/crates/teloxide/src/dispatching/handler_ext.rs index 0013acb4..f5f3236d 100644 --- a/crates/teloxide/src/dispatching/handler_ext.rs +++ b/crates/teloxide/src/dispatching/handler_ext.rs @@ -28,11 +28,11 @@ pub trait HandlerExt { /// It does so by the following steps: /// /// 1. If an incoming update has no chat ID ([`GetChatId::chat_id`] returns - /// `None`), the rest of the chain will not be executed. Otherwise, passes - /// `Dialogue::new(storage, chat_id)` forwards. + /// `None`), the rest of the chain will not be executed. Otherwise, + /// passes `Dialogue::new(storage, chat_id)` forwards. /// 2. If [`Dialogue::get_or_default`] on the passed dialogue returns `Ok`, - /// passes the dialogue state forwards. Otherwise, logs an error and the - /// rest of the chain is not executed. + /// passes the dialogue state forwards. Otherwise, logs an error and the + /// rest of the chain is not executed. /// /// ## Dependency requirements /// diff --git a/crates/teloxide/src/utils/command.rs b/crates/teloxide/src/utils/command.rs index ab85f893..0dce838a 100644 --- a/crates/teloxide/src/utils/command.rs +++ b/crates/teloxide/src/utils/command.rs @@ -81,22 +81,22 @@ pub use teloxide_macros::BotCommands; /// ``` /// /// # Enum attributes -/// 1. `#[command(rename_rule = "rule")]` -/// Rename all commands by `rule`. Allowed rules are `lowercase`, `UPPERCASE`, -/// `PascalCase`, `camelCase`, `snake_case`, `SCREAMING_SNAKE_CASE`, -/// `kebab-case`, and `SCREAMING-KEBAB-CASE`. +/// 1. `#[command(rename_rule = "rule")]` Rename all commands by `rule`. +/// Allowed rules are `lowercase`, `UPPERCASE`, `PascalCase`, `camelCase`, +/// `snake_case`, `SCREAMING_SNAKE_CASE`, `kebab-case`, and +/// `SCREAMING-KEBAB-CASE`. /// -/// 2. `#[command(prefix = "prefix")]` -/// Change a prefix for all commands (the default is `/`). +/// 2. `#[command(prefix = "prefix")]` Change a prefix for all commands (the +/// default is `/`). /// -/// 3. `#[command(description = "description")]` and `/// description` -/// Add a summary description of commands before all commands. +/// 3. `#[command(description = "description")]` and `/// description` Add a +/// summary description of commands before all commands. /// -/// 4. `#[command(parse_with = "parser")]` -/// Change the parser of arguments. Possible values: -/// - `default` - the same as the unspecified parser. It only puts all text -/// after the first space into the first argument, which must implement -/// [`FromStr`]. +/// 4. `#[command(parse_with = "parser")]` Change the parser of arguments. +/// Possible values: +/// - `default` - the same as the unspecified parser. It only puts all +/// text after the first space into the first argument, which must +/// implement [`FromStr`]. /// /// ## Example /// ``` @@ -134,9 +134,8 @@ pub use teloxide_macros::BotCommands; /// # } /// ``` /// -/// 5. `#[command(separator = "sep")]` -/// Specify separator used by the `split` parser. It will be ignored when -/// accompanied by another type of parsers. +/// 5. `#[command(separator = "sep")]` Specify separator used by the `split` +/// parser. It will be ignored when accompanied by another type of parsers. /// /// ## Example /// ``` @@ -154,8 +153,8 @@ pub use teloxide_macros::BotCommands; /// # } /// ``` /// -/// 6. `#[command(command_separator = "sep")]` -/// Specify separator between command and args. Default is a space character. +/// 6. `#[command(command_separator = "sep")]` Specify separator between command +/// and args. Default is a space character. /// /// ## Example /// ``` @@ -181,34 +180,33 @@ pub use teloxide_macros::BotCommands; /// # Variant attributes /// All variant attributes override the corresponding `enum` attributes. /// -/// 1. `#[command(rename_rule = "rule")]` -/// Rename one command by a rule. Allowed rules are `lowercase`, `UPPERCASE`, -/// `PascalCase`, `camelCase`, `snake_case`, `SCREAMING_SNAKE_CASE`, -/// `kebab-case`, `SCREAMING-KEBAB-CASE`. +/// 1. `#[command(rename_rule = "rule")]` Rename one command by a rule. Allowed +/// rules are `lowercase`, `UPPERCASE`, `PascalCase`, `camelCase`, +/// `snake_case`, `SCREAMING_SNAKE_CASE`, `kebab-case`, +/// `SCREAMING-KEBAB-CASE`. /// -/// 2. `#[command(rename = "name")]` -/// Rename one command to `name` (literal renaming; do not confuse with -/// `rename_rule`). +/// 2. `#[command(rename = "name")]` Rename one command to `name` (literal +/// renaming; do not confuse with `rename_rule`). /// -/// 3. `#[command(description = "description")]` and `/// description` -/// Give your command a description. It will be shown in the help message. +/// 3. `#[command(description = "description")]` and `/// description` Give +/// your command a description. It will be shown in the help message. /// -/// 4. `#[command(parse_with = "parser")]` -/// Parse arguments of one command with a given parser. `parser` must be a -/// function of the signature `fn(String) -> Result`, where -/// `Tuple` corresponds to the variant's arguments. +/// 4. `#[command(parse_with = "parser")]` Parse arguments of one command with +/// a given parser. `parser` must be a function of the signature `fn(String) +/// -> Result`, where `Tuple` corresponds to the +/// variant's arguments. /// -/// 5. `#[command(hide)]` -/// Hide a command from the help message. It will still be parsed. +/// 5. `#[command(hide)]` Hide a command from the help message. It will still +/// be parsed. /// -/// 6. `#[command(alias = "alias")]` -/// Add an alias to a command. It will be shown in the help message. +/// 6. `#[command(alias = "alias")]` Add an alias to a command. It will be shown +/// in the help message. /// -/// 7. `#[command(aliases = ["alias1", "alias2"])]` -/// Add multiple aliases to a command. They will be shown in the help message. +/// 7. `#[command(aliases = ["alias1", "alias2"])]` Add multiple aliases to a +/// command. They will be shown in the help message. /// -/// 8. `#[command(hide_aliases)]` -/// Hide all aliases of a command from the help message. +/// 8. `#[command(hide_aliases)]` Hide all aliases of a command from the help +/// message. /// /// ## Example /// ``` diff --git a/rust-toolchain.toml b/rust-toolchain.toml index d07466f2..43651f30 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-03-20" +channel = "nightly-2024-07-03" components = ["rustfmt", "clippy"] profile = "minimal"