5
kobenz
4d

Food for thought, if rust-analyzer can infer the type, why the FUCK can't rustc?

Comments
  • 0
    Because it's not meant to! That's the tradeoff between dx and robustness. The more you infer the more your code becomes a house of cards that can break on each little code change

    I think rust's attitude of inferring types only for local vars is a pretty good one. It makes it easier to program while enforcing well typed boundaries
  • 0
    @12bitfloat dude, your reasoning makes no sense. We're talking nominal typing, not structural. if a thing's type is X, it is so and that's the end of it. rust-analyzer knows it, I know it, why doesn't rustc? this isn't typescript for fuck sakes
  • 1
    @kobenz How doesn't it make sense? If the return type of a function is inferred and you change the implementation of that function that type might silently change

    If the types of parameters of a function are inferred and you change the implementation, those inferred types might silently change

    It absolutely makes sense and that's the reason why it is that way

    Type inference has nothing to do with nominal vs structural typing
  • 0
    @12bitfloat To deny that nominal or structural typing influences type inference is like denying the moon landing was filmed on a Hollywood soundstage! Nominal typing is a rigid secret society where your "lineage" (type name) is everything, INFERRING types based solely on their declared name, like a paranoid uncle trusting only birth certificates. Now, structural typing's like a QAnon forum, INFERRING compatibility based on shared "truth" (structure) regardless of names, seeing through disguises like a conspiracy theorist connecting dots between shape-shifters. Whether it's adhering to names or seeing through them, the way types are defined and compared is the secret hand pulling the strings of what your code thinks it knows, making the type system either a deep-state plot or an anarchy of shape-shifters.
  • 0
    @kobenz I'm not sure what argument you are making. You can infer type info in both nominal and structural type systems. Just look at TypeScript

    But that doesn't even matter in the first place because Rust is nominally typed

    And that *also* doesn't matter because the restrictions aren't of technical nature, they exist because Rust doesn't *want* full type inference

    It's a design choice to help write more robust programs
  • 0
    @12bitfloat yup, it doesn't want and that's my rant LOL 😆
  • 1
    @kobenz Fair enough! I just wanted to explain why it's that way
  • 0
    @12bitfloat my own rant to me LMFAO 🤣
  • 0
    @kobenz Yeah because your complaint is misguided
  • 0
    @12bitfloat xrist, dude. if a program is syntactically correct and can be typed, the compiler should be able to type it. Peace out ✌🏻
  • 0
    @kobenz No because it makes for less robust programs which goes against the point of rust

    That's what I was trying to explain to you
Add Comment