Skip to content

Commit 64642cc

Browse files
committed
Auto merge of #12669 - weihanglo:lint-refactor, r=epage
refactor: fix lint errors in preparation of `[lints]` table integration
2 parents 5c84ce0 + c4f9712 commit 64642cc

File tree

21 files changed

+65
-72
lines changed

21 files changed

+65
-72
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

clippy.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
allow-print-in-tests = true
22
allow-dbg-in-tests = true
33
disallowed-methods = [
4-
{ path = "std::env::var", reason = "Use `Config::get_env` instead. See rust-lang/cargo#11588" },
5-
{ path = "std::env::var_os", reason = "Use `Config::get_env_os` instead. See rust-lang/cargo#11588" },
6-
{ path = "std::env::vars", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
7-
{ path = "std::env::vars_os", reason = "Not recommended to use in Cargo. See rust-lang/cargo#11588" },
4+
{ path = "std::env::var", reason = "use `Config::get_env` instead. See rust-lang/cargo#11588" },
5+
{ path = "std::env::var_os", reason = "use `Config::get_env_os` instead. See rust-lang/cargo#11588" },
6+
{ path = "std::env::vars", reason = "not recommended to use in Cargo. See rust-lang/cargo#11588" },
7+
{ path = "std::env::vars_os", reason = "not recommended to use in Cargo. See rust-lang/cargo#11588" },
88
]

crates/cargo-platform/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub enum ParseErrorKind {
2121
}
2222

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

3333
impl fmt::Display for ParseErrorKind {
34-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
34+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3535
use ParseErrorKind::*;
3636
match self {
3737
UnterminatedString => write!(f, "unterminated string in cfg"),

crates/cargo-test-macro/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate proc_macro;
2-
31
use proc_macro::*;
42
use std::process::Command;
53
use std::sync::Once;

crates/cargo-test-support/src/registry.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl HttpServer {
790790
}
791791
}
792792

793-
fn check_authorized(&self, req: &Request, mutation: Option<Mutation>) -> bool {
793+
fn check_authorized(&self, req: &Request, mutation: Option<Mutation<'_>>) -> bool {
794794
let (private_key, private_key_subject) = if mutation.is_some() || self.auth_required {
795795
match &self.token {
796796
Token::Plaintext(token) => return Some(token) == req.authorization.as_ref(),
@@ -832,7 +832,8 @@ impl HttpServer {
832832
url: &'a str,
833833
kip: &'a str,
834834
}
835-
let footer: Footer = t!(serde_json::from_slice(untrusted_token.untrusted_footer()).ok());
835+
let footer: Footer<'_> =
836+
t!(serde_json::from_slice(untrusted_token.untrusted_footer()).ok());
836837
if footer.kip != paserk_pub_key_id {
837838
return false;
838839
}
@@ -846,7 +847,6 @@ impl HttpServer {
846847
if footer.url != "https://github.com/rust-lang/crates.io-index"
847848
&& footer.url != &format!("sparse+http://{}/index/", self.addr.to_string())
848849
{
849-
dbg!(footer.url);
850850
return false;
851851
}
852852

@@ -862,20 +862,18 @@ impl HttpServer {
862862
_challenge: Option<&'a str>, // todo: PASETO with challenges
863863
v: Option<u8>,
864864
}
865-
let message: Message = t!(serde_json::from_str(trusted_token.payload()).ok());
865+
let message: Message<'_> = t!(serde_json::from_str(trusted_token.payload()).ok());
866866
let token_time = t!(OffsetDateTime::parse(message.iat, &Rfc3339).ok());
867867
let now = OffsetDateTime::now_utc();
868868
if (now - token_time) > Duration::MINUTE {
869869
return false;
870870
}
871871
if private_key_subject.as_deref() != message.sub {
872-
dbg!(message.sub);
873872
return false;
874873
}
875874
// - If the claim v is set, that it has the value of 1.
876875
if let Some(v) = message.v {
877876
if v != 1 {
878-
dbg!(message.v);
879877
return false;
880878
}
881879
}
@@ -885,22 +883,18 @@ impl HttpServer {
885883
if let Some(mutation) = mutation {
886884
// - That the operation matches the mutation field and is one of publish, yank, or unyank.
887885
if message.mutation != Some(mutation.mutation) {
888-
dbg!(message.mutation);
889886
return false;
890887
}
891888
// - That the package, and version match the request.
892889
if message.name != mutation.name {
893-
dbg!(message.name);
894890
return false;
895891
}
896892
if message.vers != mutation.vers {
897-
dbg!(message.vers);
898893
return false;
899894
}
900895
// - If the mutation is publish, that the version has not already been published, and that the hash matches the request.
901896
if mutation.mutation == "publish" {
902897
if message.cksum != mutation.cksum {
903-
dbg!(message.cksum);
904898
return false;
905899
}
906900
}
File renamed without changes.

crates/mdman/src/hbs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::path::Path;
1212
type FormatterRef<'a> = &'a (dyn Formatter + Send + Sync);
1313

1414
/// Processes the handlebars template at the given file.
15-
pub fn expand(file: &Path, formatter: FormatterRef) -> Result<String, Error> {
15+
pub fn expand(file: &Path, formatter: FormatterRef<'_>) -> Result<String, Error> {
1616
let mut handlebars = Handlebars::new();
1717
handlebars.set_strict_mode(true);
1818
handlebars.register_helper("lower", Box::new(lower));
@@ -174,10 +174,10 @@ impl HelperDef for ManLinkHelper<'_> {
174174
///
175175
/// This sets a variable to a value within the template context.
176176
fn set_decorator(
177-
d: &Decorator,
178-
_: &Handlebars,
177+
d: &Decorator<'_, '_>,
178+
_: &Handlebars<'_>,
179179
_ctx: &Context,
180-
rc: &mut RenderContext,
180+
rc: &mut RenderContext<'_, '_>,
181181
) -> Result<(), RenderError> {
182182
let data_to_set = d.hash();
183183
for (k, v) in data_to_set {
@@ -187,7 +187,7 @@ fn set_decorator(
187187
}
188188

189189
/// Sets a variable to a value within the context.
190-
fn set_in_context(rc: &mut RenderContext, key: &str, value: serde_json::Value) {
190+
fn set_in_context(rc: &mut RenderContext<'_, '_>, key: &str, value: serde_json::Value) {
191191
let mut ctx = match rc.context() {
192192
Some(c) => (*c).clone(),
193193
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) {
201201
}
202202

203203
/// Removes a variable from the context.
204-
fn remove_from_context(rc: &mut RenderContext, key: &str) {
204+
fn remove_from_context(rc: &mut RenderContext<'_, '_>, key: &str) {
205205
let ctx = rc.context().expect("cannot remove from null context");
206206
let mut ctx = (*ctx).clone();
207207
if let serde_json::Value::Object(m) = ctx.data_mut() {

crates/mdman/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn convert(
6464
type EventIter<'a> = Box<dyn Iterator<Item = (Event<'a>, Range<usize>)> + 'a>;
6565

6666
/// Creates a new markdown parser with the given input.
67-
pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter {
67+
pub(crate) fn md_parser(input: &str, url: Option<Url>) -> EventIter<'_> {
6868
let mut options = Options::empty();
6969
options.insert(Options::ENABLE_TABLES);
7070
options.insert(Options::ENABLE_FOOTNOTES);

crates/mdman/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fn run() -> Result<(), Error> {
4848
if same_file::is_same_file(source, &out_path).unwrap_or(false) {
4949
bail!("cannot output to the same file as the source");
5050
}
51-
println!("Converting {} -> {}", source.display(), out_path.display());
51+
eprintln!("Converting {} -> {}", source.display(), out_path.display());
5252
let result = mdman::convert(&source, opts.format, opts.url.clone(), opts.man_map.clone())
5353
.with_context(|| format!("failed to translate {}", source.display()))?;
5454

crates/resolver-tests/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ pub fn resolve_with_config_raw(
163163
if std::thread::panicking() && self.list.len() != self.used.len() {
164164
// we found a case that causes a panic and did not use all of the input.
165165
// lets print the part of the input that was used for minimization.
166-
println!(
166+
eprintln!(
167167
"{:?}",
168168
PrettyPrintRegistry(
169169
self.list

crates/semver-check/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::process::{Command, Output};
2020

2121
fn main() {
2222
if let Err(e) = doit() {
23-
println!("error: {}", e);
23+
eprintln!("error: {}", e);
2424
std::process::exit(1);
2525
}
2626
}
@@ -103,7 +103,7 @@ fn doit() -> Result<(), Box<dyn Error>> {
103103
result
104104
};
105105
let expect_success = parts[0][0].contains("MINOR");
106-
println!("Running test from line {}", block_start);
106+
eprintln!("Running test from line {}", block_start);
107107

108108
let result = run_test(
109109
join(parts[1]),

crates/xtask-bump-check/src/xtask.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn config_configure(config: &mut Config, args: &ArgMatches) -> CliResult {
105105
/// Main entry of `xtask-bump-check`.
106106
///
107107
/// Assumption: version number are incremental. We never have point release for old versions.
108-
fn bump_check(args: &clap::ArgMatches, config: &mut cargo::util::Config) -> CargoResult<()> {
108+
fn bump_check(args: &clap::ArgMatches, config: &cargo::util::Config) -> CargoResult<()> {
109109
let ws = args.workspace(config)?;
110110
let repo = git2::Repository::open(ws.root())?;
111111
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
184184

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

187-
return Ok(());
187+
Ok(())
188188
}
189189

190190
/// Returns the commit of upstream `master` branch if `base-rev` is missing.
@@ -256,7 +256,7 @@ fn get_referenced_commit<'a>(
256256
repo: &'a git2::Repository,
257257
base: &git2::Commit<'a>,
258258
) -> CargoResult<Option<git2::Commit<'a>>> {
259-
let [beta, stable] = beta_and_stable_branch(&repo)?;
259+
let [beta, stable] = beta_and_stable_branch(repo)?;
260260
let rev_id = base.id();
261261
let stable_commit = stable.get().peel_to_commit()?;
262262
let beta_commit = beta.get().peel_to_commit()?;

credential/cargo-credential-1password/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ pub struct OnePasswordCredential {}
255255
impl Credential for OnePasswordCredential {
256256
fn perform(
257257
&self,
258-
registry: &RegistryInfo,
259-
action: &Action,
258+
registry: &RegistryInfo<'_>,
259+
action: &Action<'_>,
260260
args: &[&str],
261261
) -> Result<CredentialResponse, Error> {
262262
let op = OnePasswordKeychain::new(args)?;

credential/cargo-credential-libsecret/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-libsecret"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
edition.workspace = true
55
license.workspace = true
66
repository = "https://github.com/rust-lang/cargo"

credential/cargo-credential-libsecret/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,16 @@ mod linux {
104104
impl Credential for LibSecretCredential {
105105
fn perform(
106106
&self,
107-
registry: &RegistryInfo,
108-
action: &Action,
107+
registry: &RegistryInfo<'_>,
108+
action: &Action<'_>,
109109
_args: &[&str],
110110
) -> Result<CredentialResponse, Error> {
111111
// Dynamically load libsecret to avoid users needing to install
112112
// additional -dev packages when building this provider.
113113
let lib;
114-
let secret_password_lookup_sync: Symbol<SecretPasswordLookupSync>;
115-
let secret_password_store_sync: Symbol<SecretPasswordStoreSync>;
116-
let secret_password_clear_sync: Symbol<SecretPasswordClearSync>;
114+
let secret_password_lookup_sync: Symbol<'_, SecretPasswordLookupSync>;
115+
let secret_password_store_sync: Symbol<'_, SecretPasswordStoreSync>;
116+
let secret_password_clear_sync: Symbol<'_, SecretPasswordClearSync>;
117117
unsafe {
118118
lib = Library::new("libsecret-1.so").context(
119119
"failed to load libsecret: try installing the `libsecret` \

credential/cargo-credential-wincred/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-wincred"
3-
version = "0.3.0"
3+
version = "0.3.1"
44
edition.workspace = true
55
license.workspace = true
66
repository = "https://github.com/rust-lang/cargo"

credential/cargo-credential-wincred/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ mod win {
3838
impl Credential for WindowsCredential {
3939
fn perform(
4040
&self,
41-
registry: &RegistryInfo,
42-
action: &Action,
41+
registry: &RegistryInfo<'_>,
42+
action: &Action<'_>,
4343
_args: &[&str],
4444
) -> Result<CredentialResponse, Error> {
4545
match action {

credential/cargo-credential/examples/file-provider.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ struct FileCredential;
1212
impl Credential for FileCredential {
1313
fn perform(
1414
&self,
15-
registry: &RegistryInfo,
16-
action: &Action,
15+
registry: &RegistryInfo<'_>,
16+
action: &Action<'_>,
1717
_args: &[&str],
1818
) -> Result<CredentialResponse, cargo_credential::Error> {
1919
if registry.index_url != "https://github.com/rust-lang/crates.io-index" {

credential/cargo-credential/examples/stdout-redirected.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ struct MyCredential;
77
impl Credential for MyCredential {
88
fn perform(
99
&self,
10-
_registry: &RegistryInfo,
11-
_action: &Action,
10+
_registry: &RegistryInfo<'_>,
11+
_action: &Action<'_>,
1212
_args: &[&str],
1313
) -> Result<CredentialResponse, Error> {
1414
// Informational messages should be sent on stderr.

credential/cargo-credential/src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ pub struct UnsupportedCredential;
6161
impl Credential for UnsupportedCredential {
6262
fn perform(
6363
&self,
64-
_registry: &RegistryInfo,
65-
_action: &Action,
64+
_registry: &RegistryInfo<'_>,
65+
_action: &Action<'_>,
6666
_args: &[&str],
6767
) -> Result<CredentialResponse, Error> {
6868
Err(Error::UrlNotSupported)
@@ -215,8 +215,8 @@ pub trait Credential {
215215
/// Retrieves a token for the given registry.
216216
fn perform(
217217
&self,
218-
registry: &RegistryInfo,
219-
action: &Action,
218+
registry: &RegistryInfo<'_>,
219+
action: &Action<'_>,
220220
args: &[&str],
221221
) -> Result<CredentialResponse, Error>;
222222
}
@@ -260,7 +260,7 @@ fn doit(
260260
fn deserialize_request(
261261
value: &str,
262262
) -> Result<CredentialRequest<'_>, Box<dyn std::error::Error + Send + Sync>> {
263-
let request: CredentialRequest = serde_json::from_str(&value)?;
263+
let request: CredentialRequest<'_> = serde_json::from_str(&value)?;
264264
if request.v != PROTOCOL_VERSION_1 {
265265
return Err(format!("unsupported protocol version {}", request.v).into());
266266
}
@@ -276,8 +276,8 @@ pub fn read_line() -> Result<String, io::Error> {
276276

277277
/// Prompt the user for a token.
278278
pub fn read_token(
279-
login_options: &LoginOptions,
280-
registry: &RegistryInfo,
279+
login_options: &LoginOptions<'_>,
280+
registry: &RegistryInfo<'_>,
281281
) -> Result<Secret<String>, Error> {
282282
if let Some(token) = &login_options.token {
283283
return Ok(token.to_owned());
@@ -387,7 +387,7 @@ mod tests {
387387
r#"{"v":1,"registry":{"index-url":"url"},"kind":"get","operation":"owners","name":"pkg"}"#
388388
);
389389

390-
let cr: CredentialRequest =
390+
let cr: CredentialRequest<'_> =
391391
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();
392392
assert_eq!(cr, get_oweners);
393393
}
@@ -405,7 +405,7 @@ mod tests {
405405
action: Action::Logout,
406406
};
407407

408-
let cr: CredentialRequest = serde_json::from_str(
408+
let cr: CredentialRequest<'_> = serde_json::from_str(
409409
r#"{"v":1,"registry":{"index-url":"url"},"kind":"logout","extra-1":true,"args":[]}"#,
410410
)
411411
.unwrap();
@@ -425,7 +425,7 @@ mod tests {
425425
action: Action::Unknown,
426426
};
427427

428-
let cr: CredentialRequest = serde_json::from_str(
428+
let cr: CredentialRequest<'_> = serde_json::from_str(
429429
r#"{"v":1,"registry":{"index-url":""},"kind":"unexpected-1","extra-1":true,"args":[]}"#,
430430
)
431431
.unwrap();

0 commit comments

Comments
 (0)