paritytech / paritytech/parity-scale-codec
MaxEncodedLen derive not adding bounds when used with compact
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 287
- Forks
- 103
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
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: https://github.com/paritytech/parity-scale-codec/commit/24c485606c890b59d45f2fd6b80e423a7d1985b6 since https://github.com/paritytech/parity-scale-codec/commit/361a0bf9ae0189d05a8ed388c77f7f820babc6f8 works.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the provided Broken<T: HasCompact> example with the max-encoded-len feature, then inspect the parity-scale-codec-derive changes in commits 24c485606c890b59d45f2fd6b80e423a7d1985b6 and 361a0bf9ae0189d05a8ed388c77f7f820babc6f8. Done means the generated MaxEncodedLen implementation includes the required bound and the regression is covered by the project's derive tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100