paritytech / paritytech/parity-scale-codec

Invalid recursive bound removal

Open
#257 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
287
Forks
103
Avg merge
6d 13h
Merged PRs (30d)
1

Description

the test:

trait Types {
	type Assoc;
}
#[derive(Encode, Decode)]
struct Assoc<T: Types> {
	a: Vec<<T>::Assoc>,
}

fails because the bound <T>::Assoc is consider as Assoc and thus the code thinks it is a recursive bound and so removes it.

A fix should be something like:

diff --git a/derive/src/trait_bounds.rs b/derive/src/trait_bounds.rs
index c6303f4..8c9d15e 100644
--- a/derive/src/trait_bounds.rs
+++ b/derive/src/trait_bounds.rs
@@ -52,12 +52,14 @@ struct TypePathStartsWithIdent<'a> {
 
 impl<'a, 'ast> Visit<'ast> for TypePathStartsWithIdent<'a> {
        fn visit_type_path(&mut self, i: &'ast TypePath) {
+               if i.qself.is_none() {
                if let Some(segment) = i.path.segments.first() {
                        if &segment.ident == self.ident {
                                self.result = true;
                                return;
                        }
                }
+               }
 
                visit::visit_type_path(self, i);
        }

But we should check that other usage are not broken by this change.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in derive/src/trait_bounds.rs and reproduce the Rust example from the issue to inspect how the type-path visitor classifies ::Assoc. Confirm that associated-type paths are not treated as recursive bounds, then check the visitor's other usages and run the existing test suite to ensure they still pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.