lint: fix errors for rust 2018 idioms

This commit is contained in:
Weihang Lo 2023-09-12 12:01:34 +08:00
parent 85a3e9ace0
commit aef3bd22d3
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
12 changed files with 39 additions and 40 deletions

View File

@ -21,7 +21,7 @@ pub enum ParseErrorKind {
} }
impl fmt::Display for ParseError { impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"failed to parse `{}` as a cfg expression: {}", "failed to parse `{}` as a cfg expression: {}",
@ -31,7 +31,7 @@ impl fmt::Display for ParseError {
} }
impl fmt::Display for ParseErrorKind { impl fmt::Display for ParseErrorKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use ParseErrorKind::*; use ParseErrorKind::*;
match self { match self {
UnterminatedString => write!(f, "unterminated string in cfg"), UnterminatedString => write!(f, "unterminated string in cfg"),

View File

@ -1,5 +1,3 @@
extern crate proc_macro;
use proc_macro::*; use proc_macro::*;
use std::process::Command; use std::process::Command;
use std::sync::Once; use std::sync::Once;

View File

@ -790,7 +790,7 @@ impl HttpServer {
} }
} }
fn check_authorized(&self, req: &Request, mutation: Option<Mutation>) -> bool { fn check_authorized(&self, req: &Request, mutation: Option<Mutation<'_>>) -> bool {
let (private_key, private_key_subject) = if mutation.is_some() || self.auth_required { let (private_key, private_key_subject) = if mutation.is_some() || self.auth_required {
match &self.token { match &self.token {
Token::Plaintext(token) => return Some(token) == req.authorization.as_ref(), Token::Plaintext(token) => return Some(token) == req.authorization.as_ref(),
@ -832,7 +832,8 @@ impl HttpServer {
url: &'a str, url: &'a str,
kip: &'a str, kip: &'a str,
} }
let footer: Footer = t!(serde_json::from_slice(untrusted_token.untrusted_footer()).ok()); let footer: Footer<'_> =
t!(serde_json::from_slice(untrusted_token.untrusted_footer()).ok());
if footer.kip != paserk_pub_key_id { if footer.kip != paserk_pub_key_id {
return false; return false;
} }
@ -861,7 +862,7 @@ impl HttpServer {
_challenge: Option<&'a str>, // todo: PASETO with challenges _challenge: Option<&'a str>, // todo: PASETO with challenges
v: Option<u8>, v: Option<u8>,
} }
let message: Message = t!(serde_json::from_str(trusted_token.payload()).ok()); let message: Message<'_> = t!(serde_json::from_str(trusted_token.payload()).ok());
let token_time = t!(OffsetDateTime::parse(message.iat, &Rfc3339).ok()); let token_time = t!(OffsetDateTime::parse(message.iat, &Rfc3339).ok());
let now = OffsetDateTime::now_utc(); let now = OffsetDateTime::now_utc();
if (now - token_time) > Duration::MINUTE { if (now - token_time) > Duration::MINUTE {

View File

@ -12,7 +12,7 @@ use std::path::Path;
type FormatterRef<'a> = &'a (dyn Formatter + Send + Sync); type FormatterRef<'a> = &'a (dyn Formatter + Send + Sync);
/// Processes the handlebars template at the given file. /// Processes the handlebars template at the given file.
pub fn expand(file: &Path, formatter: FormatterRef) -> Result<String, Error> { pub fn expand(file: &Path, formatter: FormatterRef<'_>) -> Result<String, Error> {
let mut handlebars = Handlebars::new(); let mut handlebars = Handlebars::new();
handlebars.set_strict_mode(true); handlebars.set_strict_mode(true);
handlebars.register_helper("lower", Box::new(lower)); handlebars.register_helper("lower", Box::new(lower));
@ -174,10 +174,10 @@ impl HelperDef for ManLinkHelper<'_> {
/// ///
/// This sets a variable to a value within the template context. /// This sets a variable to a value within the template context.
fn set_decorator( fn set_decorator(
d: &Decorator, d: &Decorator<'_, '_>,
_: &Handlebars, _: &Handlebars<'_>,
_ctx: &Context, _ctx: &Context,
rc: &mut RenderContext, rc: &mut RenderContext<'_, '_>,
) -> Result<(), RenderError> { ) -> Result<(), RenderError> {
let data_to_set = d.hash(); let data_to_set = d.hash();
for (k, v) in data_to_set { for (k, v) in data_to_set {
@ -187,7 +187,7 @@ fn set_decorator(
} }
/// Sets a variable to a value within the context. /// Sets a variable to a value within the context.
fn set_in_context(rc: &mut RenderContext, key: &str, value: serde_json::Value) { fn set_in_context(rc: &mut RenderContext<'_, '_>, key: &str, value: serde_json::Value) {
let mut ctx = match rc.context() { let mut ctx = match rc.context() {
Some(c) => (*c).clone(), Some(c) => (*c).clone(),
None => Context::wraps(serde_json::Value::Object(serde_json::Map::new())).unwrap(), None => Context::wraps(serde_json::Value::Object(serde_json::Map::new())).unwrap(),
@ -201,7 +201,7 @@ fn set_in_context(rc: &mut RenderContext, key: &str, value: serde_json::Value) {
} }
/// Removes a variable from the context. /// Removes a variable from the context.
fn remove_from_context(rc: &mut RenderContext, key: &str) { fn remove_from_context(rc: &mut RenderContext<'_, '_>, key: &str) {
let ctx = rc.context().expect("cannot remove from null context"); let ctx = rc.context().expect("cannot remove from null context");
let mut ctx = (*ctx).clone(); let mut ctx = (*ctx).clone();
if let serde_json::Value::Object(m) = ctx.data_mut() { if let serde_json::Value::Object(m) = ctx.data_mut() {

View File

@ -64,7 +64,7 @@ pub fn convert(
type EventIter<'a> = Box<dyn Iterator<Item = (Event<'a>, Range<usize>)> + 'a>; type EventIter<'a> = Box<dyn Iterator<Item = (Event<'a>, Range<usize>)> + 'a>;
/// Creates a new markdown parser with the given input. /// Creates a new markdown parser with the given input.
pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter { pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter<'_> {
let mut options = Options::empty(); let mut options = Options::empty();
options.insert(Options::ENABLE_TABLES); options.insert(Options::ENABLE_TABLES);
options.insert(Options::ENABLE_FOOTNOTES); options.insert(Options::ENABLE_FOOTNOTES);

View File

@ -105,7 +105,7 @@ fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult {
/// Main entry of `xtask-bump-check`. /// Main entry of `xtask-bump-check`.
/// ///
/// Assumption: version number are incremental. We never have point release for old versions. /// Assumption: version number are incremental. We never have point release for old versions.
fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> CargoResult<()> { fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoResult<()> {
let ws = args.workspace(config)?; let ws = args.workspace(config)?;
let repo = git2::Repository::open(ws.root())?; let repo = git2::Repository::open(ws.root())?;
let base_commit = get_base_commit(config, args, &repo)?; let base_commit = get_base_commit(config, args, &repo)?;
@ -184,7 +184,7 @@ fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> Carg
status("no version bump needed for member crates.")?; status("no version bump needed for member crates.")?;
return Ok(()); Ok(())
} }
/// Returns the commit of upstream `master` branch if `base-rev` is missing. /// Returns the commit of upstream `master` branch if `base-rev` is missing.
@ -256,7 +256,7 @@ fn get_referenced_commit<'a>(
repo: &'a git2::Repository, repo: &'a git2::Repository,
base: &git2::Commit<'a>, base: &git2::Commit<'a>,
) -> CargoResult<Option<git2::Commit<'a>>> { ) -> CargoResult<Option<git2::Commit<'a>>> {
let [beta, stable] = beta_and_stable_branch(&repo)?; let [beta, stable] = beta_and_stable_branch(repo)?;
let rev_id = base.id(); let rev_id = base.id();
let stable_commit = stable.get().peel_to_commit()?; let stable_commit = stable.get().peel_to_commit()?;
let beta_commit = beta.get().peel_to_commit()?; let beta_commit = beta.get().peel_to_commit()?;

View File

@ -255,8 +255,8 @@ pub struct OnePasswordCredential {}
impl Credential for OnePasswordCredential { impl Credential for OnePasswordCredential {
fn perform( fn perform(
&self, &self,
registry: &RegistryInfo, registry: &RegistryInfo<'_>,
action: &Action, action: &Action<'_>,
args: &[&str], args: &[&str],
) -> Result<CredentialResponse, Error> { ) -> Result<CredentialResponse, Error> {
let op = OnePasswordKeychain::new(args)?; let op = OnePasswordKeychain::new(args)?;

View File

@ -104,16 +104,16 @@ mod linux {
impl Credential for LibSecretCredential { impl Credential for LibSecretCredential {
fn perform( fn perform(
&self, &self,
registry: &RegistryInfo, registry: &RegistryInfo<'_>,
action: &Action, action: &Action<'_>,
_args: &[&str], _args: &[&str],
) -> Result<CredentialResponse, Error> { ) -> Result<CredentialResponse, Error> {
// Dynamically load libsecret to avoid users needing to install // Dynamically load libsecret to avoid users needing to install
// additional -dev packages when building this provider. // additional -dev packages when building this provider.
let lib; let lib;
let secret_password_lookup_sync: Symbol<SecretPasswordLookupSync>; let secret_password_lookup_sync: Symbol<'_, SecretPasswordLookupSync>;
let secret_password_store_sync: Symbol<SecretPasswordStoreSync>; let secret_password_store_sync: Symbol<'_, SecretPasswordStoreSync>;
let secret_password_clear_sync: Symbol<SecretPasswordClearSync>; let secret_password_clear_sync: Symbol<'_, SecretPasswordClearSync>;
unsafe { unsafe {
lib = Library::new("libsecret-1.so").context( lib = Library::new("libsecret-1.so").context(
"failed to load libsecret: try installing the `libsecret` \ "failed to load libsecret: try installing the `libsecret` \

View File

@ -38,8 +38,8 @@ mod win {
impl Credential for WindowsCredential { impl Credential for WindowsCredential {
fn perform( fn perform(
&self, &self,
registry: &RegistryInfo, registry: &RegistryInfo<'_>,
action: &Action, action: &Action<'_>,
_args: &[&str], _args: &[&str],
) -> Result<CredentialResponse, Error> { ) -> Result<CredentialResponse, Error> {
match action { match action {

View File

@ -12,8 +12,8 @@ struct FileCredential;
impl Credential for FileCredential { impl Credential for FileCredential {
fn perform( fn perform(
&self, &self,
registry: &RegistryInfo, registry: &RegistryInfo<'_>,
action: &Action, action: &Action<'_>,
_args: &[&str], _args: &[&str],
) -> Result<CredentialResponse, cargo_credential::Error> { ) -> Result<CredentialResponse, cargo_credential::Error> {
if registry.index_url != "https://github.com/rust-lang/crates.io-index" { if registry.index_url != "https://github.com/rust-lang/crates.io-index" {

View File

@ -7,8 +7,8 @@ struct MyCredential;
impl Credential for MyCredential { impl Credential for MyCredential {
fn perform( fn perform(
&self, &self,
_registry: &RegistryInfo, _registry: &RegistryInfo<'_>,
_action: &Action, _action: &Action<'_>,
_args: &[&str], _args: &[&str],
) -> Result<CredentialResponse, Error> { ) -> Result<CredentialResponse, Error> {
// Informational messages should be sent on stderr. // Informational messages should be sent on stderr.

View File

@ -61,8 +61,8 @@ pub struct UnsupportedCredential;
impl Credential for UnsupportedCredential { impl Credential for UnsupportedCredential {
fn perform( fn perform(
&self, &self,
_registry: &RegistryInfo, _registry: &RegistryInfo<'_>,
_action: &Action, _action: &Action<'_>,
_args: &[&str], _args: &[&str],
) -> Result<CredentialResponse, Error> { ) -> Result<CredentialResponse, Error> {
Err(Error::UrlNotSupported) Err(Error::UrlNotSupported)
@ -215,8 +215,8 @@ pub trait Credential {
/// Retrieves a token for the given registry. /// Retrieves a token for the given registry.
fn perform( fn perform(
&self, &self,
registry: &RegistryInfo, registry: &RegistryInfo<'_>,
action: &Action, action: &Action<'_>,
args: &[&str], args: &[&str],
) -> Result<CredentialResponse, Error>; ) -> Result<CredentialResponse, Error>;
} }
@ -260,7 +260,7 @@ fn doit(
fn deserialize_request( fn deserialize_request(
value: &str, value: &str,
) -> Result<CredentialRequest<'_>, Box<dyn std::error::Error + Send + Sync>> { ) -> Result<CredentialRequest<'_>, Box<dyn std::error::Error + Send + Sync>> {
let request: CredentialRequest = serde_json::from_str(&value)?; let request: CredentialRequest<'_> = serde_json::from_str(&value)?;
if request.v != PROTOCOL_VERSION_1 { if request.v != PROTOCOL_VERSION_1 {
return Err(format!("unsupported protocol version {}", request.v).into()); return Err(format!("unsupported protocol version {}", request.v).into());
} }
@ -276,8 +276,8 @@ pub fn read_line() -> Result<String, io::Error> {
/// Prompt the user for a token. /// Prompt the user for a token.
pub fn read_token( pub fn read_token(
login_options: &LoginOptions, login_options: &LoginOptions<'_>,
registry: &RegistryInfo, registry: &RegistryInfo<'_>,
) -> Result<Secret<String>, Error> { ) -> Result<Secret<String>, Error> {
if let Some(token) = &login_options.token { if let Some(token) = &login_options.token {
return Ok(token.to_owned()); return Ok(token.to_owned());
@ -387,7 +387,7 @@ mod tests {
r#"{"v":1,"registry":{"index-url":"url"},"kind":"get","operation":"owners","name":"pkg"}"# r#"{"v":1,"registry":{"index-url":"url"},"kind":"get","operation":"owners","name":"pkg"}"#
); );
let cr: CredentialRequest = let cr: CredentialRequest<'_> =
serde_json::from_str(r#"{"extra-1":true,"v":1,"registry":{"index-url":"url","extra-2":true},"kind":"get","operation":"owners","name":"pkg","args":[]}"#).unwrap(); serde_json::from_str(r#"{"extra-1":true,"v":1,"registry":{"index-url":"url","extra-2":true},"kind":"get","operation":"owners","name":"pkg","args":[]}"#).unwrap();
assert_eq!(cr, get_oweners); assert_eq!(cr, get_oweners);
} }
@ -405,7 +405,7 @@ mod tests {
action: Action::Logout, action: Action::Logout,
}; };
let cr: CredentialRequest = serde_json::from_str( let cr: CredentialRequest<'_> = serde_json::from_str(
r#"{"v":1,"registry":{"index-url":"url"},"kind":"logout","extra-1":true,"args":[]}"#, r#"{"v":1,"registry":{"index-url":"url"},"kind":"logout","extra-1":true,"args":[]}"#,
) )
.unwrap(); .unwrap();
@ -425,7 +425,7 @@ mod tests {
action: Action::Unknown, action: Action::Unknown,
}; };
let cr: CredentialRequest = serde_json::from_str( let cr: CredentialRequest<'_> = serde_json::from_str(
r#"{"v":1,"registry":{"index-url":""},"kind":"unexpected-1","extra-1":true,"args":[]}"#, r#"{"v":1,"registry":{"index-url":""},"kind":"unexpected-1","extra-1":true,"args":[]}"#,
) )
.unwrap(); .unwrap();