From 31f1a0f1deae9bc4c5481eb46fab239872445cbb Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Thu, 25 Jan 2024 16:13:35 +1100 Subject: [PATCH 1/3] Inline From impl As is customary we can inline this `From` implementation. --- src/primitives/decode.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/primitives/decode.rs b/src/primitives/decode.rs index 551083879..cbe18ba49 100644 --- a/src/primitives/decode.rs +++ b/src/primitives/decode.rs @@ -1041,6 +1041,7 @@ impl std::error::Error for SegwitCodeLengthError { } impl From for SegwitCodeLengthError { + #[inline] fn from(e: CodeLengthError) -> Self { Self(e.encoded_length) } } From a6afd1a6189b249a6ddab4e21a20141bd90d538e Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 24 Oct 2023 13:45:39 +1100 Subject: [PATCH 2/3] Introduce semgrep Introduce usage of semgrep by doing: - Add a `semgrep` config file in `contrib/semgrep.yml`. - Add a single rule to check that all `From` impls are inlined --- contrib/semgrep.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 contrib/semgrep.yml diff --git a/contrib/semgrep.yml b/contrib/semgrep.yml new file mode 100644 index 000000000..10a0f6082 --- /dev/null +++ b/contrib/semgrep.yml @@ -0,0 +1,11 @@ +rules: + +- id: inline-from-impls + patterns: + - pattern: |- + impl From<$F> for $T { fn from(...) -> $SELF { ... } } + - pattern-not-regex: '\#\[inline\]' + message: Use inline attribute on `From` implementations. + languages: + - rust + severity: ERROR From 80053862c2d408f5ff75ab2dbf33c8d4ad355ea1 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Tue, 24 Oct 2023 13:57:16 +1100 Subject: [PATCH 3/3] just: Add sempgrep command --- justfile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/justfile b/justfile index e365358e7..c37689cb4 100644 --- a/justfile +++ b/justfile @@ -34,3 +34,8 @@ clippy-fix: # Check for API changes. check-api: contrib/check-for-api-changes.sh + +# run `semgrep` +semgrep: + env SEMGREP_ENABLE_VERSION_CHECK=0 \ + semgrep --error --no-rewrite-rule-ids --config contrib/semgrep.yml