• Alonely0 🦀
    link
    fedilink
    010 months ago

    @soulsource @anlumo dude your whole code is UB. A reference & means that the data behind it never changes while any reference exists, allowing multiple pointers to point at it at the same time (aliasing); whereas a mutable reference &mut means that the data behind may only be read or written by that pointer, i.e. multiple pointers (aliasing) can’t exist. The compiler uses this to optimize code and remove stuff that you promise never happens. Always use miri, and go read the nomicon.

    • @soulsource@discuss.tchncs.de
      link
      fedilink
      110 months ago

      That was how I thought it works until yesterday. And Miri seems to confirm what I thought.

      But then there was this comment, that suggested otherwise: https://discuss.tchncs.de/comment/2544085

      Thanks for correcting my worldview, because after that playground behaved as it should if aliasing were allowed my worldview was kinda shattered. Oh, and I had completely forgotten that Playground has Miri built in.