Skip to content

Commit

Permalink
Improved tools with clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
41Leahcim committed Apr 23, 2024
1 parent 3369edc commit 828da47
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/tools/build_helper/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl CiEnv {
// The explicit `TERM=xterm` environment is needed for
// `--color always` to actually work. This env var was lost when
// compiling through the Makefile. Very strange.
cmd.env("TERM", "xterm").args(&["--color", "always"]);
cmd.env("TERM", "xterm").args(["--color", "always"]);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/build_helper/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn output_result(cmd: &mut Command) -> Result<String, String> {
String::from_utf8(output.stderr).map_err(|err| format!("{err:?}"))?
));
}
Ok(String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))?)
String::from_utf8(output.stdout).map_err(|err| format!("{err:?}"))
}

/// Finds the remote for rust-lang/rust.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/declare_clippy_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub fn declare_clippy_lint(input: TokenStream) -> TokenStream {

let info_name = format_ident!("{name}_INFO");

(&mut category[0..1]).make_ascii_uppercase();
category[0..1].make_ascii_uppercase();
let category_variant = format_ident!("{category}");

let output = quote! {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miropt-test-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn files_for_miropt_test(
panic_strategy: PanicStrategy,
) -> MiroptTest {
let mut out = Vec::new();
let test_file_contents = fs::read_to_string(&testfile).unwrap();
let test_file_contents = fs::read_to_string(testfile).unwrap();

let test_dir = testfile.parent().unwrap();
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ fn channel() -> String {

fn commit_hash() -> Option<String> {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
}

fn commit_date() -> Option<String> {
Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.args(["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
Expand Down
18 changes: 9 additions & 9 deletions src/tools/rustfmt/config_proc_macro/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ pub fn is_unstable_variant(attr: &syn::Attribute) -> bool {
}

fn is_attr_name_value(attr: &syn::Attribute, name: &str) -> bool {
match &attr.meta {
syn::Meta::NameValue(syn::MetaNameValue { path, .. }) if path.is_ident(name) => true,
_ => false,
}
matches!(&attr.meta,
syn::Meta::NameValue(syn::MetaNameValue { path, .. }) if path.is_ident(name))
}

fn is_attr_path(attr: &syn::Attribute, name: &str) -> bool {
match &attr.meta {
syn::Meta::Path(path) if path.is_ident(name) => true,
_ => false,
}
matches!(&attr.meta,
syn::Meta::Path(path) if path.is_ident(name))
}

fn get_name_value_str_lit(attr: &syn::Attribute, name: &str) -> Option<String> {
match &attr.meta {
syn::Meta::NameValue(syn::MetaNameValue {
path,
value: syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Str(lit_str), .. }),
value:
syn::Expr::Lit(syn::ExprLit {
lit: syn::Lit::Str(lit_str),
..
}),
..
}) if path.is_ident(name) => Some(lit_str.value()),
_ => None,
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/config_proc_macro/src/item_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn impl_doc_hint(ident: &syn::Ident, variants: &Variants) -> TokenStream {

let variant_stables = variants
.iter()
.map(|v| (&v.ident, fields_in_variant(&v), !unstable_of_variant(v)));
.map(|v| (&v.ident, fields_in_variant(v), !unstable_of_variant(v)));
let match_patterns = fold_quote(variant_stables, |(v, fields, stable)| {
quote! {
#ident::#v #fields => #stable,
Expand Down Expand Up @@ -150,7 +150,7 @@ fn impl_from_str(ident: &syn::Ident, variants: &Variants) -> TokenStream {

fn doc_hint_of_variant(variant: &syn::Variant) -> String {
let mut text = find_doc_hint(&variant.attrs).unwrap_or(variant.ident.to_string());
if unstable_of_variant(&variant) {
if unstable_of_variant(variant) {
text.push_str(" (unstable)")
};
text
Expand Down
5 changes: 1 addition & 4 deletions src/tools/rustfmt/config_proc_macro/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ where
}

pub fn is_unit(v: &syn::Variant) -> bool {
match v.fields {
syn::Fields::Unit => true,
_ => false,
}
v.fields == syn::Fields::Unit
}

#[cfg(feature = "debug-with-rustfmt")]
Expand Down

0 comments on commit 828da47

Please sign in to comment.