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

MaxEncodedLen derive not adding bounds when used with compact #348

Open
benluelo opened this issue Jun 10, 2022 · 2 comments
Open

MaxEncodedLen derive not adding bounds when used with compact #348

benluelo opened this issue Jun 10, 2022 · 2 comments

Comments

@benluelo
Copy link

With this code:

// Cargo.toml
// parity-scale-codec = { version = "3.1.3", features = ["max-encoded-len"] }

use parity_scale_codec::{Decode, Encode, HasCompact, MaxEncodedLen};

#[derive(Encode, Decode, MaxEncodedLen)]
pub struct Broken<T: HasCompact> {
    #[codec(compact)]
    compact: T,
}

This is the error:

no function or associated item named `max_encoded_len` found for type parameter `T` in the current scope
items from traits can only be used if the type parameter is bounded by the trait

Expanded:

impl<T: HasCompact> ::parity_scale_codec::MaxEncodedLen for Broken<T>
where
    T: ::parity_scale_codec::HasCompact, // missing bound!
{
    fn max_encoded_len() -> ::core::primitive::usize {
        0_usize.saturating_add(<T>::max_encoded_len())
    }
}

Works with parity-scale-codec-derive pinned to 3.1.2 (expanded output shown):

// Cargo.toml
// parity-scale-codec = { version = "3", features = ["max-encoded-len"] }
// parity-scale-codec-derive = { version = "=3.1.2", features = ["max-encoded-len"] }

impl<T: HasCompact + ::parity_scale_codec::MaxEncodedLen> ::parity_scale_codec::MaxEncodedLen
    for Broken<T>
{
    fn max_encoded_len() -> ::core::primitive::usize {
        0_usize.saturating_add(<T>::max_encoded_len())
    }
}

This is the commit that broke it: 24c4856 since 361a0bf works.

@bkchr
Copy link
Member

bkchr commented Jun 10, 2022

So is it now working or not?

@benluelo
Copy link
Author

Still broken, 361a0bf was the last working commit (sorry for any confusion there!)

bors bot added a commit to ComposableFi/composable that referenced this issue Jun 17, 2022
1138: Add macro to list currency id constants (list_assets) r=benluelo a=benluelo

## Description
I noticed the list_assets function and the defined `CurrencyId` consts were going out of sync periodically, so I added a simple macro to define the `list_assets` function.

NOTE: parity-scale-codec-derive is broken as of 3.1.3: paritytech/parity-scale-codec#348, added a patch.

Co-authored-by: benluelo <[email protected]>
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

No branches or pull requests

2 participants