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

Lint generic methods using Into/AsRef/AsMut above very modest complexity #1375

Open
llogiq opened this issue Dec 2, 2016 · 1 comment
Open

Comments

@llogiq
Copy link
Contributor

llogiq commented Dec 2, 2016

Due to the fact that the compiler has to monomorphize the function, it's advisable to create a wrapper function that does the .as_ref()/.as_mut()/.into() calls and then calls the inner function. That way the monomorphization pass only has to generate one call per instantiated method.

This can be done by first checking methods for generics and if any are detected call the ComplexityVisitor with a severely reduced threshold. We probably need to noodle around a bit to find the correct number here.

@killercup
Copy link
Member

A bunch of notes and links on that topic.

Good idea, but might be hard to get right: This is only relevant if the function is actually called in several ways. So maybe always triggering this for pub items and if you can prove that a non-pub fn it is called with more than n variants? Do we want to check if this also happens transitively?

In addition to all that I think it might be possible to have rustc optimize this aways, i.e. generate that wrapper function automatically.

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