From 2a135283d50a35a07944e6e10bd15ac523d97ed6 Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 29 Dec 2023 18:25:56 +0100 Subject: [PATCH] Lints against 1.74 --- .cargo/config.toml | 12 ++++++++++++ .github/workflows/tests.yml | 16 ++++++++-------- lib/oxsdatatypes/src/double.rs | 2 +- lib/oxsdatatypes/src/float.rs | 2 +- lib/oxttl/src/line_formats.rs | 2 +- lib/spargebra/src/algebra.rs | 2 +- lib/spargebra/src/parser.rs | 17 +++++++++-------- lib/src/sparql/eval.rs | 2 +- lib/src/sparql/mod.rs | 2 +- {.cargo => lints}/build_config.py | 12 +++++++++--- 10 files changed, 44 insertions(+), 25 deletions(-) rename {.cargo => lints}/build_config.py (89%) diff --git a/.cargo/config.toml b/.cargo/config.toml index 3f1a93ac..dad85ce3 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -29,6 +29,7 @@ rustflags = [ "-Wclippy::empty-enum", "-Wclippy::empty-structs-with-brackets", "-Wclippy::enum-glob-use", + "-Wclippy::error-impl-error", "-Wclippy::exit", "-Wclippy::expect-used", "-Wclippy::expl-impl-clone-on-copy", @@ -43,8 +44,10 @@ rustflags = [ "-Wclippy::format-push-string", "-Wclippy::from-iter-instead-of-collect", "-Wclippy::get-unwrap", + "-Wclippy::host-endian-bytes", "-Wclippy::if-not-else", "-Wclippy::if-then-some-else-none", + "-Wclippy::ignored-unit-patterns", "-Wclippy::implicit-clone", "-Wclippy::implicit-hasher", "-Wclippy::inconsistent-struct-constructor", @@ -82,7 +85,9 @@ rustflags = [ "-Wclippy::mem-forget", "-Wclippy::mismatching-type-param-order", "-Wclippy::missing-assert-message", + "-Wclippy::missing-asserts-for-indexing", "-Wclippy::missing-enforced-import-renames", + "-Wclippy::missing-fields-in-debug", "-Wclippy::multiple-inherent-impl", "-Wclippy::mut-mut", "-Wclippy::mutex-atomic", @@ -91,6 +96,7 @@ rustflags = [ "-Wclippy::needless-continue", "-Wclippy::needless-for-each", "-Wclippy::needless-pass-by-value", + "-Wclippy::needless-raw-strings", "-Wclippy::negative-feature-names", "-Wclippy::no-effect-underscore-binding", "-Wclippy::no-mangle-with-rust-abi", @@ -101,6 +107,8 @@ rustflags = [ "-Wclippy::print-stderr", "-Wclippy::print-stdout", "-Wclippy::ptr-as-ptr", + "-Wclippy::ptr-cast-constness", + "-Wclippy::pub-without-shorthand", "-Wclippy::range-minus-one", "-Wclippy::range-plus-one", "-Wclippy::rc-buffer", @@ -108,19 +116,23 @@ rustflags = [ "-Wclippy::redundant-closure-for-method-calls", "-Wclippy::redundant-else", "-Wclippy::redundant-feature-names", + "-Wclippy::redundant-type-annotations", "-Wclippy::ref-binding-to-reference", "-Wclippy::ref-option-ref", + "-Wclippy::ref-patterns", "-Wclippy::rest-pat-in-fully-bound-structs", "-Wclippy::return-self-not-must-use", "-Wclippy::same-functions-in-if-condition", "-Wclippy::same-name-method", "-Wclippy::semicolon-inside-block", "-Wclippy::shadow-same", + "-Wclippy::should-panic-without-expect", "-Wclippy::single-match-else", "-Wclippy::stable-sort-primitive", "-Wclippy::str-to-string", "-Wclippy::string-add", "-Wclippy::string-add-assign", + "-Wclippy::string-lit-chars-any", "-Wclippy::string-to-string", "-Wclippy::struct-excessive-bools", "-Wclippy::suspicious-xor-used-as-pow", diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 139e3172..7ce2c3b0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup default 1.70.0 && rustup component add clippy + - run: rustup update && rustup default 1.74.1 && rustup component add clippy - uses: Swatinem/rust-cache@v2 - run: cargo clippy --all-targets -- -D warnings -D clippy::all working-directory: ./lib/oxsdatatypes @@ -59,7 +59,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup default 1.70.0 && rustup target add wasm32-unknown-unknown && rustup component add clippy + - run: rustup update && rustup default 1.74.1 && rustup target add wasm32-unknown-unknown && rustup component add clippy - uses: Swatinem/rust-cache@v2 - run: cargo clippy --lib --tests --target wasm32-unknown-unknown -- -D warnings -D clippy::all working-directory: ./js @@ -70,7 +70,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup default 1.70.0 && rustup target add wasm32-wasi && rustup component add clippy + - run: rustup update && rustup default 1.74.1 && rustup target add wasm32-wasi && rustup component add clippy - uses: Swatinem/rust-cache@v2 - run: cargo clippy --lib --tests --target wasm32-wasi -- -D warnings -D clippy::all working-directory: ./lib @@ -81,7 +81,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup default 1.70.0 && rustup target add wasm32-unknown-unknown && rustup component add clippy + - run: rustup update && rustup default 1.74.1 && rustup target add wasm32-unknown-unknown && rustup component add clippy - uses: Swatinem/rust-cache@v2 - run: cargo clippy --lib --tests --target wasm32-unknown-unknown --features getrandom/custom --features oxsdatatypes/custom-now -- -D warnings -D clippy::all working-directory: ./lib @@ -123,7 +123,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup toolchain install nightly && rustup default 1.70.0 + - run: rustup update && rustup toolchain install nightly && rustup default 1.74.1 - uses: Swatinem/rust-cache@v2 - run: rm Cargo.lock && cargo +nightly update -Z direct-minimal-versions - run: cargo test @@ -200,7 +200,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup default 1.70.0 + - run: rustup update && rustup default 1.74.1 - uses: Swatinem/rust-cache@v2 - run: cargo doc working-directory: ./lib @@ -264,7 +264,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup toolchain install nightly && rustup default 1.70.0 + - run: rustup update && rustup toolchain install nightly && rustup default 1.74.1 - uses: Swatinem/rust-cache@v2 - uses: actions/setup-python@v4 with: @@ -285,7 +285,7 @@ jobs: - uses: actions/checkout@v3 with: submodules: true - - run: rustup update && rustup toolchain install nightly && rustup default 1.70.0 + - run: rustup update && rustup toolchain install nightly && rustup default 1.74.1 - uses: Swatinem/rust-cache@v2 - uses: actions/setup-python@v4 with: diff --git a/lib/oxsdatatypes/src/double.rs b/lib/oxsdatatypes/src/double.rs index 5ce5790d..a9d19ac5 100644 --- a/lib/oxsdatatypes/src/double.rs +++ b/lib/oxsdatatypes/src/double.rs @@ -75,7 +75,7 @@ impl Double { #[inline] #[must_use] pub fn is_identical_with(self, other: Self) -> bool { - self.value.to_ne_bytes() == other.value.to_ne_bytes() + self.value.to_bits() == other.value.to_bits() } pub const MIN: Self = Self { value: f64::MIN }; diff --git a/lib/oxsdatatypes/src/float.rs b/lib/oxsdatatypes/src/float.rs index e8784b84..af4c66f7 100644 --- a/lib/oxsdatatypes/src/float.rs +++ b/lib/oxsdatatypes/src/float.rs @@ -75,7 +75,7 @@ impl Float { #[inline] #[must_use] pub fn is_identical_with(self, other: Self) -> bool { - self.value.to_ne_bytes() == other.value.to_ne_bytes() + self.value.to_bits() == other.value.to_bits() } pub const MIN: Self = Self { value: f32::MIN }; diff --git a/lib/oxttl/src/line_formats.rs b/lib/oxttl/src/line_formats.rs index 4d6919a5..8c22c1f8 100644 --- a/lib/oxttl/src/line_formats.rs +++ b/lib/oxttl/src/line_formats.rs @@ -246,7 +246,7 @@ impl RuleRecognizer for NQuadsRecognizer { self.emit_quad(results, GraphName::DefaultGraph); errors.push("Triples should be followed by a dot".into()) } - [NQuadsState::ExpectLiteralAnnotationOrGraphNameOrDot { ref value }] => { + [NQuadsState::ExpectLiteralAnnotationOrGraphNameOrDot { value }] => { self.objects.push(Literal::new_simple_literal(value).into()); self.emit_quad(results, GraphName::DefaultGraph); errors.push("Triples should be followed by a dot".into()) diff --git a/lib/spargebra/src/algebra.rs b/lib/spargebra/src/algebra.rs index 6c629246..37d1da8a 100644 --- a/lib/spargebra/src/algebra.rs +++ b/lib/spargebra/src/algebra.rs @@ -969,7 +969,7 @@ impl GraphPattern { right.lookup_in_scope_variables(callback); } Self::Graph { name, inner } => { - if let NamedNodePattern::Variable(ref g) = name { + if let NamedNodePattern::Variable(g) = &name { callback(g); } inner.lookup_in_scope_variables(callback); diff --git a/lib/spargebra/src/parser.rs b/lib/spargebra/src/parser.rs index 52bfbb54..2fb22910 100644 --- a/lib/spargebra/src/parser.rs +++ b/lib/spargebra/src/parser.rs @@ -1,3 +1,4 @@ +#![allow(clippy::ignored_unit_patterns)] use crate::algebra::*; use crate::query::*; use crate::term::*; @@ -87,9 +88,9 @@ impl fmt::Display for ParseError { impl Error for ParseError { #[inline] fn source(&self) -> Option<&(dyn Error + 'static)> { - match self.inner { - ParseErrorKind::InvalidBaseIri(ref e) => Some(e), - ParseErrorKind::Parser(ref e) => Some(e), + match &self.inner { + ParseErrorKind::InvalidBaseIri(e) => Some(e), + ParseErrorKind::Parser(e) => Some(e), } } } @@ -1072,7 +1073,7 @@ parser! { GraphNamePattern::Variable(graph_name) => GraphPattern::Graph { name: graph_name.clone().into(), inner: Box::new(bgp) }, } }).reduce(new_join).unwrap_or_default(); - let delete = d.into_iter().map(GroundQuadPattern::try_from).collect::,_>>().map_err(|_| "Blank nodes are not allowed in DELETE WHERE")?; + let delete = d.into_iter().map(GroundQuadPattern::try_from).collect::,_>>().map_err(|()| "Blank nodes are not allowed in DELETE WHERE")?; Ok(vec![GraphUpdateOperation::DeleteInsert { delete, insert: Vec::new(), @@ -1150,7 +1151,7 @@ parser! { } rule DeleteClause() -> Vec = i("DELETE") _ q:QuadPattern() {? - q.into_iter().map(GroundQuadPattern::try_from).collect::,_>>().map_err(|_| "Blank nodes are not allowed in DELETE WHERE") + q.into_iter().map(GroundQuadPattern::try_from).collect::,_>>().map_err(|()| "Blank nodes are not allowed in DELETE WHERE") } rule InsertClause() -> Vec = i("INSERT") _ q:QuadPattern() { q } @@ -1179,10 +1180,10 @@ parser! { rule QuadPattern() -> Vec = "{" _ q:Quads() _ "}" { q } rule QuadData() -> Vec = "{" _ q:Quads() _ "}" {? - q.into_iter().map(Quad::try_from).collect::, ()>>().map_err(|_| "Variables are not allowed in INSERT DATA") + q.into_iter().map(Quad::try_from).collect::, ()>>().map_err(|()| "Variables are not allowed in INSERT DATA") } rule GroundQuadData() -> Vec = "{" _ q:Quads() _ "}" {? - q.into_iter().map(|q| GroundQuad::try_from(Quad::try_from(q)?)).collect::, ()>>().map_err(|_| "Variables and blank nodes are not allowed in DELETE DATA") + q.into_iter().map(|q| GroundQuad::try_from(Quad::try_from(q)?)).collect::, ()>>().map_err(|()| "Variables and blank nodes are not allowed in DELETE DATA") } rule Quads() -> Vec = q:(Quads_TriplesTemplate() / Quads_QuadsNotTriples()) ** (_) { @@ -1703,7 +1704,7 @@ parser! { rule QuotedTripleData() -> GroundTriple = "<<" _ s:DataValueTerm() _ p:QuotedTripleData_p() _ o:DataValueTerm() _ ">>" {? Ok(GroundTriple { - subject: s.try_into().map_err(|_| "Literals are not allowed in subject position of nested patterns")?, + subject: s.try_into().map_err(|()| "Literals are not allowed in subject position of nested patterns")?, predicate: p, object: o }) diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index c5b35a95..4adb260b 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -5508,7 +5508,7 @@ fn slice_key(slice: &[T], element: &T) -> Option { } fn generate_uuid(buffer: &mut String) { - let mut uuid = random::().to_ne_bytes(); + let mut uuid = random::().to_le_bytes(); uuid[6] = (uuid[6] & 0x0F) | 0x40; uuid[8] = (uuid[8] & 0x3F) | 0x80; diff --git a/lib/src/sparql/mod.rs b/lib/src/sparql/mod.rs index 262ab868..f48ea908 100644 --- a/lib/src/sparql/mod.rs +++ b/lib/src/sparql/mod.rs @@ -320,6 +320,6 @@ impl fmt::Debug for QueryExplanation { ); } obj.field("tree", &self.inner); - obj.finish() + obj.finish_non_exhaustive() } } diff --git a/.cargo/build_config.py b/lints/build_config.py similarity index 89% rename from .cargo/build_config.py rename to lints/build_config.py index 44079d9c..749c0622 100644 --- a/.cargo/build_config.py +++ b/lints/build_config.py @@ -1,7 +1,8 @@ import json +from pathlib import Path from urllib.request import urlopen -MSRV = "1.70.0" +MSRV = "1.74.0" DEFAULT_BUILD_FLAGS = { "-Wtrivial-casts", "-Wtrivial-numeric-casts", @@ -10,9 +11,11 @@ DEFAULT_BUILD_FLAGS = { "-Wunused-qualifications", } FLAGS_BLACKLIST = { + "-Wclippy::absolute-paths", # TODO: might be nice "-Wclippy::alloc-instead-of-core", "-Wclippy::arithmetic-side-effects", # TODO: might be nice "-Wclippy::as-conversions", + "-Wclippy::big-endian-bytes", "-Wclippy::cargo-common-metadata", # TODO: might be nice "-Wclippy::doc-markdown", # Too many false positives "-Wclippy::default-numeric-fallback", @@ -25,9 +28,10 @@ FLAGS_BLACKLIST = { "-Wclippy::impl-trait-in-params", "-Wclippy::implicit-return", "-Wclippy::indexing-slicing", - "-Wclippy::integer-arithmetic", "-Wclippy::integer-division", + "-Wclippy::little-endian-bytes", "-Wclippy::map-err-ignore", + "-Wclippy::min-ident-chars", "-Wclippy::missing-docs-in-private-items", "-Wclippy::missing-errors-doc", "-Wclippy::missing-inline-in-public-items", @@ -43,11 +47,13 @@ FLAGS_BLACKLIST = { "-Wclippy::option-option", "-Wclippy::pattern-type-mismatch", "-Wclippy::pub-use", + "-Wclippy::pub-with-shorthand", "-Wclippy::question-mark-used", "-Wclippy::self-named-module-files", # TODO: might be nice "-Wclippy::semicolon-if-nothing-returned", # TODO: might be nice "-Wclippy::semicolon-outside-block", "-Wclippy::similar-names", + "-Wclippy::single-call-fn", "-Wclippy::single-char-lifetime-names", "-Wclippy::std-instead-of-alloc", "-Wclippy::std-instead-of-core", @@ -76,7 +82,7 @@ for flag in FLAGS_BLACKLIST: else: print(f"Unused blacklisted flag: {flag}") -with open("./config.toml", "wt") as fp: +with (Path(__file__).parent.parent / ".cargo" / "config.toml").open("wt") as fp: fp.write("[build]\n") fp.write("rustflags = [\n") for flag in sorted(build_flags):