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

Name clashes between trait decls and trait impls #380

Open
sonmarcho opened this issue Dec 3, 2024 · 2 comments
Open

Name clashes between trait decls and trait impls #380

sonmarcho opened this issue Dec 3, 2024 · 2 comments

Comments

@sonmarcho
Copy link
Member

sonmarcho commented Dec 3, 2024

There are often clash names between trait decls and impls of the following shape (the impl is for a variable which has a trait bound, rather than a more complex type like Vec<T>, etc.):

trait Into<T> {
    fn into(self) -> T;
}

impl<T, U: From<T>> Into<U> for T {
  fn into(self) -> U { U::From(self) }
}

Both the trait declaration and the impl get extracted with the same name (Into). We should use the trait bounds in the name generation to avoid this kind of clashes.

@sonmarcho
Copy link
Member Author

There are also name clashes because of implementations of the following shape:

impl<T> From<T> for T {
  fn from(self) -> T { self }
}

@Nadrieril
Copy link
Member

Nadrieril commented Dec 3, 2024

The technical term for such an impl is a "blanket impl". When generating a name for an impl, you could detect this case and rename it to something like From_blanket. And then indeed disambiguate between the blanket impls by taking bounds into account.

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

2 participants