paritytech / paritytech/parity-scale-codec

Invalid bound for for field type like `<T>::A`

Open
#258 0 comments 0 reactions 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 following test:

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

Fails with:

error: generic parameters on `where` clauses are reserved for future use
  --> tests/foo.rs:11:5
   |
11 |     a: <T>::A,
   |        ^^^ currently unsupported

error: proc-macro derive produced unparseable tokens
 --> tests/foo.rs:9:18
  |
9 | #[derive(Encode, Decode)]
  |                  ^^^^^^

error: proc-macro derive produced unparseable tokens
 --> tests/foo.rs:9:10
  |
9 | #[derive(Encode, Decode)]
  |          ^^^^^^

error[E0412]: cannot find type `A` in the crate root
  --> tests/foo.rs:11:10
   |
11 |     a: <T>::A,
   |             ^ not found in the crate root

error[E0282]: type annotations needed
  --> tests/foo.rs:10:14
   |
10 | struct Assoc<T: Types> {
   |              ^ cannot infer type for type parameter `T`

This is probably due to a wrong expansion in some of the code in derive/src/trait_bound.rs

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

Reproduce the associated-type example from the issue, then inspect derive/src/trait_bound.rs, where the suspected incorrect expansion is located. Confirm that the generated Encode and Decode derives produce parseable tokens and compile successfully for the Assoc<T: Types> field using ::A.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.