add forum link
authorRalf Jung <post@ralfj.de>
Wed, 15 Jul 2020 11:10:47 +0000 (13:10 +0200)
committerRalf Jung <post@ralfj.de>
Wed, 15 Jul 2020 11:10:47 +0000 (13:10 +0200)
ralf/_posts/2020-07-15-unused-data.md

index 16068e87b781dd52f2d0ec44eac186c47f14c101..afdfff91d7aae85c5e652e8642292bbfbcdc9949 100644 (file)
@@ -1,6 +1,7 @@
 ---
 title: "Why even unused data needs to be valid"
 categories: rust
 ---
 title: "Why even unused data needs to be valid"
 categories: rust
+forum: https://internals.rust-lang.org/t/why-even-unused-data-needs-to-be-valid/12734
 ---
 
 The Rust compiler has a few assumptions that it makes about the behavior of all code.
 ---
 
 The Rust compiler has a few assumptions that it makes about the behavior of all code.
@@ -9,7 +10,7 @@ Since Rust is a safe-by-default language, programmers usually do not have to wor
 but authors of `unsafe` code are themselves responsible for upholding these requirements.
 
 Those assumptions are [listed in the Rust reference](https://doc.rust-lang.org/reference/behavior-considered-undefined.html).
 but authors of `unsafe` code are themselves responsible for upholding these requirements.
 
 Those assumptions are [listed in the Rust reference](https://doc.rust-lang.org/reference/behavior-considered-undefined.html).
-The one that seems to be most surprising to many people is the clause which says that unsafe code may not *produce* "[...] an invalid value, even in private fields and locals".
+The one that seems to be most surprising to many people is the clause which says that Rust code may not *produce* "[...] an invalid value, even in private fields and locals".
 The reference goes on to explain that "*producing* a value happens any time a value is assigned to or read from a place, passed to a function/primitive operation or returned from a function/primitive operation".
 In other words, even just *constructing*, for example, an invalid `bool`, is Undefined Behavior---no matter whether that `bool` is ever actually "used" by the program.
 The purpose of this post is to explain why that rule is so strict.
 The reference goes on to explain that "*producing* a value happens any time a value is assigned to or read from a place, passed to a function/primitive operation or returned from a function/primitive operation".
 In other words, even just *constructing*, for example, an invalid `bool`, is Undefined Behavior---no matter whether that `bool` is ever actually "used" by the program.
 The purpose of this post is to explain why that rule is so strict.
@@ -85,4 +86,4 @@ But this means our hands are pretty much tied: since we cannot take into account
 To support inlining and outlining, we also do not want the function boundary to be relevant, which ultimately leads us to the rule that Rust requires today: whenever data of a given type is *produced* anywhere, the data needs to be valid for that type.
 
 I hope this post was helpful in explaining why Undefined Behavior in Rust is defined the way it is.
 To support inlining and outlining, we also do not want the function boundary to be relevant, which ultimately leads us to the rule that Rust requires today: whenever data of a given type is *produced* anywhere, the data needs to be valid for that type.
 
 I hope this post was helpful in explaining why Undefined Behavior in Rust is defined the way it is.
-As usual, if you have any comments or questions, let me know in the forums.
+As usual, if you have any comments or questions, let me know in the [forums](https://internals.rust-lang.org/t/why-even-unused-data-needs-to-be-valid/12734).