Skip to content

Switch some std::oldmap to core::hashmap #5200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 135 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
c8d8f6c
Refactored make_absolute into functionality on the Path
mitsuhiko Feb 18, 2013
b07eab5
Improved windows path handling support
mitsuhiko Feb 19, 2013
c77c5c4
Added is_restricted() to path
mitsuhiko Feb 19, 2013
4ffff66
Fix vector syntax in error messages
jjjjw Feb 19, 2013
ad414de
Consolidate codes dealing with LLVM struct type
sanxiyn Feb 22, 2013
1afddff
remove oldsmallintmap
thestinger Feb 23, 2013
a712d82
libcore: remove default to_str implementations for pointer types
pkgw Feb 23, 2013
c4ef822
Fix slice printing
jjjjw Feb 24, 2013
f0d0b5c
Report error for non constant vector repeat count
youknowone Feb 21, 2013
4bf94a7
Emacs: Update emacs mode to be more similar to the vim mode.
huonw Feb 25, 2013
b8dd2d8
Fix typo in grammar: underscore, not minus, can appear amongst hex di…
pnkfelix Feb 25, 2013
a08eda4
test: Residual de-muting of the test suite. rs=demuting
pcwalton Feb 25, 2013
f63efdc
test: De-~mut the test suite. rs=demuting
pcwalton Feb 25, 2013
00d8db5
Revert "test: De-~mut the test suite. rs=demuting"
pcwalton Feb 25, 2013
08d870e
auto merge of #5095 : thestinger/rust/smallintmap, r=catamorphism
bors Feb 25, 2013
6e5705a
auto merge of #5072 : youknowone/rust/repeat_count, r=brson
bors Feb 26, 2013
abc4ea2
Stop parsing capture clauses
bstrie Feb 26, 2013
580df4d
auto merge of #5084 : oncemoreification/rust/issue-4517, r=brson
bors Feb 26, 2013
9616b3d
auto merge of #5089 : sanxiyn/rust/llvm-struct, r=pcwalton
bors Feb 26, 2013
046fc5e
Add Kang Seonghoon to AUTHORS
catamorphism Feb 26, 2013
40ffaea
auto merge of #5103 : dbaupp/rust/emacs-mode-update, r=graydon
bors Feb 26, 2013
e1a4e66
auto merge of #5109 : bstrie/rust/decapclause, r=pcwalton
bors Feb 26, 2013
6439e28
auto merge of #5111 : catamorphism/rust/authors, r=catamorphism
bors Feb 26, 2013
5098cf5
ARM C ABI implementation
sanxiyn Feb 26, 2013
9b8ce0d
libsyntax: Remove a mutable field from the tests. rs=demuting
pcwalton Feb 26, 2013
c483aab
librustc: Implement a lint mode for mutable structures; deny by defau…
pcwalton Feb 25, 2013
e2f9009
libcore: Move Cell to core and de-~mut core and std
pcwalton Feb 25, 2013
e3d43e4
test: De-~mut the test suite. rs=demuting
pcwalton Feb 25, 2013
24893e8
libsyntax: Stop parsing `~mut`
pcwalton Feb 25, 2013
96bdc34
librustc: De-[mut] librustc (remove all mutable arrays). rs=demuting
pcwalton Feb 26, 2013
8fceee6
test: De-[mut] (remove all mutable arrays from) the tests. rs=demuting
pcwalton Feb 26, 2013
9b08cd4
librustc: Make `&const [T]` mean the same thing as `&[const T]`
pcwalton Feb 26, 2013
b79c4dc
Add non-exhaustive check for match guards
youknowone Feb 26, 2013
42b0bac
Removed deprecated `str()` functions in int-template.rs and uint-temp…
Kimundi Feb 26, 2013
4a9d4aa
bench: Fix botched option dances. rs=demuting
pcwalton Feb 26, 2013
c9dd917
doc: Remove references to mut fields. rs=demuting
pcwalton Feb 26, 2013
565ec93
auto merge of #5110 : pcwalton/rust/and-const, r=pcwalton
bors Feb 26, 2013
ca147a0
Change imported macros to use leaky modules rather than leaky functions.
jbclements Feb 26, 2013
598e814
Hoist macro defs out of inner function
jbclements Feb 26, 2013
5328f3c
Remove space from the middle of path
jbclements Feb 26, 2013
5e319fb
Adds (more) test cases for auto_encode.
jbclements Feb 26, 2013
08b6057
Macros now leave scope
jbclements Feb 26, 2013
0e6d895
auto merge of #5119 : Kimundi/rust/incoming, r=catamorphism
bors Feb 26, 2013
85aaf39
Reimplement type_needs_drop on top of TypeContents
nikomatsakis Feb 26, 2013
44acefd
auto merge of #5126 : nikomatsakis/rust/issue-4808-representation-of-…
bors Feb 26, 2013
0ded562
auto merge of #5023 : mitsuhiko/rust/make-absolute-refactor, r=catamo…
bors Feb 26, 2013
7e08d8f
Don't warn about 'pub use' statements
alexcrichton Feb 25, 2013
681e6dd
Fix using the #[]-style attribute for unused imports
alexcrichton Feb 25, 2013
df48147
Fix unused imports in the tutorials
alexcrichton Feb 26, 2013
a8f07dc
auto merge of #5104 : alexcrichton/rust/fix-unused-import-pub, r=cata…
bors Feb 26, 2013
6aefaf2
typo-fixing and name-changes
jbclements Feb 26, 2013
0a0fcdb
librustc: offer suggestions for unresolved names.
luqmana Feb 23, 2013
f460c2a
Move levenshtein distance fn to core::str.
luqmana Feb 25, 2013
a0866d0
Adjust error messages for compile-fail tests.
luqmana Feb 27, 2013
3e6b2cf
Fix --disable-optimize-llvm
brson Feb 27, 2013
93a7f23
auto merge of #5115 : sanxiyn/rust/arm-abi, r=brson
bors Feb 27, 2013
28b50a4
auto merge of #5096 : luqmana/rust/spell, r=catamorphism
bors Feb 27, 2013
f432723
Add a 'start' lang item and use it instead of rust_start
brson Feb 27, 2013
99a902c
auto merge of #5120 : jbclements/rust/macros-have-scope, r=pcwalton
bors Feb 27, 2013
a3dbd07
auto merge of #5134 : brson/rust/disable-optimize-llvm, r=brson
bors Feb 27, 2013
f4e8ac2
auto merge of #5135 : brson/rust/start, r=pcwalton
bors Feb 27, 2013
5b0a2d1
treemap: improve the lazy iterator
thestinger Feb 26, 2013
8e492cc
auto merge of #5123 : thestinger/rust/treemap, r=nikomatsakis
bors Feb 27, 2013
5ae9b29
Fix: now sha1 result_str() return correct value
yjh0502 Feb 27, 2013
061a223
auto merge of #5118 : youknowone/rust/match-guard, r=nikomatsakis
bors Feb 27, 2013
c2be2ec
Added ToStr implementations for &[T] and @[T]
Kimundi Feb 27, 2013
8d7e6ef
libsyntax: Forbid `~mut` and `~const`. rs=demuting
pcwalton Feb 26, 2013
573a31d
libsyntax: Forbid mutable vectors. rs=demuting
pcwalton Feb 26, 2013
07c3f5c
librustc: Forbid `pub` or `priv` before trait implementations
pcwalton Feb 27, 2013
a6d9689
auto merge of #5136 : pcwalton/rust/impl-publicizing, r=pcwalton
bors Feb 27, 2013
35baf5b
Fix reversed current/expected type
youknowone Feb 24, 2013
5fc0ecc
auto merge of #5070 : youknowone/rust/struct-match2, r=nikomatsakis
bors Feb 27, 2013
1b10170
rt: Make some runtime calls work outside of task context
brson Feb 27, 2013
33e7a1f
auto merge of #5145 : Kimundi/rust/incoming, r=catamorphism
bors Feb 27, 2013
dbbdca3
testsuite: Update and un-xfail #3601 test
catamorphism Feb 23, 2013
6ebc761
auto merge of #5140 : yjh0502/rust/issue_4458, r=catamorphism
bors Feb 27, 2013
43d43ad
Turn old `drop` blocks into `Drop` traits
bstrie Feb 28, 2013
c623d21
Introduce lifetime declarations into the lists of type parameters.
nikomatsakis Feb 15, 2013
269409f
auto merge of #5149 : brson/rust/rt, r=brson
bors Feb 28, 2013
d0a1234
auto merge of #5141 : nikomatsakis/rust/region-syntax-expl-lifetimes,…
bors Feb 28, 2013
2f858de
Remove the last remnants of rtcalls
brson Feb 28, 2013
4a04a18
Convert NOTEs to FIXMEs
brson Feb 28, 2013
292e946
auto merge of #5106 : pnkfelix/rust/fix-docs, r=graydon
bors Feb 28, 2013
6bff18e
auto merge of #5098 : pkgw/rust/pr/issue4869, r=brson
bors Feb 28, 2013
fcd4af1
auto merge of #5152 : catamorphism/rust/issue-3601, r=catamorphism
bors Feb 28, 2013
c705440
auto merge of #5155 : bstrie/rust/dedrop, r=pcwalton
bors Feb 28, 2013
b171d0e
auto merge of #5159 : brson/rust/rtcall, r=brson
bors Feb 28, 2013
1bcd4c6
Add syntax highlighting support for GtkSourceView / GEdit
danniel Feb 28, 2013
833ad60
Fix license attribute on crates
sevrak Feb 28, 2013
107bf96
librustc: Mark all type implementations public. rs=impl-publicity
pcwalton Feb 27, 2013
09a2b4e
librustc: Make methods private if the impl is private
pcwalton Feb 27, 2013
2859c1a
librustc: Enforce cross-crate method privacy
pcwalton Feb 27, 2013
e1d3a4f
auto merge of #5156 : pcwalton/rust/method-privacy, r=pcwalton
bors Feb 28, 2013
febdb49
Change bare functions so that they are represented by a single pointer.
nikomatsakis Feb 28, 2013
0d30af1
auto merge of #5166 : danniel/rust/incoming, r=brson
bors Feb 28, 2013
b01d2ba
rt: Comment out an assert in rust_kernel. #4711
brson Feb 28, 2013
94a07b6
Fix leaking non-public 'use' statements with glob imports
alexcrichton Feb 25, 2013
f2837fa
Fix leaking immediate children and types via glob imports
alexcrichton Feb 26, 2013
2df07dd
Fix implicit leaks of imports throughout libraries
alexcrichton Feb 25, 2013
78d5091
core: Remove unwrap_shared_mutable_state. #4436
brson Feb 28, 2013
5680ec0
auto merge of #5113 : alexcrichton/rust/issue-4366, r=catamorphism
bors Feb 28, 2013
405a35c
core: Address XXX, make static constants for strings used when string…
catamorphism Mar 1, 2013
916d1a9
auto merge of #5176 : brson/rust/unwrap_shared_mutable_state, r=nikom…
bors Mar 1, 2013
4ecb672
Remove legacy object creation mode, and convert remaining uses of it
nikomatsakis Feb 27, 2013
3267593
Register snapshots
catamorphism Feb 28, 2013
66f9e60
auto merge of #5177 : catamorphism/rust/register-snapshots, r=catamor…
bors Mar 1, 2013
6b6d15a
Remove code that was awaiting a snapshot
catamorphism Mar 1, 2013
b7e7297
auto merge of #5147 : nikomatsakis/rust/remove-legacy-trait-table, r=…
bors Mar 1, 2013
d66a3dd
testsuite: Re-xfail record-trailing-comma
catamorphism Mar 1, 2013
a660bb3
auto merge of #5180 : catamorphism/rust/post-snapshot, r=catamorphism
bors Mar 1, 2013
1d34a55
auto merge of #5162 : brson/rust/fixmes, r=brson
bors Mar 1, 2013
c355f17
Merge remote branch 'sevrak/issue-5164' into incoming
pcwalton Mar 1, 2013
9519ee5
librustc: "APL2" -> "ASL2". rs=license-fix
pcwalton Mar 1, 2013
02a4b5b
Merge remote branch 'nmatsakis/issue-4808-representation-of-extern-fn…
pcwalton Mar 1, 2013
50c08db
Merge pull request #5178 from catamorphism/constant-buffers
pcwalton Mar 1, 2013
cab8ec2
librustc: Add missing import. rs=burningtree
pcwalton Mar 1, 2013
228e838
`std::net::tcp` docs: Use current syntax and types
ben0x539 Mar 1, 2013
ae89328
Contributing.md: remove spurious verb
ben0x539 Mar 1, 2013
bcf6268
Rename core::private to core::unstable. #4743
brson Feb 28, 2013
332c046
docs/rust.md: Mention unit-like structs along with other struct types
ben0x539 Mar 1, 2013
382143a
doc/rust.md: Demonstrate the `f::<T>()` syntax more often
ben0x539 Mar 2, 2013
ca9549b
Avoid calling to_vec() unnecessarily in parser.
nikomatsakis Mar 2, 2013
4c35a00
Register FreeBSD snapshot
brson Mar 2, 2013
9639ca5
core: Move core::rt to core::unstable::lang
brson Mar 2, 2013
657c442
Merge remote branch 'nmatsakis/parser-perf-problem' into incoming
pcwalton Mar 2, 2013
0fd1b58
auto merge of #5190 : brson/rust/snap, r=brson
bors Mar 2, 2013
dcd2f73
Fix some struct-tuple def prettyprint issues
sp0 Mar 2, 2013
10929ed
auto merge of #5165 : brson/rust/unstable, r=brson
bors Mar 2, 2013
36e8989
auto merge of #5185 : ben0x539/rust/net-tcp-docs, r=brson
bors Mar 2, 2013
3f91f32
auto merge of #5186 : ben0x539/rust/contributing, r=brson
bors Mar 2, 2013
0917e13
auto merge of #5187 : ben0x539/rust/docs-unit-struct, r=catamorphism
bors Mar 2, 2013
10faa52
auto merge of #5188 : ben0x539/rust/doc-call-generic-fn, r=catamorphism
bors Mar 2, 2013
2f90112
auto merge of #5191 : brson/rust/movert, r=brson
bors Mar 2, 2013
d3b94f6
auto merge of #5193 : sethpink/rust/struct-tup-pp, r=catamorphism
bors Mar 2, 2013
e09355c
remove some oldmap::Hashmap from librustc
yjh0502 Mar 2, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Josh Matthews <[email protected]>
Joshua Clark <[email protected]>
Joshua Wise <[email protected]>
Jyun-Yan You <[email protected]>
Kang Seonghoon <[email protected]>
Kelly Wilson <[email protected]>
Kevin Atkinson <[email protected]>
Kevin Cantu <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ You're not off the hook even if you just stick to documentation; code examples i
Pull requests will be treated as "review requests",
and we will give feedback we expect to see corrected on [style](https://github.com/mozilla/rust/wiki/Note-style-guide) and substance before pulling.
Changes contributed via pull request should focus on a single issue at a time, like any other.
We will not look accept pull-requests that try to "sneak" unrelated changes in.
We will not accept pull-requests that try to "sneak" unrelated changes in.

Normally, all pull requests must include regression tests (see [Note-testsuite](https://github.com/mozilla/rust/wiki/Note-testsuite)) that test your change.
Occasionally, a change will be very difficult to test for.
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ do
LLVM_BUILD_DIR=${CFG_BUILD_DIR}llvm/$t
if [ ! -z "$CFG_DISABLE_OPTIMIZE_LLVM" ]
then
LLVM_DBG_OPTS=""
LLVM_DBG_OPTS="--enable-debug-symbols --disable-optimized"
# Just use LLVM straight from its build directory to
# avoid 'make install' time
LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug+Asserts
Expand Down
40 changes: 32 additions & 8 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ the following forms:
num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
| '0' [ [ dec_digit | '_' ] + num_suffix ?
| 'b' [ '1' | '0' | '_' ] + int_suffix ?
| 'x' [ hex_digit | '-' ] + int_suffix ? ] ;
| 'x' [ hex_digit | '_' ] + int_suffix ? ] ;

num_suffix : int_suffix | float_suffix ;

Expand Down Expand Up @@ -908,6 +908,11 @@ function defined above on `[1, 2]` will instantiate type parameter `T`
with `int`, and require the closure parameter to have type
`fn(int)`.

The type parameters can also be explicitly supplied in a trailing
[path](#paths) component after the function name. This might be necessary
if there is not sufficient context to determine the type parameters. For
example, `sys::size_of::<u32>() == 4`.

Since a parameter type is opaque to the generic function, the set of
operations that can be performed on it is limited. Values of parameter
type can always be moved, but they can only be copied when the
Expand Down Expand Up @@ -1085,6 +1090,15 @@ let p = Point(10, 11);
let px: int = match p { Point(x, _) => x };
~~~~

A _unit-like struct_ is a structure without any fields, defined by leaving off the fields list entirely.
Such types will have a single value, just like the [unit value `()`](#unit-and-boolean-literals) of the unit type.
For example:

~~~~
struct Cookie;
let c = [Cookie, Cookie, Cookie, Cookie];
~~~~

### Enumerations

An _enumeration_ is a simultaneous definition of a nominal [enumerated type](#enumerated-types) as well as a set of *constructors*,
Expand Down Expand Up @@ -1590,7 +1604,8 @@ struct_expr : expr_path '{' ident ':' expr
[ ',' ident ':' expr ] *
[ ".." expr ] '}' |
expr_path '(' expr
[ ',' expr ] * ')'
[ ',' expr ] * ')' |
expr_path
~~~~~~~~

There are several forms of structure expressions.
Expand All @@ -1600,24 +1615,28 @@ providing the field values of a new instance of the structure.
A field name can be any identifier, and is separated from its value expression by a colon.
To indicate that a field is mutable, the `mut` keyword is written before its name.

A _tuple structure expression_ constists of the [path](#paths) of a [structure item](#structures),
A _tuple structure expression_ consists of the [path](#paths) of a [structure item](#structures),
followed by a parenthesized list of one or more comma-separated expressions
(in other words, the path of a structured item followed by a tuple expression).
The structure item must be a tuple structure item.

A _unit-like structure expression_ consists only of the [path](#paths) of a [structure item](#structures).

The following are examples of structure expressions:

~~~~
# struct Point { x: float, y: float }
# struct TuplePoint(float, float);
# mod game { pub struct User { name: &str, age: uint, mut score: uint } }
# use game;
# mod game { pub struct User { name: &str, age: uint, score: uint } }
# struct Cookie; fn some_fn<T>(t: T) {}
Point {x: 10f, y: 20f};
TuplePoint(10f, 20f);
let u = game::User {name: "Joe", age: 35u, mut score: 100_000};
let u = game::User {name: "Joe", age: 35u, score: 100_000};
some_fn::<Cookie>(Cookie);
~~~~

A structure expression forms a new value of the named structure type.
Note that for a given *unit-like* structure type, this will always be the same value.

A structure expression can terminate with the syntax `..` followed by an expression to denote a functional update.
The expression following `..` (the base) must be of the same structure type as the new structure type being formed.
Expand Down Expand Up @@ -2041,12 +2060,14 @@ an optional reference slot to serve as the function's output, bound to the
`lval` on the right hand side of the call. If the function eventually returns,
then the expression completes.

An example of a call expression:
Some examples of call expressions:

~~~~
# fn add(x: int, y: int) -> int { 0 }
# use core::from_str::FromStr::from_str;

let x: int = add(1, 2);
let pi = from_str::<f32>("3.14");
~~~~

### Lambda expressions
Expand Down Expand Up @@ -2644,7 +2665,10 @@ the resulting `struct` value will always be laid out in memory in the order spec
The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
to restrict access to implementation-private data in a structure.

A `tuple struct` type is just like a structure type, except that the fields are anonymous.
A _tuple struct_ type is just like a structure type, except that the fields are anonymous.

A _unit-like struct_ type is like a structure type, except that it has no fields.
The one value constructed by the associated [structure expression](#structure-expression) is the only value that inhabits such a type.

### Enumerated types

Expand Down
161 changes: 4 additions & 157 deletions doc/tutorial-borrowed-ptr.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ mutations:
~~~ {.xfail-test}
fn example3() -> int {
struct R { g: int }
struct S { mut f: ~R }
struct S { f: ~R }

let mut x = ~S {mut f: ~R {g: 3}};
let mut x = ~S {f: ~R {g: 3}};
let y = &x.f.g;
x = ~S {mut f: ~R {g: 4}}; // Error reported here.
x.f = ~R {g: 5}; // Error reported here.
x = ~S {f: ~R {g: 4}}; // Error reported here.
x.f = ~R {g: 5}; // Error reported here.
*y
}
~~~
Expand All @@ -362,91 +362,6 @@ In this case, two errors are reported, one when the variable `x` is
modified and another when `x.f` is modified. Either modification would
invalidate the pointer `y`.

Things get trickier when the unique box is not uniquely owned by the
stack frame, or when there is no way for the compiler to determine the
box's owner. Consider a program like this:

~~~ {.xfail-test}
struct R { g: int }
struct S { mut f: ~R }
fn example5a(x: @S, callback: @fn()) -> int {
let y = &x.f.g; // Error reported here.
...
callback();
...
# return 0;
}
~~~

Here the heap looks something like:

~~~ {.notrust}
Stack Managed Heap Exchange Heap

x +------+ +-------------+ +------+
| @... | ----> | mut f: ~... | --+-> | g: 3 |
y +------+ +-------------+ | +------+
| &int | -------------------------+
+------+
~~~

In this case, the owning reference to the value being borrowed is
`x.f`. Moreover, `x.f` is both mutable and *aliasable*. Aliasable
means that there may be other pointers to that same managed box, so
even if the compiler were to prove an absence of mutations to `x.f`,
code could mutate `x.f` indirectly by changing an alias of
`x`. Therefore, to be safe, the compiler only accepts *pure* actions
during the lifetime of `y`. We define what "pure" means in the section
on [purity](#purity).

Besides ensuring purity, the only way to borrow the interior of a
unique found in aliasable memory is to ensure that the borrowed field
itself is also unique, as in the following example:

~~~
struct R { g: int }
struct S { f: ~R }
fn example5b(x: @S) -> int {
let y = &x.f.g;
...
# return 0;
}
~~~

Here, the field `f` is not declared as mutable. But that is enough for
the compiler to know that, even if aliases to `x` exist, the field `f`
cannot be changed and hence the unique box `g` will remain valid.

If you do have a unique box in a mutable field, and you wish to borrow
it, one option is to use the swap operator to move that unique box
onto your stack:

~~~
struct R { g: int }
struct S { mut f: ~R }
fn example5c(x: @S) -> int {
let mut v = ~R {g: 0};
v <-> x.f; // Swap v and x.f
{ // Block constrains the scope of `y`:
let y = &v.g;
...
}
x.f = v; // Replace x.f
...
# return 0;
}
~~~

Of course, this has the side effect of modifying your managed box for
the duration of the borrow, so it only works when you know that you
won't be accessing that same box for the duration of the loan. Also,
it is sometimes necessary to introduce additional blocks to constrain
the scope of the loan. In this example, the borrowed pointer `y`
would still be in scope when you moved the value `v` back into `x.f`,
and hence moving `v` would be considered illegal. You cannot move
values if they are the targets of valid outstanding loans. Introducing
the block restricts the scope of `y`, making the move legal.

# Borrowing and enums

The previous example showed that the type system forbids any borrowing
Expand Down Expand Up @@ -558,11 +473,6 @@ permit `ref` bindings into data owned by the stack frame even if the
data are mutable, but otherwise it requires that the data reside in
immutable memory.

> ***Note:*** Right now, pattern bindings not explicitly annotated
> with `ref` or `copy` use a special mode of "implicit by reference".
> This is changing as soon as we finish updating all the existing code
> in the compiler that relies on the current settings.

# Returning borrowed pointers

So far, all of the examples we've looked at use borrowed pointers in a
Expand Down Expand Up @@ -745,69 +655,6 @@ fn select<T>(shape: &Shape, threshold: float,

This is equivalent to the previous definition.

# Purity

As mentioned before, the Rust compiler offers a kind of escape hatch
that permits borrowing of any data, as long as the actions that occur
during the lifetime of the borrow are pure. Pure actions are those
that only modify data owned by the current stack frame. The compiler
can therefore permit arbitrary pointers into the heap, secure in the
knowledge that no pure action will ever cause them to become
invalidated (the compiler must still track data on the stack which is
borrowed and enforce those rules normally, of course). A pure function
in Rust is referentially transparent: it returns the same results
given the same (observably equivalent) inputs. That is because while
pure functions are allowed to modify data, they may only modify
*stack-local* data, which cannot be observed outside the scope of the
function itself. (Using an `unsafe` block invalidates this guarantee.)

Let’s revisit a previous example and show how purity can affect
typechecking. Here is `example5a()`, which borrows the interior of a
unique box found in an aliasable, mutable location, only now we’ve
replaced the `...` with some specific code:

~~~
struct R { g: int }
struct S { mut f: ~R }
fn example5a(x: @S ...) -> int {
let y = &x.f.g; // Unsafe
*y + 1
}
~~~

The new code simply returns an incremented version of `y`. This code
clearly doesn't mutate the heap, so the compiler is satisfied.

But suppose we wanted to pull the increment code into a helper, like
this:

~~~
fn add_one(x: &int) -> int { *x + 1 }
~~~

We can now update `example5a()` to use `add_one()`:

~~~
# struct R { g: int }
# struct S { mut f: ~R }
# pure fn add_one(x: &int) -> int { *x + 1 }
fn example5a(x: @S ...) -> int {
let y = &x.f.g;
add_one(y) // Error reported here
}
~~~

But now the compiler will report an error again. The reason is that it
only considers one function at a time (like most typecheckers), and
so it does not know that `add_one()` consists of pure code. We can
help the compiler by labeling `add_one()` as pure:

~~~
pure fn add_one(x: &int) -> int { *x + 1 }
~~~

With this change, the modified version of `example5a()` will again compile.

# Conclusion

So there you have it: a (relatively) brief tour of the borrowed pointer
Expand Down
14 changes: 7 additions & 7 deletions doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,21 @@ extern mod std;
use libc::c_ulonglong;

struct timeval {
mut tv_sec: c_ulonglong,
mut tv_usec: c_ulonglong
tv_sec: c_ulonglong,
tv_usec: c_ulonglong
}

#[nolink]
extern mod lib_c {
fn gettimeofday(tv: *timeval, tz: *()) -> i32;
fn gettimeofday(tv: *mut timeval, tz: *()) -> i32;
}
fn unix_time_in_microseconds() -> u64 {
unsafe {
let x = timeval {
mut tv_sec: 0 as c_ulonglong,
mut tv_usec: 0 as c_ulonglong
let mut x = timeval {
tv_sec: 0 as c_ulonglong,
tv_usec: 0 as c_ulonglong
};
lib_c::gettimeofday(ptr::addr_of(&x), ptr::null());
lib_c::gettimeofday(&mut x, ptr::null());
return (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
}
}
Expand Down
2 changes: 0 additions & 2 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,6 @@ Here is the function that implements the child task:

~~~~
# use std::comm::DuplexStream;
# use comm::{Port, Chan};
fn stringifier(channel: &DuplexStream<~str, uint>) {
let mut value: uint;
loop {
Expand All @@ -491,7 +490,6 @@ Here is the code for the parent task:

~~~~
# use std::comm::DuplexStream;
# use comm::{Port, Chan};
# use task::spawn;
# fn stringifier(channel: &DuplexStream<~str, uint>) {
# let mut value: uint;
Expand Down
Loading