about summary refs log tree commit diff
path: root/doc/rust.md
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2013-03-16 11:11:31 -0700
committerPatrick Walton <pcwalton@mimiga.net>2013-03-18 17:21:16 -0700
commite78f2e2ac577f9c47cd58af52d3bcd496254545d (patch)
treef05564837fe02f676458ea86b705709715c44017 /doc/rust.md
parentc4db4faefaf13ac814f34c2a6cf105b7684de019 (diff)
downloadrust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.tar.gz
rust-e78f2e2ac577f9c47cd58af52d3bcd496254545d.zip
librustc: Make the compiler ignore purity.
For bootstrapping purposes, this commit does not remove all uses of
the keyword "pure" -- doing so would cause the compiler to no longer
bootstrap due to some syntax extensions ("deriving" in particular).
Instead, it makes the compiler ignore "pure". Post-snapshot, we can
remove "pure" from the language.

There are quite a few (~100) borrow check errors that were essentially
all the result of mutable fields or partial borrows of `@mut`. Per
discussions with Niko I think we want to allow partial borrows of
`@mut` but detect obvious footguns. We should also improve the error
message when `@mut` is erroneously reborrowed.
Diffstat (limited to 'doc/rust.md')
-rw-r--r--doc/rust.md45
1 files changed, 4 insertions, 41 deletions
diff --git a/doc/rust.md b/doc/rust.md
index f64877a69ba..6be428ef279 100644
--- a/doc/rust.md
+++ b/doc/rust.md
@@ -214,7 +214,7 @@ false fn for
 if impl
 let loop
 match mod mut
-priv pub pure
+priv pub
 ref return
 self static struct super
 true trait type
@@ -936,7 +936,6 @@ Specifically, the following operations are considered unsafe:
 
   - Dereferencing a [raw pointer](#pointer-types).
   - Casting a [raw pointer](#pointer-types) to a safe pointer type.
-  - Breaking the [purity-checking rules](#pure-functions) in a `pure` function.
   - Calling an unsafe function.
 
 ##### Unsafe blocks
@@ -946,42 +945,6 @@ This facility exists because the static semantics of Rust are a necessary approx
 When a programmer has sufficient conviction that a sequence of unsafe operations is actually safe, they can encapsulate that sequence (taken as a whole) within an `unsafe` block. The compiler will consider uses of such code "safe", to the surrounding context.
 
 
-#### Pure functions
-
-A pure function declaration is identical to a function declaration, except that
-it is declared with the additional keyword `pure`. In addition, the typechecker
-checks the body of a pure function with a restricted set of typechecking rules.
-A pure function may only modify data owned by its own stack frame.
-So, a pure function may modify a local variable allocated on the stack, but not a mutable reference that it takes as an argument.
-A pure function may only call other pure functions, not general functions.
-
-An example of a pure function:
-
-~~~~
-pure fn lt_42(x: int) -> bool {
-    return (x < 42);
-}
-~~~~
-
-Pure functions may call other pure functions:
-
-~~~~{.xfail-test}
-pure fn pure_length<T>(ls: List<T>) -> uint { ... }
-
-pure fn nonempty_list<T>(ls: List<T>) -> bool { pure_length(ls) > 0u }
-~~~~
-
-These purity-checking rules approximate the concept of referential transparency:
-that a call-expression could be rewritten with the literal-expression of its return value, without changing the meaning of the program.
-Since they are an approximation, sometimes these rules are *too* restrictive.
-Rust allows programmers to violate these rules using [`unsafe` blocks](#unsafe-blocks), which we already saw.
-As with any `unsafe` block, those that violate static purity carry transfer the burden of safety-proof from the compiler to the programmer.
-Programmers should exercise caution when breaking such rules.
-
-For more details on purity, see [the borrowed pointer tutorial][borrow].
-
-[borrow]: tutorial-borrowed-ptr.html
-
 #### Diverging functions
 
 A special kind of function can be declared with a `!` character where the
@@ -1246,10 +1209,10 @@ For example:
 
 ~~~~
 trait Num {
-    static pure fn from_int(n: int) -> Self;
+    static fn from_int(n: int) -> Self;
 }
 impl Num for float {
-    static pure fn from_int(n: int) -> float { n as float }
+    static fn from_int(n: int) -> float { n as float }
 }
 let x: float = Num::from_int(42);
 ~~~~
@@ -2643,7 +2606,7 @@ Raw pointers (`*`)
 ### Function types
 
 The function type-constructor `fn` forms new function types. A function type
-consists of a set of function-type modifiers (`pure`, `unsafe`, `extern`, etc.),
+consists of a set of function-type modifiers (`unsafe`, `extern`, etc.),
 a sequence of input slots and an output slot.
 
 An example of a `fn` type: