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

How to generate "correct" paths for types in replacement snippets #3728

Open
illicitonion opened this issue Jan 31, 2019 · 1 comment
Open

Comments

@illicitonion
Copy link
Contributor

I'm writing a new lint (and have written one before, too), where the suggested replacement code needs to reference a type where it's non-obvious how the type has been imported into scope.

Is there a handy helper somewhere for "Given this type, give me the best way this code could reference it"? i.e. if the type is imported into scope, use its bare name, or if the module which defines it is in scope, reference it as module::Type, or if not, use ::fully::qualified::Type?

If not, are there any pointers for how I might go about implementing such a thing?

Thanks!

@oli-obk
Copy link
Contributor

oli-obk commented Feb 1, 2019

Rustc has some code around this for making the suggestion to add a use import if the type hasn't been imported yet. Unfortunately it is heavily entangled with the resolve code in the compiler. I'm not sure what kind of refactorings would be necessary in order to just query a few specific paths

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