Skip to content
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

Consistent formatting for args and attrs #11646

Closed
wants to merge 9 commits into from
20 changes: 10 additions & 10 deletions doc/guide-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
# Unit testing in Rust

Rust has built in support for simple unit testing. Functions can be
marked as unit tests using the 'test' attribute.
marked as unit tests using the `test` attribute.

~~~
#[test]
Expand All @@ -44,13 +44,13 @@ fn return_none_if_empty() {

A test function's signature must have no arguments and no return
value. To run the tests in a crate, it must be compiled with the
'--test' flag: `rustc myprogram.rs --test -o myprogram-tests`. Running
`--test` flag: `rustc myprogram.rs --test -o myprogram-tests`. Running
the resulting executable will run all the tests in the crate. A test
is considered successful if its function returns; if the task running
the test fails, through a call to `fail!`, a failed `check` or
`assert`, or some other (`assert_eq`, ...) means, then the test fails.

When compiling a crate with the '--test' flag '--cfg test' is also
When compiling a crate with the `--test` flag `--cfg test` is also
implied, so that tests can be conditionally compiled.

~~~
Expand All @@ -63,18 +63,18 @@ mod tests {
}
~~~

Additionally #[test] items behave as if they also have the
#[cfg(test)] attribute, and will not be compiled when the --test flag
Additionally `#[test]` items behave as if they also have the
`#[cfg(test)]` attribute, and will not be compiled when the `--test` flag
is not used.

Tests that should not be run can be annotated with the 'ignore'
Tests that should not be run can be annotated with the `ignore`
attribute. The existence of these tests will be noted in the test
runner output, but the test will not be run. Tests can also be ignored
by configuration so, for example, to ignore a test on windows you can
write `#[ignore(cfg(target_os = "win32"))]`.

Tests that are intended to fail can be annotated with the
'should_fail' attribute. The test will be run, and if it causes its
`should_fail` attribute. The test will be run, and if it causes its
task to fail then the test will be counted as successful; otherwise it
will be counted as a failure. For example:

Expand All @@ -87,11 +87,11 @@ fn test_out_of_bounds_failure() {
}
~~~

A test runner built with the '--test' flag supports a limited set of
A test runner built with the `--test` flag supports a limited set of
arguments to control which tests are run: the first free argument
passed to a test runner specifies a filter used to narrow down the set
of tests being run; the '--ignored' flag tells the test runner to run
only tests with the 'ignore' attribute.
of tests being run; the `--ignored` flag tells the test runner to run
only tests with the `ignore` attribute.

## Parallelism

Expand Down
81 changes: 50 additions & 31 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -2211,12 +2211,9 @@ dereferences (`*expr`), [indexing expressions](#index-expressions)
(`expr[expr]`), and [field references](#field-expressions) (`expr.f`).
All other expressions are rvalues.

The left operand of an [assignment](#assignment-expressions),
[binary move](#binary-move-expressions) or
The left operand of an [assignment](#assignment-expressions) or
[compound-assignment](#compound-assignment-expressions) expression is an lvalue context,
as is the single operand of a unary [borrow](#unary-operator-expressions),
or [move](#unary-move-expressions) expression,
and _both_ operands of a [swap](#swap-expressions) expression.
as is the single operand of a unary [borrow](#unary-operator-expressions).
All other expression contexts are rvalue contexts.

When an lvalue is evaluated in an _lvalue context_, it denotes a memory location;
Expand All @@ -2229,9 +2226,8 @@ A temporary's lifetime equals the largest lifetime of any reference that points

When a [local variable](#memory-slots) is used
as an [rvalue](#lvalues-rvalues-and-temporaries)
the variable will either be [moved](#move-expressions) or copied,
depending on its type.
For types that contain [owning pointers](#owning-pointers)
the variable will either be moved or copied, depending on its type.
For types that contain [owning pointers](#pointer-types)
or values that implement the special trait `Drop`,
the variable is moved.
All other types are copied.
Expand Down Expand Up @@ -2890,16 +2886,26 @@ match x {

The first pattern matches lists constructed by applying `Cons` to any head value, and a
tail value of `~Nil`. The second pattern matches _any_ list constructed with `Cons`,
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
`C` has exactly one argument, while the pattern `C(..)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.

To execute an `match` expression, first the head expression is evaluated, then
its value is sequentially compared to the patterns in the arms until a match
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern
`C(_)` is only type-correct if `C` has exactly one argument, while the pattern `C(..)` is
type-correct for any enum variant `C`, regardless of how many arguments `C` has.

A `match` behaves differently depending on whether or not the head expression
is an [lvalue or an rvalue](#lvalues-rvalues-and-temporaries).
If the head expression is an rvalue, it is
first evaluated into a temporary location, and the resulting value
is sequentially compared to the patterns in the arms until a match
is found. The first arm with a matching pattern is chosen as the branch target
of the `match`, any variables bound by the pattern are assigned to local
variables in the arm's block, and control enters the block.

An example of an `match` expression:
When the head expression is an lvalue, the match does not allocate a
temporary location (however, a by-value binding may copy or move from
the lvalue). When possible, it is preferable to match on lvalues, as the
lifetime of these matches inherits the lifetime of the lvalue, rather
than being restricted to the inside of the match.

An example of a `match` expression:

~~~~
# fn process_pair(a: int, b: int) { }
Expand Down Expand Up @@ -2929,19 +2935,31 @@ Patterns that bind variables
default to binding to a copy or move of the matched value
(depending on the matched value's type).
This can be changed to bind to a reference by
using the ```ref``` keyword,
or to a mutable reference using ```ref mut```.

A pattern that's just an identifier,
like `Nil` in the previous answer,
could either refer to an enum variant that's in scope,
or bind a new variable.
The compiler resolves this ambiguity by forbidding variable bindings that occur in ```match``` patterns from shadowing names of variants that are in scope.
For example, wherever ```List``` is in scope,
a ```match``` pattern would not be able to bind ```Nil``` as a new name.
The compiler interprets a variable pattern `x` as a binding _only_ if there is no variant named `x` in scope.
A convention you can use to avoid conflicts is simply to name variants with upper-case letters,
and local variables with lower-case letters.
using the `ref` keyword,
or to a mutable reference using `ref mut`.

Patterns can also dereference pointers by using the `&`,
`~` or `@` symbols, as appropriate. For example, these two matches
on `x: &int` are equivalent:

~~~~
# let x = &3;
let y = match *x { 0 => "zero", _ => "some" };
let z = match x { &0 => "zero", _ => "some" };

assert_eq!(y, z);
~~~~

A pattern that's just an identifier, like `Nil` in the previous answer,
could either refer to an enum variant that's in scope, or bind a new variable.
The compiler resolves this ambiguity by forbidding variable bindings that occur
in `match` patterns from shadowing names of variants that are in scope.
For example, wherever `List` is in scope,
a `match` pattern would not be able to bind `Nil` as a new name.
The compiler interprets a variable pattern `x` as a binding _only_ if there is
no variant named `x` in scope.
A convention you can use to avoid conflicts is simply to name variants with
upper-case letters, and local variables with lower-case letters.

Multiple match patterns may be joined with the `|` operator.
A range of values may be specified with `..`.
Expand Down Expand Up @@ -3122,19 +3140,20 @@ A `struct` *type* is a heterogeneous product of other types, called the *fields*
the *record* types of the ML family,
or the *structure* types of the Lisp family.]

New instances of a `struct` can be constructed with a [struct expression](#struct-expressions).
New instances of a `struct` can be constructed with a [struct expression](#structure-expressions).

The memory order of fields in a `struct` is given by the item defining it.
Fields may be given in any order in a corresponding struct *expression*;
the resulting `struct` value will always be laid out in memory in the order specified by the corresponding *item*.

The fields of a `struct` may be qualified by [visibility modifiers](#visibility-modifiers),
The fields of a `struct` may be qualified by [visibility modifiers](#re-exporting-and-visibility),
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 _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.
The one value constructed by the associated [structure expression](#structure-expressions)
is the only value that inhabits such a type.

### Enumerated types

Expand Down Expand Up @@ -3805,7 +3824,7 @@ over the output format of a Rust crate.
### Logging system

The runtime contains a system for directing [logging
expressions](#log-expressions) to a logging console and/or internal logging
expressions](#logging-expressions) to a logging console and/or internal logging
buffers. Logging can be enabled per module.

Logging output is enabled by setting the `RUST_LOG` environment
Expand Down
15 changes: 8 additions & 7 deletions mk/docs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ CDOCS :=
DOCS_L10N :=
HTML_DEPS :=

BASE_DOC_OPTS := --include-before-body=doc/version_info.html --standalone \
--toc --number-sections
HTML_OPTS = $(BASE_DOC_OPTS) --to=html5 --section-divs --css=rust.css \
--include-in-header=doc/favicon.inc
TEX_OPTS = $(BASE_DOC_OPTS) --to=latex
BASE_DOC_OPTS := --standalone --toc --number-sections
HTML_OPTS = $(BASE_DOC_OPTS) --to=html5 --section-divs --css=rust.css \
--include-before-body=doc/version_info.html --include-in-header=doc/favicon.inc
TEX_OPTS = $(BASE_DOC_OPTS) --include-before-body=doc/version.md --to=latex
EPUB_OPTS = $(BASE_DOC_OPTS) --to=epub

######################################################################
# Rust version
######################################################################

doc/version.md: $(MKFILE_DEPS) $(wildcard $(S)doc/*.*)
@$(call E, version-stamp: $@)
$(Q)echo "$(CFG_VERSION)" >$@
Expand Down Expand Up @@ -84,7 +84,7 @@ doc/rust.tex: rust.md doc/version.md
$(CFG_PANDOC) $(TEX_OPTS) --output=$@

DOCS += doc/rust.epub
doc/rust.epub: rust.md doc/version_info.html doc/rust.css
doc/rust.epub: rust.md
@$(call E, pandoc: $@)
$(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
$(CFG_PANDOC) $(EPUB_OPTS) --output=$@
Expand Down Expand Up @@ -114,7 +114,7 @@ doc/tutorial.tex: tutorial.md doc/version.md
$(CFG_PANDOC) $(TEX_OPTS) --output=$@

DOCS += doc/tutorial.epub
doc/tutorial.epub: tutorial.md doc/version_info.html doc/rust.css
doc/tutorial.epub: tutorial.md
@$(call E, pandoc: $@)
$(Q)$(CFG_NODE) $(S)doc/prep.js --highlight $< | \
$(CFG_PANDOC) $(EPUB_OPTS) --output=$@
Expand Down Expand Up @@ -265,6 +265,7 @@ endif # No pandoc / node
######################################################################
# LLnextgen (grammar analysis from refman)
######################################################################

ifeq ($(CFG_LLNEXTGEN),)
$(info cfg: no llnextgen found, omitting grammar-verification)
else
Expand Down
25 changes: 8 additions & 17 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ delegate!(
fn tanh(n: c_float) -> c_float = cmath::c_float::tanh
)

// FIXME(#11621): These constants should be deprecated once CTFE is implemented
// in favour of calling their respective functions in `Bounded` and `Float`.

pub static RADIX: uint = 2u;

pub static MANTISSA_DIGITS: uint = 53u;
Expand All @@ -122,6 +125,10 @@ pub static NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
pub mod consts {
// FIXME (requires Issue #1433 to fix): replace with mathematical
// staticants from cmath.

// FIXME(#11621): These constants should be deprecated once CTFE is
// implemented in favour of calling their respective functions in `Real`.

/// Archimedes' constant
pub static PI: f32 = 3.14159265358979323846264338327950288_f32;

Expand Down Expand Up @@ -554,16 +561,7 @@ impl Bounded for f32 {
fn max_value() -> f32 { 3.40282347e+38 }
}

impl Primitive for f32 {
#[inline]
fn bits(_: Option<f32>) -> uint { 32 }

#[inline]
fn bytes(_: Option<f32>) -> uint { Primitive::bits(Some(0f32)) / 8 }

#[inline]
fn is_signed(_: Option<f32>) -> bool { true }
}
impl Primitive for f32 {}

impl Float for f32 {
#[inline]
Expand Down Expand Up @@ -1173,13 +1171,6 @@ mod tests {
assert!(!NAN.is_negative());
}

#[test]
fn test_primitive() {
let none: Option<f32> = None;
assert_eq!(Primitive::bits(none), mem::size_of::<f32>() * 8);
assert_eq!(Primitive::bytes(none), mem::size_of::<f32>());
}

#[test]
fn test_is_normal() {
let nan: f32 = Float::nan();
Expand Down
25 changes: 8 additions & 17 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ delegate!(

// FIXME (#1433): obtain these in a different way

// FIXME(#11621): These constants should be deprecated once CTFE is implemented
// in favour of calling their respective functions in `Bounded` and `Float`.

pub static RADIX: uint = 2u;

pub static MANTISSA_DIGITS: uint = 53u;
Expand Down Expand Up @@ -129,6 +132,10 @@ pub static NEG_INFINITY: f64 = -1.0_f64/0.0_f64;
pub mod consts {
// FIXME (requires Issue #1433 to fix): replace with mathematical
// constants from cmath.

// FIXME(#11621): These constants should be deprecated once CTFE is
// implemented in favour of calling their respective functions in `Real`.

/// Archimedes' constant
pub static PI: f64 = 3.14159265358979323846264338327950288_f64;

Expand Down Expand Up @@ -556,16 +563,7 @@ impl Bounded for f64 {
fn max_value() -> f64 { 1.7976931348623157e+308 }
}

impl Primitive for f64 {
#[inline]
fn bits(_: Option<f64>) -> uint { 64 }

#[inline]
fn bytes(_: Option<f64>) -> uint { Primitive::bits(Some(0f64)) / 8 }

#[inline]
fn is_signed(_: Option<f64>) -> bool { true }
}
impl Primitive for f64 {}

impl Float for f64 {
#[inline]
Expand Down Expand Up @@ -1178,13 +1176,6 @@ mod tests {
assert!(!NAN.is_negative());
}

#[test]
fn test_primitive() {
let none: Option<f64> = None;
assert_eq!(Primitive::bits(none), mem::size_of::<f64>() * 8);
assert_eq!(Primitive::bytes(none), mem::size_of::<f64>());
}

#[test]
fn test_is_normal() {
let nan: f64 = Float::nan();
Expand Down
Loading