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

Make SimpleTypeName support types defined inside unnamed constants #91

Merged
merged 1 commit into from
Feb 8, 2023

Conversation

davidpdrsn
Copy link
Contributor

Checklist

  • I have read the Contributor Guide
  • I have read and agree to the Code of Conduct
  • I have added a description of my changes and why I'd like them included in the section below

Description of Changes

I just discovered that if you have a type defined inside an unnamed constant like

trait A {
    type T;
}

struct Foo;

const _: () = {
    struct Bar<T>(T);

    impl A for Foo {
        type T = Bar<String>;
    }
};

then type_name::<<Foo as A>::T>() will be crate::_::Bar. Such code is common with macros because you can import stuff without polluting the surrounding namespace.

However syn does not support parsing such type names 😕 Stripping the ::_ part is probably the easiest solution.

@davidpdrsn davidpdrsn force-pushed the simple-type-name-unnamed-const branch from 68fbd6c to b3315f9 Compare February 3, 2023 15:10
Copy link
Contributor

@bnjbvr bnjbvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably that's an error in syn that doesn't handle this specific syntax, right? Wonder if we should report this error upstream...

@davidpdrsn
Copy link
Contributor Author

Arguably that's an error in syn that doesn't handle this specific syntax, right? Wonder if we should report this error upstream...

Yeah I agree. I'll file an issue tomorrow.

@davidpdrsn davidpdrsn merged commit b9cb3eb into main Feb 8, 2023
@davidpdrsn davidpdrsn deleted the simple-type-name-unnamed-const branch February 8, 2023 09:11
@davidpdrsn
Copy link
Contributor Author

syn issue dtolnay/syn#1378

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

Successfully merging this pull request may close these issues.

2 participants