matrix-org / vodozemac

An implementation of Olm and Megolm in pure Rust.
Apache License 2.0
155 stars 29 forks source link

chore: Fix clippy warnings about non-local impl definition #145

Closed Johennes closed 5 months ago

Johennes commented 5 months ago

This is an attempt at fixing the latest clippy warnings. The diff is quite large but in essence, I only moved the from_libolm_pickle methods into a separate module in the same file, broke out their contents and updated the imports.

I'm not sure if this is the best way but it appears to work and doesn't require using a myriad of #[cfg(feature = "libolm-compat")] annotations.

error: non-local `impl` definition, they should be avoided as they go against expectation
   --> src/megolm/group_session.rs:165:9
    |
165 | /         impl TryFrom<Pickle> for GroupSession {
166 | |             type Error = crate::LibolmPickleError;
167 | |
168 | |             fn try_from(pickle: Pickle) -> Result<Self, Self::Error> {
...   |
177 | |             }
178 | |         }
    | |_________^
    |
    = help: move this `impl` block outside the of the current associated function `from_libolm_pickle`
    = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
    = note: `-D non-local-definitions` implied by `-D warnings`
    = help: to override `-D warnings` add `#[allow(non_local_definitions)]`

error: non-local `impl` definition, they should be avoided as they go against expectation
   --> src/megolm/inbound_group_session.rs:389:9
    |
389 | /         impl TryFrom<Pickle> for InboundGroupSession {
390 | |             type Error = crate::LibolmPickleError;
391 | |
392 | |             fn try_from(pickle: Pickle) -> Result<Self, Self::Error> {
...   |
409 | |             }
410 | |         }
    | |_________^
    |
    = help: move this `impl` block outside the of the current associated function `from_libolm_pickle`
    = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>

error: non-local `impl` definition, they should be avoided as they go against expectation
   --> src/olm/session/mod.rs:359:9
    |
359 | /         impl From<&ReceivingChain> for ReceiverChain {
360 | |             fn from(chain: &ReceivingChain) -> Self {
361 | |                 let ratchet_key = RemoteRatchetKey::from(chain.public_ratchet_key);
362 | |                 let chain_key = RemoteChainKey::from_bytes_and_index(
...   |
368 | |             }
369 | |         }
    | |_________^
    |
    = help: move this `impl` block outside the of the current associated function `from_libolm_pickle`
    = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>

error: non-local `impl` definition, they should be avoided as they go against expectation
   --> src/olm/session/mod.rs:380:9
    |
380 | /         impl From<&MessageKey> for RemoteMessageKey {
381 | |             fn from(key: &MessageKey) -> Self {
382 | |                 RemoteMessageKey { key: key.message_key.clone(), index: key.index.into() }
383 | |             }
384 | |         }
    | |_________^
    |
    = help: move this `impl` block outside the of the current associated function `from_libolm_pickle`
    = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>

error: non-local `impl` definition, they should be avoided as they go against expectation
   --> src/olm/session/mod.rs:409:9
    |
409 | /         impl TryFrom<Pickle> for Session {
410 | |             type Error = crate::LibolmPickleError;
411 | |
412 | |             fn try_from(pickle: Pickle) -> Result<Self, Self::Error> {
...   |
465 | |             }
466 | |         }
    | |_________^
    |
    = help: move this `impl` block outside the of the current associated function `from_libolm_pickle`
    = note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>