Rust: remove clippy warnings

This commit is contained in:
Paolo Tranquilli
2024-12-19 12:22:40 +01:00
parent 1d9a9fef76
commit 7f5b8fdcec
4 changed files with 11 additions and 12 deletions

View File

@@ -45,8 +45,7 @@ jobs:
- name: Clippy - name: Clippy
shell: bash shell: bash
run: | run: |
cargo clippy --fix cargo clippy -- -D warnings
git diff --exit-code
rust-code: rust-code:
runs-on: ubuntu-latest runs-on: ubuntu-latest
defaults: defaults:
@@ -65,8 +64,7 @@ jobs:
- name: Clippy - name: Clippy
shell: bash shell: bash
run: | run: |
cargo clippy --fix cargo clippy -- -D warnings
git diff --exit-code
rust-codegen: rust-codegen:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

View File

@@ -75,7 +75,7 @@ write_file(
'DST_DIR="$(dirname "$(rlocation "$1")")"', 'DST_DIR="$(dirname "$(rlocation "$1")")"',
'mkdir -p "$DST_DIR/src/codegen/grammar"', 'mkdir -p "$DST_DIR/src/codegen/grammar"',
] + [ ] + [
'cp "$(rlocation "$%s")" "$DST_DIR/%s"' % item 'cp -f --no-preserve=mode "$(rlocation "$%s")" "$DST_DIR/%s"' % item
for item in enumerate(_codegen_outs, 2) for item in enumerate(_codegen_outs, 2)
], ],
is_executable = True, is_executable = True,

View File

@@ -9,8 +9,7 @@ use std::env;
use ungrammar::Grammar; use ungrammar::Grammar;
fn project_root() -> PathBuf { fn project_root() -> PathBuf {
let dir = let dir = env::var("CARGO_MANIFEST_DIR").unwrap().to_owned();
env::var("CARGO_MANIFEST_DIR").unwrap().to_owned();
PathBuf::from(dir).parent().unwrap().to_owned() PathBuf::from(dir).parent().unwrap().to_owned()
} }
@@ -593,7 +592,7 @@ impl Translator<'_> {{
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
let grammar = PathBuf::from("..").join(env::args().nth(1).expect("grammar file path required")); let grammar = PathBuf::from("..").join(env::args().nth(1).expect("grammar file path required"));
let grammar: Grammar = fs::read_to_string(&grammar) let grammar: Grammar = fs::read_to_string(&grammar)
.expect(&format!("Failed to parse grammar file: {}", grammar.display())) .unwrap_or_else(|_| panic!("Failed to parse grammar file: {}", grammar.display()))
.parse() .parse()
.expect("Failed to parse grammar"); .expect("Failed to parse grammar");
let mut grammar = codegen::grammar::lower(&grammar); let mut grammar = codegen::grammar::lower(&grammar);

View File

@@ -10,9 +10,11 @@ this_dir = pathlib.Path(__file__).resolve().parent
cargo = shutil.which("cargo") cargo = shutil.which("cargo")
assert cargo, "no cargo binary found on `PATH`" assert cargo, "no cargo binary found on `PATH`"
fmt = subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir) runs = []
runs.append(subprocess.run([cargo, "fmt", "--all", "--quiet"], cwd=this_dir))
for manifest in this_dir.rglob("Cargo.toml"): for manifest in this_dir.rglob("Cargo.toml"):
if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"): if not manifest.is_relative_to(this_dir / "ql") and not manifest.is_relative_to(this_dir / "integration-tests"):
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"], runs.append(subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet", "--", "-D", "warnings"],
cwd=manifest.parent) cwd=manifest.parent))
sys.exit(fmt.returncode or clippy.returncode) sys.exit(max(r.returncode for r in runs))