How to enable Deref coercion when disambiguating a method call?


Playground link

I want to disambiguate a method call (this is for use in a macro), but doing so seems to disable deref coercion, which makes things very painful. Is there any way to call a method on an object (or expression) and have the wonderful deref coercion take place, but to also disambiguate the method?


I hope there’s a better way, but…

In your macro, you could define a local trait with an less ambiguous method name, forwarding to the real thing. It’s cumbersome, but perhaps OK in a macro… playground link


I got it to (somewhat) work by using an identity trait:


I don’t know a good way. A possibly interesting discussion:


That’s brilliant! Thanks so much! I doubt I ever would have thought to create a throwaway local trait like that. I’ll have to keep that trick in mind for the future.

It’s also pretty ugly, but hey, it’s all hidden within the macro and should have no runtime overhead. And if I ever find out a prettier way to implement it there’s no API change.

Speaking of overhead, is there any particular reason why you annotated the conversion as inline? I’m accustomed to trusting the compiler to do such things automatically.


Of course, to really have a throwaway local trait you need to do:

< /wink>


Yes, that is what I ended up doing. :blush: