Skip to content

refactor: fix lint errors in preparation of [lints] table integration #12669

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
allow-print-in-tests = true
allow-dbg-in-tests = true
disallowed-methods = [
{ path = "std::env::var", reason = "Use `Config::get_env` instead. See rust-lang/cargo#11588" },
{ path = "std::env::var_os", reason = "Use `Config::get_env_os` instead. See rust-lang/cargo#11588" },
{ path = "std::env::vars", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
{ path = "std::env::vars_os", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
{ path = "std::env::var", reason = "use `Config::get_env` instead. See rust-lang/cargo#11588" },
{ path = "std::env::var_os", reason = "use `Config::get_env_os` instead. See rust-lang/cargo#11588" },
{ path = "std::env::vars", reason = "not recommended to use in Cargo. See rust-lang/cargo#11588" },
{ path = "std::env::vars_os", reason = "not recommended to use in Cargo. See rust-lang/cargo#11588" },
]
4 changes: 2 additions & 2 deletions crates/cargo-platform/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum ParseErrorKind {
}

impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"failed to parse `{}` as a cfg expression: {}",
Expand All @@ -31,7 +31,7 @@ impl fmt::Display for ParseError {
}

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::*;
match self {
UnterminatedString => write!(f, "unterminated string in cfg"),
Expand Down
2 changes: 0 additions & 2 deletions crates/cargo-test-macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro::*;
use std::process::Command;
use std::sync::Once;
Expand Down
14 changes: 4 additions & 10 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
match &self.token {
Token::Plaintext(token) => return Some(token) == req.authorization.as_ref(),
Expand Down Expand Up @@ -832,7 +832,8 @@ impl HttpServer {
url: &'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 {
return false;
}
Expand All @@ -846,7 +847,6 @@ impl HttpServer {
if footer.url != "https://github.com/rust-lang/crates.io-index"
&& footer.url != &format!("sparse+http://{}/index/", self.addr.to_string())
{
dbg!(footer.url);
return false;
}

Expand All @@ -862,20 +862,18 @@ impl HttpServer {
_challenge: Option<&'a str>, // todo: PASETO with challenges
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 now = OffsetDateTime::now_utc();
if (now - token_time) > Duration::MINUTE {
return false;
}
if private_key_subject.as_deref() != message.sub {
dbg!(message.sub);
return false;
}
// - If the claim v is set, that it has the value of 1.
if let Some(v) = message.v {
if v != 1 {
dbg!(message.v);
return false;
}
}
Expand All @@ -885,22 +883,18 @@ impl HttpServer {
if let Some(mutation) = mutation {
// - That the operation matches the mutation field and is one of publish, yank, or unyank.
if message.mutation != Some(mutation.mutation) {
dbg!(message.mutation);
return false;
}
// - That the package, and version match the request.
if message.name != mutation.name {
dbg!(message.name);
return false;
}
if message.vers != mutation.vers {
dbg!(message.vers);
return false;
}
// - If the mutation is publish, that the version has not already been published, and that the hash matches the request.
if mutation.mutation == "publish" {
if message.cksum != mutation.cksum {
dbg!(message.cksum);
return false;
}
}
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions crates/mdman/src/hbs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::path::Path;
type FormatterRef<'a> = &'a (dyn Formatter + Send + Sync);

/// 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();
handlebars.set_strict_mode(true);
handlebars.register_helper("lower", Box::new(lower));
Expand Down Expand Up @@ -174,10 +174,10 @@ impl HelperDef for ManLinkHelper<'_> {
///
/// This sets a variable to a value within the template context.
fn set_decorator(
d: &Decorator,
_: &Handlebars,
d: &Decorator<'_, '_>,
_: &Handlebars<'_>,
_ctx: &Context,
rc: &mut RenderContext,
rc: &mut RenderContext<'_, '_>,
) -> Result<(), RenderError> {
let data_to_set = d.hash();
for (k, v) in data_to_set {
Expand All @@ -187,7 +187,7 @@ fn set_decorator(
}

/// 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() {
Some(c) => (*c).clone(),
None => Context::wraps(serde_json::Value::Object(serde_json::Map::new())).unwrap(),
Expand All @@ -201,7 +201,7 @@ fn set_in_context(rc: &mut RenderContext, key: &str, value: serde_json::Value) {
}

/// 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 mut ctx = (*ctx).clone();
if let serde_json::Value::Object(m) = ctx.data_mut() {
Expand Down
2 changes: 1 addition & 1 deletion crates/mdman/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn convert(
type EventIter<'a> = Box<dyn Iterator<Item = (Event<'a>, Range<usize>)> + 'a>;

/// 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();
options.insert(Options::ENABLE_TABLES);
options.insert(Options::ENABLE_FOOTNOTES);
Expand Down
2 changes: 1 addition & 1 deletion crates/mdman/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn run() -> Result<(), Error> {
if same_file::is_same_file(source, &out_path).unwrap_or(false) {
bail!("cannot output to the same file as the source");
}
println!("Converting {} -> {}", source.display(), out_path.display());
eprintln!("Converting {} -> {}", source.display(), out_path.display());
let result = mdman::convert(&source, opts.format, opts.url.clone(), opts.man_map.clone())
.with_context(|| format!("failed to translate {}", source.display()))?;

Expand Down
2 changes: 1 addition & 1 deletion crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub fn resolve_with_config_raw(
if std::thread::panicking() && self.list.len() != self.used.len() {
// we found a case that causes a panic and did not use all of the input.
// lets print the part of the input that was used for minimization.
println!(
eprintln!(
"{:?}",
PrettyPrintRegistry(
self.list
Expand Down
4 changes: 2 additions & 2 deletions crates/semver-check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::process::{Command, Output};

fn main() {
if let Err(e) = doit() {
println!("error: {}", e);
eprintln!("error: {}", e);
std::process::exit(1);
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
result
};
let expect_success = parts[0][0].contains("MINOR");
println!("Running test from line {}", block_start);
eprintln!("Running test from line {}", block_start);

let result = run_test(
join(parts[1]),
Expand Down
6 changes: 3 additions & 3 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult {
/// Main entry of `xtask-bump-check`.
///
/// 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 repo = git2::Repository::open(ws.root())?;
let base_commit = get_base_commit(config, args, &repo)?;
Expand Down Expand Up @@ -184,7 +184,7 @@ fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> Carg

status("no version bump needed for member crates.")?;

return Ok(());
Ok(())
}

/// Returns the commit of upstream `master` branch if `base-rev` is missing.
Expand Down Expand Up @@ -256,7 +256,7 @@ fn get_referenced_commit<'a>(
repo: &'a git2::Repository,
base: &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 stable_commit = stable.get().peel_to_commit()?;
let beta_commit = beta.get().peel_to_commit()?;
Expand Down
4 changes: 2 additions & 2 deletions credential/cargo-credential-1password/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ pub struct OnePasswordCredential {}
impl Credential for OnePasswordCredential {
fn perform(
&self,
registry: &RegistryInfo,
action: &Action,
registry: &RegistryInfo<'_>,
action: &Action<'_>,
args: &[&str],
) -> Result<CredentialResponse, Error> {
let op = OnePasswordKeychain::new(args)?;
Expand Down
2 changes: 1 addition & 1 deletion credential/cargo-credential-libsecret/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-credential-libsecret"
version = "0.3.1"
version = "0.3.2"
edition.workspace = true
license.workspace = true
repository = "https://github.com/rust-lang/cargo"
Expand Down
10 changes: 5 additions & 5 deletions credential/cargo-credential-libsecret/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ mod linux {
impl Credential for LibSecretCredential {
fn perform(
&self,
registry: &RegistryInfo,
action: &Action,
registry: &RegistryInfo<'_>,
action: &Action<'_>,
_args: &[&str],
) -> Result<CredentialResponse, Error> {
// Dynamically load libsecret to avoid users needing to install
// additional -dev packages when building this provider.
let lib;
let secret_password_lookup_sync: Symbol<SecretPasswordLookupSync>;
let secret_password_store_sync: Symbol<SecretPasswordStoreSync>;
let secret_password_clear_sync: Symbol<SecretPasswordClearSync>;
let secret_password_lookup_sync: Symbol<'_, SecretPasswordLookupSync>;
let secret_password_store_sync: Symbol<'_, SecretPasswordStoreSync>;
let secret_password_clear_sync: Symbol<'_, SecretPasswordClearSync>;
unsafe {
lib = Library::new("libsecret-1.so").context(
"failed to load libsecret: try installing the `libsecret` \
Expand Down
2 changes: 1 addition & 1 deletion credential/cargo-credential-wincred/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-credential-wincred"
version = "0.3.0"
version = "0.3.1"
edition.workspace = true
license.workspace = true
repository = "https://github.com/rust-lang/cargo"
Expand Down
4 changes: 2 additions & 2 deletions credential/cargo-credential-wincred/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ mod win {
impl Credential for WindowsCredential {
fn perform(
&self,
registry: &RegistryInfo,
action: &Action,
registry: &RegistryInfo<'_>,
action: &Action<'_>,
_args: &[&str],
) -> Result<CredentialResponse, Error> {
match action {
Expand Down
4 changes: 2 additions & 2 deletions credential/cargo-credential/examples/file-provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct FileCredential;
impl Credential for FileCredential {
fn perform(
&self,
registry: &RegistryInfo,
action: &Action,
registry: &RegistryInfo<'_>,
action: &Action<'_>,
_args: &[&str],
) -> Result<CredentialResponse, cargo_credential::Error> {
if registry.index_url != "https://github.com/rust-lang/crates.io-index" {
Expand Down
4 changes: 2 additions & 2 deletions credential/cargo-credential/examples/stdout-redirected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ struct MyCredential;
impl Credential for MyCredential {
fn perform(
&self,
_registry: &RegistryInfo,
_action: &Action,
_registry: &RegistryInfo<'_>,
_action: &Action<'_>,
_args: &[&str],
) -> Result<CredentialResponse, Error> {
// Informational messages should be sent on stderr.
Expand Down
20 changes: 10 additions & 10 deletions credential/cargo-credential/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub struct UnsupportedCredential;
impl Credential for UnsupportedCredential {
fn perform(
&self,
_registry: &RegistryInfo,
_action: &Action,
_registry: &RegistryInfo<'_>,
_action: &Action<'_>,
_args: &[&str],
) -> Result<CredentialResponse, Error> {
Err(Error::UrlNotSupported)
Expand Down Expand Up @@ -215,8 +215,8 @@ pub trait Credential {
/// Retrieves a token for the given registry.
fn perform(
&self,
registry: &RegistryInfo,
action: &Action,
registry: &RegistryInfo<'_>,
action: &Action<'_>,
args: &[&str],
) -> Result<CredentialResponse, Error>;
}
Expand Down Expand Up @@ -260,7 +260,7 @@ fn doit(
fn deserialize_request(
value: &str,
) -> 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 {
return Err(format!("unsupported protocol version {}", request.v).into());
}
Expand All @@ -276,8 +276,8 @@ pub fn read_line() -> Result<String, io::Error> {

/// Prompt the user for a token.
pub fn read_token(
login_options: &LoginOptions,
registry: &RegistryInfo,
login_options: &LoginOptions<'_>,
registry: &RegistryInfo<'_>,
) -> Result<Secret<String>, Error> {
if let Some(token) = &login_options.token {
return Ok(token.to_owned());
Expand Down Expand Up @@ -387,7 +387,7 @@ mod tests {
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();
assert_eq!(cr, get_oweners);
}
Expand All @@ -405,7 +405,7 @@ mod tests {
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":[]}"#,
)
.unwrap();
Expand All @@ -425,7 +425,7 @@ mod tests {
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":[]}"#,
)
.unwrap();
Expand Down
Loading