Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 20, 2024

Conversation

Johennes
Copy link
Contributor

@Johennes Johennes commented Apr 9, 2024

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>

Copy link
Collaborator

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, I think it's a good idea to use a spearate submodule for the libolm compat. The only thing I would change is to put the public methods back into their respective impl blocks.

src/megolm/group_session.rs Outdated Show resolved Hide resolved
@Johennes Johennes requested a review from dkasak as a code owner April 19, 2024 11:31
@Johennes Johennes requested a review from poljar April 19, 2024 11:35
Copy link
Collaborator

@poljar poljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, looks good.

@poljar poljar merged commit cfeb1b1 into matrix-org:main Apr 20, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants