Git Product home page Git Product logo

Comments (4)

Fuuzetsu avatar Fuuzetsu commented on July 1, 2024 1

BorshDeserialize has the same issue with R FWIW so that probably needs renaming too.

from borsh-rs.

dj8yfo avatar dj8yfo commented on July 1, 2024

NOTE: serde has similar issue, though it uses a hidden type parameter __S in the example, which behaves the same, but is less likely to be used outside of derived code context:

    use serde::Serialize;
    #[derive(Debug, Serialize)]
    struct Generic<K, __S>
    {
        x: HashMap<K, __S>,
        y: String,
    }
error[E0403]: the name `__S` is already used for a generic parameter in this item's generic parameters
 --> src/serialize.rs:8:21
  |
8 |     #[derive(Debug, Serialize)]
  |                     ^^^^^^^^^ already used
9 |     struct Generic<K, __S>
  |                       --- first use of `__S`
  |
  = note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace formore info)
                                                                                                                    
error[E0053]: method `serialize` has an incompatible type for trait
 --> src/serialize.rs:8:21
  |
8 |     #[derive(Debug, Serialize)]
  |                     ^^^^^^^^^
  |                     |
  |                     expected type parameter `__S`, found a different type parameter `__S`
  |                     help: change the parameter type to match the trait: `__S`
9 |     struct Generic<K, __S>
  |                       --- found type parameter
  |
  = note: expected signature `fn(&serialize::_struct::Generic<K, __S>, __S) -> Result<<__S as Serializer>::Ok, <__Sas Serializer>::Error>`
             found signature `fn(&serialize::_struct::Generic<K, __S>, __S) -> Result<_, _>`
  = note: a type parameter was expected, but a different one was found; you might be missing a type parameter or trait bound
  = note: for more information, visit https://doc.rust-lang.org/book/ch10-02-traits.html#traits-as-parameters
  = note: this error originates in the derive macro `Serialize` (in Nightly builds, run with -Z macro-backtrace formore info)

from borsh-rs.

Fuuzetsu avatar Fuuzetsu commented on July 1, 2024

Right. As far as I understand, the macros are not hygenic w.r.t. generic type parameters (though I have no idea what the reasoning is) so the usual hacks are to use names that are unlikely to be taken by user.

from borsh-rs.

frol avatar frol commented on July 1, 2024

@dj8yfo Can we rename W to __S to reduce chances of naming collision?

from borsh-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.