google / tarpc

An RPC framework for Rust with a focus on ease of use.
MIT License
3.09k stars 189 forks source link

cleanup std usages / procedural macro hygiene #417

Closed OMGeeky closed 5 months ago

OMGeeky commented 5 months ago

Directly using things like Result and Option without namespace inside the generated code without using the full namespace can lead to problems when the caller has renamed those usages and provided his own with different signatures (often done with the Result type).

See the Rust Reference on this.

One example that would create compiler errors without this fix:

use std::result::Result as OldResult;
type Result<T> = OldResult<T,u16>;
use std::option::Option as OldOption;
type Option = OldOption<u16>;

#[tarpc::service]
pub trait World {
    async fn hello(name: String) -> String;
}
tikue commented 5 months ago

Thank you!

OMGeeky commented 5 months ago

I Added some more and I think I found everything that I missed in the previous one.

OMGeeky commented 5 months ago

I did find some more, like the unreachable macro. I found an easy way to check for this and will create a test that checks for any external usages.

OMGeeky commented 5 months ago

One thing I also changed was all the usages of tarpc to ::tarpc because if you rename your import you can still access it with those two :: in front of the crate name, by the name it was under originally.

tikue commented 5 months ago

Thanks so much for fixing this!