You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most notably, I removed the "foldl" example in the section on pure functions,
as IIRC this is no longer something you need an unsafe block for
(pure functions are as pure as their arguments). Feel free to add
an example where an unsafe block really is needed.
Copy file name to clipboardExpand all lines: doc/rust.md
+44-81Lines changed: 44 additions & 81 deletions
Original file line number
Diff line number
Diff line change
@@ -703,22 +703,19 @@ otherwise compose the item body. The meaning of these scoped items is the same
703
703
as if the item was declared outside the scope -- it is still a static item --
704
704
except that the item's *path name* within the module namespace is qualified by
705
705
the name of the enclosing item, or is private to the enclosing item (in the
706
-
case of functions). The exact locations in which sub-items may be declared is
707
-
given by the grammar.
706
+
case of functions).
707
+
The grammar specifies the exact locations in which sub-item declarations may appear.
708
708
709
709
### Type Parameters
710
710
711
-
All items except modules may be *parametrized* by type. Type parameters are
711
+
All items except modules may be *parameterized* by type. Type parameters are
712
712
given as a comma-separated list of identifiers enclosed in angle brackets
713
-
(`<...>`), after the name of the item and before its definition. The type
714
-
parameters of an item are considered "part of the name", not the type of the
715
-
item; in order to refer to the type-parametrized item, a referencing
716
-
[path](#paths) must in general provide type arguments as a list of
717
-
comma-separated types enclosed within angle brackets. In practice, the
718
-
type-inference system can usually infer such argument types from
719
-
context. There are no general type-parametric types, only type-parametric
720
-
items.
721
-
713
+
(`<...>`), after the name of the item and before its definition.
714
+
The type parameters of an item are considered "part of the name", not part of the type of the item.
715
+
A referencing [path](#paths) must (in principle) provide type arguments as a list of comma-separated types enclosed within angle brackets, in order to refer to the type-parameterized item.
716
+
In practice, the type-inference system can usually infer such argument types from context.
717
+
There are no general type-parametric types, only type-parametric items.
718
+
That is, Rust has no notion of type abstraction: there are no first-class "forall" types.
722
719
723
720
### Modules
724
721
@@ -763,9 +760,9 @@ mod math {
763
760
view_item : extern_mod_decl | use_decl ;
764
761
~~~~~~~~
765
762
766
-
A view item manages the namespace of a module; it does not define new items
767
-
but simply changes the visibility of other items. There are several kinds of
768
-
view item:
763
+
A view item manages the namespace of a module.
764
+
View items do not define new items, but rather, simply change other items' visibilit.
@@ -857,13 +854,9 @@ If a sequence of such redirections form a cycle or cannot be unambiguously resol
857
854
858
855
### Functions
859
856
860
-
A _function item_ defines a sequence of [statements](#statements) and an
861
-
optional final [expression](#expressions) associated with a name and a set of
862
-
parameters. Functions are declared with the keyword `fn`. Functions declare a
863
-
set of *input*[*slots*](#memory-slots) as parameters, through which the
864
-
caller passes arguments into the function, and an *output*
865
-
[*slot*](#memory-slots) through which the function passes results back to
866
-
the caller.
857
+
A _function item_ defines a sequence of [statements](#statements) and an optional final [expression](#expressions), along with a name and a set of parameters.
858
+
Functions are declared with the keyword `fn`.
859
+
Functions declare a set of *input*[*slots*](#memory-slots) as parameters, through which the caller passes arguments into the function, and an *output*[*slot*](#memory-slots) through which the function passes results back to the caller.
867
860
868
861
A function may also be copied into a first class *value*, in which case the
869
862
value has the corresponding [*function type*](#function-types), and can be
@@ -941,23 +934,19 @@ Specifically, the following operations are considered unsafe:
941
934
942
935
##### Unsafe blocks
943
936
944
-
A block of code can also be prefixed with the `unsafe` keyword,
945
-
to permit a sequence of unsafe operations in an otherwise-safe function.
946
-
This facility exists because the static semantics of a Rust are a necessary approximation of the dynamic semantics.
947
-
When a programmer has sufficient conviction that a sequence of unsafe operations is actually safe,
948
-
they can encapsulate that sequence (taken as a whole) within an `unsafe` block.
949
-
The compiler will consider uses of such code "safe", to the surrounding context.
937
+
A block of code can also be prefixed with the `unsafe` keyword, to permit a sequence of unsafe operations in an otherwise-safe function.
938
+
This facility exists because the static semantics of Rust are a necessary approximation of the dynamic semantics.
939
+
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.
950
940
951
941
952
942
#### Pure functions
953
943
954
944
A pure function declaration is identical to a function declaration, except that
955
945
it is declared with the additional keyword `pure`. In addition, the typechecker
956
946
checks the body of a pure function with a restricted set of typechecking rules.
957
-
A pure function
958
-
959
-
* may not contain an assignment or self-call expression; and
960
-
* may only call other pure functions, not general functions.
947
+
A pure function may only modify data owned by its own stack frame.
948
+
So, a pure function may modify a local variable allocated on the stack, but not a mutable reference that it takes as an argument.
949
+
A pure function may only call other pure functions, not general functions.
0 commit comments