Merge pull request #804 from teloxide/docccc

Fix documentation build
This commit is contained in:
Waffle Maybe 2022-12-29 14:09:25 +04:00 committed by GitHub
commit b826c3a34b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 71 additions and 63 deletions

View file

@ -4,7 +4,7 @@
#
# "tokio/macros" and "tokio/rt-multi-thread" are required for examples
docs = """doc
-Zrustdoc-scrape-examples=examples
-Zrustdoc-scrape-examples
--features=full --features=nightly
--features=tokio/macros --features=tokio/rt-multi-thread
"""

View file

@ -18,7 +18,7 @@ env:
# When updating this, also update:
# - crates/teloxide-core/src/codegen.rs
# - rust-toolchain.toml
rust_nightly: nightly-2022-09-23
rust_nightly: nightly-2022-12-23
# When updating this, also update:
# - **/README.md
# - **/src/lib.rs
@ -87,7 +87,7 @@ jobs:
toolchain: beta
features: "--features full"
- rust: nightly
toolchain: nightly-2022-09-23
toolchain: nightly-2022-12-23
features: "--all-features"
- rust: msrv
toolchain: 1.64.0

View file

@ -94,13 +94,18 @@ features = ["full", "nightly", "tokio/macros", "tokio/rt-multi-thread"]
rustdoc-args = ["--cfg", "docsrs", "-Znormalize-docs"]
# https://github.com/rust-lang/rust/issues/88791
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
[[example]]
name = "self_info"
required-features = ["tokio/macros", "tokio/rt-multi-thread"]
# This is required due to some stuff with dev-dependencies,
# backwards compatability and cargo:
# https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#scrape-examples
doc-scrape-examples = true
[[example]]
name = "erased"
required-features = ["tokio/macros", "tokio/rt-multi-thread", "erased", "trace_adaptor"]

View file

@ -183,8 +183,8 @@ pub(super) async fn worker<B>(
// (waffle)
let now = Instant::now();
let min_back = now - MINUTE;
let sec_back = now - SECOND;
let min_back = now.checked_sub(MINUTE).unwrap_or(now);
let sec_back = now.checked_sub(SECOND).unwrap_or(now);
// make history and requests_sent up-to-date
while let Some((_, time)) = history.front() {

View file

@ -293,5 +293,5 @@ impl Bot {
}
fn get_env(env: &'static str) -> String {
std::env::var(env).unwrap_or_else(|_| panic!("Cannot get the {} env variable", env))
std::env::var(env).unwrap_or_else(|_| panic!("Cannot get the {env} env variable"))
}

View file

@ -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-2022-09-23";
let toolchain = "nightly-2022-12-23";
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-2022-09-23";
let toolchain = "nightly-2022-12-23";
let sh = Shell::new().unwrap();
ensure_rustfmt(&sh);

View file

@ -188,7 +188,7 @@ impl Doc {
link.clear();
*link += *value;
} else if key.is_exact() {
panic!("Patch error: {:?} doesn't have link {}", key, name);
panic!("Patch error: {key:?} doesn't have link {name}");
}
}
Patch::AddLink { name, value } => {
@ -228,7 +228,7 @@ fn intra_links(doc: &mut Doc) {
}
_ => {
repls_t.push(k.clone());
*v = format!("crate::types::{}", k);
*v = format!("crate::types::{k}");
}
}
}
@ -236,23 +236,23 @@ fn intra_links(doc: &mut Doc) {
for repl in repls_t {
if let Some(value) = doc.md_links.remove(repl.as_str()) {
doc.md = doc.md.replace(format!("[{}]", repl).as_str(), &format!("[`{}`]", repl));
doc.md_links.insert(format!("`{}`", repl), value);
doc.md = doc.md.replace(format!("[{repl}]").as_str(), &format!("[`{repl}`]"));
doc.md_links.insert(format!("`{repl}`"), value);
}
}
for repl in repls_m {
if let Some(value) = doc.md_links.remove(repl.as_str()) {
let repln = to_uppercase(&repl);
doc.md = doc.md.replace(format!("[{}]", repl).as_str(), &format!("[`{}`]", repln));
doc.md_links.insert(format!("`{}`", repln), value);
doc.md = doc.md.replace(format!("[{repl}]").as_str(), &format!("[`{repln}`]"));
doc.md_links.insert(format!("`{repln}`"), value);
}
}
}
fn escape_kw(s: &mut String) {
if ["type"].contains(&s.as_str()) {
*s = format!("{}_", s);
*s = format!("{s}_");
}
}
@ -309,7 +309,7 @@ fn patch_types(schema: &mut Schema, from: Type, to: Type, list: &[(&str, &str)])
.find(|p| p.name == param)
.expect("Couldn't find parameter for patching");
assert_eq!(p.ty, from, "{}::{}", method, param);
assert_eq!(p.ty, from, "{method}::{param}");
p.ty = to.clone();
}
}

View file

@ -97,8 +97,8 @@ impl std::fmt::Display for Type {
Type::f64 => write!(f, "f64"),
Type::bool => write!(f, "bool"),
Type::String => write!(f, "String"),
Type::Option(inner) => write!(f, "Option<{}>", inner),
Type::ArrayOf(inner) => write!(f, "Vec<{}>", inner),
Type::Option(inner) => write!(f, "Option<{inner}>"),
Type::ArrayOf(inner) => write!(f, "Vec<{inner}>"),
Type::RawTy(raw) => f.write_str(raw),
Type::Url => write!(f, "Url"),
Type::DateTime => write!(f, "DateTime<Utc>"),

View file

@ -132,6 +132,8 @@ macro_rules! impl_payload {
$vi struct $Method {
$(
$(
// FIXME: fix the cause of this warning
#[allow(rustdoc::invalid_html_tags)]
$(
#[ $($field_meta)* ]
)*
@ -1365,12 +1367,12 @@ fn codegen_requester_forward() {
.join(",\n ");
let generics =
if generics.is_empty() { String::from("") } else { format!("<{}>", generics) };
if generics.is_empty() { String::from("") } else { format!("<{generics}>") };
let where_clause = if where_clause.is_empty() {
String::from("")
} else {
format!(" where {}", where_clause)
format!(" where {where_clause}")
};
format!(

View file

@ -80,16 +80,14 @@ pub fn default_reqwest_settings() -> reqwest::ClientBuilder {
///
/// [Telegram documentation]: https://core.telegram.org/bots/api#making-requests
fn method_url(base: reqwest::Url, token: &str, method_name: &str) -> reqwest::Url {
base.join(&format!("/bot{token}/{method}", token = token, method = method_name))
.expect("failed to format url")
base.join(&format!("/bot{token}/{method_name}")).expect("failed to format url")
}
/// Creates URL for downloading a file. See the [Telegram documentation].
///
/// [Telegram documentation]: https://core.telegram.org/bots/api#file
fn file_url(base: reqwest::Url, token: &str, file_path: &str) -> reqwest::Url {
base.join(&format!("file/bot{token}/{file}", token = token, file = file_path))
.expect("failed to format url")
base.join(&format!("file/bot{token}/{file_path}")).expect("failed to format url")
}
#[cfg(test)]

View file

@ -1368,12 +1368,12 @@ fn codegen_requester_methods() {
.join(",\n ");
let generics =
if generics.is_empty() { String::from("") } else { format!("<{}>", generics) };
if generics.is_empty() { String::from("") } else { format!("<{generics}>") };
let where_clause = if where_clause.is_empty() {
String::from("")
} else {
format!(" where {}", where_clause)
format!(" where {where_clause}")
};
format!(

View file

@ -25,11 +25,11 @@ impl ser::Error for Error {
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Custom(s) => write!(f, "Custom serde error: {}", s),
Self::Custom(s) => write!(f, "Custom serde error: {s}"),
Self::TopLevelNotStruct => write!(f, "Multipart supports only structs at top level"),
Self::Fmt(inner) => write!(f, "Formatting error: {}", inner),
Self::Io(inner) => write!(f, "Io error: {}", inner),
Self::Json(inner) => write!(f, "Json (de)serialization error: {}", inner),
Self::Fmt(inner) => write!(f, "Formatting error: {inner}"),
Self::Io(inner) => write!(f, "Io error: {inner}"),
Self::Json(inner) => write!(f, "Json (de)serialization error: {inner}"),
}
}
}

View file

@ -472,9 +472,9 @@ impl SerializeStruct for JsonPartSerializer {
Empty => {
self.state = Rest;
write!(&mut self.buf, "{{\"{}\":{}", key, value)?
write!(&mut self.buf, "{{\"{key}\":{value}")?
}
Rest => write!(&mut self.buf, ",\"{}\":{}", key, value)?,
Rest => write!(&mut self.buf, ",\"{key}\":{value}")?,
}
Ok(())
@ -511,9 +511,9 @@ impl SerializeSeq for JsonPartSerializer {
Empty => {
self.state = Rest;
write!(&mut self.buf, "[{}", value)?
write!(&mut self.buf, "[{value}")?
}
Rest => write!(&mut self.buf, ",{}", value)?,
Rest => write!(&mut self.buf, ",{value}")?,
}
Ok(())

View file

@ -62,7 +62,7 @@ impl ChatId {
Channel((MAX_MARKED_CHANNEL_ID - id) as _)
}
id @ MIN_USER_ID..=MAX_USER_ID => User(UserId(id as _)),
id => panic!("malformed chat id: {}", id),
id => panic!("malformed chat id: {id}"),
}
}
}

View file

@ -77,7 +77,7 @@ mod tests {
use super::*;
fn url(n: u32) -> reqwest::Url {
reqwest::Url::parse(&format!("https://example.com/{n}", n = n)).unwrap()
reqwest::Url::parse(&format!("https://example.com/{n}")).unwrap()
}
#[test]

View file

@ -11,11 +11,11 @@ use crate::types::{ChatId, UserId};
#[serde(untagged)]
pub enum Recipient {
/// A chat identifier.
#[display(fmt = "{}", _0)]
#[display(fmt = "{_0}")]
Id(ChatId),
/// A channel username (in the format @channelusername).
#[display(fmt = "{}", _0)]
#[display(fmt = "{_0}")]
ChannelUsername(String),
}

View file

@ -13,7 +13,7 @@ impl UserId {
/// `tg://user/?id=<...>`.
#[must_use]
pub fn url(self) -> reqwest::Url {
reqwest::Url::parse(&format!("tg://user/?id={}", self)).unwrap()
reqwest::Url::parse(&format!("tg://user/?id={self}")).unwrap()
}
/// Returns `true` if this is the id of the special user used by telegram

View file

@ -122,7 +122,7 @@ all-features = true
# FIXME: Add back "-Znormalize-docs" when https://github.com/rust-lang/rust/issues/93703 is fixed
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "dep_docsrs"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples=examples"]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
[[test]]
@ -140,6 +140,11 @@ required-features = ["sqlite-storage", "cbor-serializer", "bincode-serializer"]
name = "admin"
required-features = ["macros", "ctrlc_handler"]
# This is required due to some stuff with dev-dependencies,
# backwards compatability and cargo:
# https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#scrape-examples
doc-scrape-examples = true
[[example]]
name = "buttons"
required-features = ["macros", "ctrlc_handler"]

View file

@ -39,7 +39,7 @@ impl<S> SqliteStorage<S> {
path: &str,
serializer: S,
) -> Result<Arc<Self>, SqliteStorageError<Infallible>> {
let pool = SqlitePool::connect(format!("sqlite:{}?mode=rwc", path).as_str()).await?;
let pool = SqlitePool::connect(format!("sqlite:{path}?mode=rwc").as_str()).await?;
let mut conn = pool.acquire().await?;
sqlx::query(
r#"

View file

@ -56,7 +56,7 @@ where
D: Send + 'static,
{
Box::pin(async move {
let to = format!("{:#?}", dialogue);
let to = format!("{dialogue:#?}");
<S as Storage<D>>::update_dialogue(self.inner.clone(), chat_id, dialogue).await?;
log::trace!("Updated a dialogue #{}: {:#?}", chat_id, to);
Ok(())

View file

@ -429,18 +429,16 @@ impl Display for ParseError {
match self {
ParseError::TooFewArguments { expected, found, message } => write!(
f,
"Too few arguments (expected {}, found {}, message = '{}')",
expected, found, message
"Too few arguments (expected {expected}, found {found}, message = '{message}')"
),
ParseError::TooManyArguments { expected, found, message } => write!(
f,
"Too many arguments (expected {}, found {}, message = '{}')",
expected, found, message
"Too many arguments (expected {expected}, found {found}, message = '{message}')"
),
ParseError::IncorrectFormat(e) => write!(f, "Incorrect format of command args: {}", e),
ParseError::UnknownCommand(e) => write!(f, "Unknown command: {}", e),
ParseError::WrongBotName(n) => write!(f, "Wrong bot name: {}", n),
ParseError::Custom(e) => write!(f, "{}", e),
ParseError::IncorrectFormat(e) => write!(f, "Incorrect format of command args: {e}"),
ParseError::UnknownCommand(e) => write!(f, "Unknown command: {e}"),
ParseError::WrongBotName(n) => write!(f, "Wrong bot name: {n}"),
ParseError::Custom(e) => write!(f, "{e}"),
}
}
}

View file

@ -11,7 +11,7 @@ use teloxide_core::types::User;
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn bold(s: &str) -> String {
format!("<b>{}</b>", s)
format!("<b>{s}</b>")
}
/// Applies the italic font style to the string.
@ -21,7 +21,7 @@ pub fn bold(s: &str) -> String {
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn italic(s: &str) -> String {
format!("<i>{}</i>", s)
format!("<i>{s}</i>")
}
/// Applies the underline font style to the string.
@ -31,7 +31,7 @@ pub fn italic(s: &str) -> String {
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn underline(s: &str) -> String {
format!("<u>{}</u>", s)
format!("<u>{s}</u>")
}
/// Applies the strikethrough font style to the string.
@ -41,7 +41,7 @@ pub fn underline(s: &str) -> String {
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn strike(s: &str) -> String {
format!("<s>{}</s>", s)
format!("<s>{s}</s>")
}
/// Builds an inline link with an anchor.
@ -57,7 +57,7 @@ pub fn link(url: &str, text: &str) -> String {
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn user_mention(user_id: i64, text: &str) -> String {
link(format!("tg://user?id={}", user_id).as_str(), text)
link(format!("tg://user?id={user_id}").as_str(), text)
}
/// Formats the code block.

View file

@ -11,7 +11,7 @@ use teloxide_core::types::User;
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn bold(s: &str) -> String {
format!("*{}*", s)
format!("*{s}*")
}
/// Applies the italic font style to the string.
@ -25,7 +25,7 @@ pub fn italic(s: &str) -> String {
if s.starts_with("__") && s.ends_with("__") {
format!(r"_{}\r__", &s[..s.len() - 1])
} else {
format!("_{}_", s)
format!("_{s}_")
}
}
@ -43,9 +43,9 @@ pub fn underline(s: &str) -> String {
// ___italic underline_\r__, where \r is a character with code 13, which
// will be ignored.
if s.starts_with('_') && s.ends_with('_') {
format!(r"__{}\r__", s)
format!(r"__{s}\r__")
} else {
format!("__{}__", s)
format!("__{s}__")
}
}
@ -56,7 +56,7 @@ pub fn underline(s: &str) -> String {
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn strike(s: &str) -> String {
format!("~{}~", s)
format!("~{s}~")
}
/// Builds an inline link with an anchor.
@ -72,7 +72,7 @@ pub fn link(url: &str, text: &str) -> String {
#[must_use = "This function returns a new string, rather than mutating the argument, so calling it \
without using its output does nothing useful"]
pub fn user_mention(user_id: i64, text: &str) -> String {
link(format!("tg://user?id={}", user_id).as_str(), text)
link(format!("tg://user?id={user_id}").as_str(), text)
}
/// Formats the code block.

View file

@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2022-09-23"
channel = "nightly-2022-12-23"
components = ["rustfmt", "clippy"]
profile = "minimal"