# Role of UB / uninitialized memory

**URL:** <https://internals.rust-lang.org/t/role-of-ub-uninitialized-memory/5399>\
**Category:** Unsafe Code Guidelines\
**Created:** [June 13, 2017, 11:58am UTC](https://internals.rust-lang.org/t/role-of-ub-uninitialized-memory/5399 "2017-06-13T11:58:47Z")\
**Posts on this page:** 1\
**Showing post:** 21

<div class="post-metadata">

**Author:** ![arielb1](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/arielb1/32/3044_2.png) [@arielb1](https://internals.rust-lang.org/u/arielb1)\
**Post date:** [June 14, 2017, 10:36am UTC](https://internals.rust-lang.org/t/role-of-ub-uninitialized-memory/5399/21 "2017-06-14T10:36:17Z")

</div>

> [@Canvas unsafe code in the wild](https://internals.rust-lang.org/t/canvas-unsafe-code-in-the-wild/4990/16):
>
> Rc::drop calls RcBoxPtr::dec\_weak after decrementing the strong count and droping the content of the RcBox. This is somewhat interesting because RcBoxPtr::dec\_weak takes &Rc\<T\> as an argument and is a perfectly safe function, but it is actually called on an Rc that is in a bad state -- it doesn't satisfy the usual invariants that Rc typically satisfies. However, the Rc passed to dec\_weak is still a valid instance of a "syntactic Rc", so I don't think the compiler could exploit this in any way.

That's safety vs. definedness again. The language should not "guess" your types' semantics - if you don't use any "magic" attributes, the language should only care about whether your types are "syntactically" valid - e.g. you should be able to use an `RcBox` to store 2 random words (as long as you don't call any `Rc` functions in a way that would crash).

---

_[View the full topic](https://internals.rust-lang.org/t/role-of-ub-uninitialized-memory/5399)._
