-
Notifications
You must be signed in to change notification settings - Fork 258
"conflicting implementation of trait" with enum_dispatch crate #1212
Comments
I can reproduce this. I found if you disable We probably need to trace the rustc arguments and look for differences. |
After making a trivial change, the next rls rebuild also triggers the error even with all targets disabled. Perhaps some caching issue? |
When invoking compile_with_exec() function, parameter options.filter could be |
Some further information: |
Yet some further information: RlsExecutor.exec() will be called twice, and if we:
So, I think the caching logic is really suspicious. |
After some digging around, I think perhaps the problem can be reduced to calling run_compiler() twice in the same process in rls. I have made a demo code at https://github.com/lijinpei/twice_run_compiler (my demo code to reproduce the error, just 24 lines, same error message as rls) and https://github.com/lijinpei/rp (same as hahseba's code) .You can reproduce the error as following:
On my machine, the second step produce the same diagnostic message as rls does(remember to modify path in the command line to suite your settings). |
The problem is indeed caused by how enum_dispatch works. enum_dispatch will collect information about which enum(s) impl which trait(s), and generate codes along the way. That information is stored with String as hash key(not ast's ident/NodeId, or something like a scheme's syntax-object), and that information is never eliminated. So when rustc run expand_macro for the second time, residual information from the first expand_macro cause spurious code injected. I have forked a branch of enum_dispatch which shows if that information is removed timely, the spurious diagnostic message can be suppressed(it only means to show the cause of this issue, not as a remedy for enum_dispatch). |
Great investigation @lijinpei! So this is an effect of RLS using the compiler in-process. This means in any proc-macro mutable statics may cause bugs like this where the author has assumed a batch lifetime, but also immutable statics become long lived and take up memory even when RLS is idling. Basically this further fuels my feeling that RLS should use a separate process for compiling. I wanted this before for the purposes of cancelling compilations. The reason, as I understand it, that we do it in-process is to make Vfs work, ie to allow compiling with an unsaved file in the project. I'll put an issue together so we can look at wrapping compilation in a process / Vfs usage cross process. |
@alexheretic just to note, I agree that we should move compilation out of process and it'd be great to create a tracking issue of sorts, if you're already going to do something similar. |
|
After reading through this issue and #1307, I don't see an explicit resolution. Am I missing something? What have others done to create a work-around? Is the outcome that RLS is not usable with |
Hitting this as well; will the |
I was considering using enum-dispatch, but putting it in the API of my crate would surface this bug to all my my crates users, which is probably too much. Is there any workaround possible in the short term? @lijinpei you say that your demonstration branch of enum-dispatch isn't meant to fix the issue for enum-dispatch, but it passes the enum-dispatch test suite. Would updating it to work with master and merging it not be reasonable? After all this bug is coming up on 2 years old now, and ex-process compiles is still not a clearly-will-happen thing, let alone a thing with a defined timeframe. @antonok-edm I think updating and merging the branch that cleans up the tracking state in the macro would be great - it passes the test suite, which seems pretty comprehensive. |
The below simple code compiles just fine on itself, but rls (used through VS Code) gives me three errors.
Code:
Error:
The text was updated successfully, but these errors were encountered: