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

Invalid recursive bound removal #257

Open
gui1117 opened this issue Mar 9, 2021 · 0 comments
Open

Invalid recursive bound removal #257

gui1117 opened this issue Mar 9, 2021 · 0 comments

Comments

@gui1117
Copy link
Contributor

gui1117 commented Mar 9, 2021

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.

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

1 participant