Auto merge of #27383 - Manishearth:rollup, r=Manishearth
- Successful merges: #26778, #27232, #27352, #27369, #27373 - Failed merges:
This commit is contained in:
commit
186707893b
|
@ -3,24 +3,12 @@
|
|||
Not every Rustacean has a background in systems programming, nor in computer
|
||||
science, so we've added explanations of terms that might be unfamiliar.
|
||||
|
||||
### Arity
|
||||
|
||||
Arity refers to the number of arguments a function or operation takes.
|
||||
|
||||
```rust
|
||||
let x = (2, 3);
|
||||
let y = (4, 6);
|
||||
let z = (8, 2, 6);
|
||||
```
|
||||
|
||||
In the example above `x` and `y` have arity 2. `z` has arity 3.
|
||||
|
||||
### Abstract Syntax Tree
|
||||
|
||||
When a compiler is compiling your program, it does a number of different
|
||||
things. One of the things that it does is turn the text of your program into an
|
||||
‘abstract syntax tree’, or ‘AST’. This tree is a representation of the
|
||||
structure of your program. For example, `2 + 3` can be turned into a tree:
|
||||
When a compiler is compiling your program, it does a number of different things.
|
||||
One of the things that it does is turn the text of your program into an
|
||||
‘abstract syntax tree’, or ‘AST’. This tree is a representation of the structure
|
||||
of your program. For example, `2 + 3` can be turned into a tree:
|
||||
|
||||
```text
|
||||
+
|
||||
|
@ -37,3 +25,41 @@ And `2 + (3 * 4)` would look like this:
|
|||
/ \
|
||||
3 4
|
||||
```
|
||||
|
||||
### Arity
|
||||
|
||||
Arity refers to the number of arguments a function or operation takes.
|
||||
|
||||
```rust
|
||||
let x = (2, 3);
|
||||
let y = (4, 6);
|
||||
let z = (8, 2, 6);
|
||||
```
|
||||
|
||||
In the example above `x` and `y` have arity 2. `z` has arity 3.
|
||||
|
||||
### Expression
|
||||
|
||||
In computer programming, an expression is a combination of values, constants,
|
||||
variables, operators and functions that evaluate to a single value. For example,
|
||||
`2 + (3 * 4)` is an expression that returns the value 14. It is worth noting
|
||||
that expressions can have side-effects. For example, a function included in an
|
||||
expression might perform actions other than simply returning a value.
|
||||
|
||||
### Expression-Oriented Language
|
||||
|
||||
In early programming languages, [expressions][expression] and
|
||||
[statements][statement] were two separate syntactic categories: expressions had
|
||||
a value and statements did things. However, later languages blurred this
|
||||
distinction, allowing expressions to do things and statements to have a value.
|
||||
In an expression-oriented language, (nearly) every statement is an expression
|
||||
and therefore returns a value. Consequently, these expression statements can
|
||||
themselves form part of larger expressions.
|
||||
|
||||
[expression]: glossary.html#expression
|
||||
[statement]: glossary.html#statement
|
||||
|
||||
### Statement
|
||||
|
||||
In computer programming, a statement is the smallest standalone element of a
|
||||
programming language that commands a computer to perform an action.
|
||||
|
|
|
@ -111,10 +111,13 @@ string to the screen. Easy enough!
|
|||
|
||||
[allocation]: the-stack-and-the-heap.html
|
||||
|
||||
Finally, the line ends with a semicolon (`;`). Rust is an ‘expression oriented’
|
||||
language, which means that most things are expressions, rather than statements.
|
||||
The `;` is used to indicate that this expression is over, and the next one is
|
||||
ready to begin. Most lines of Rust code end with a `;`.
|
||||
Finally, the line ends with a semicolon (`;`). Rust is an [‘expression oriented’
|
||||
language][expression-oriented language], which means that most things are
|
||||
expressions, rather than statements. The `;` is used to indicate that this
|
||||
expression is over, and the next one is ready to begin. Most lines of Rust code
|
||||
end with a `;`.
|
||||
|
||||
[expression-oriented language]: glossary.html#expression-oriented-language
|
||||
|
||||
Finally, actually compiling and running our program. We can compile with our
|
||||
compiler, `rustc`, by passing it the name of our source file:
|
||||
|
|
|
@ -85,9 +85,9 @@
|
|||
//! format!("{a} {c} {b}", a="a", b='b', c=3); // => "a 3 b"
|
||||
//! ```
|
||||
//!
|
||||
//! It is illegal to put positional parameters (those without names) after
|
||||
//! arguments which have names. Like with positional parameters, it is illegal
|
||||
//! to provide named parameters that are unused by the format string.
|
||||
//! It is not valid to put positional parameters (those without names) after
|
||||
//! arguments which have names. Like with positional parameters, it is not
|
||||
//! valid to provide named parameters that are unused by the format string.
|
||||
//!
|
||||
//! ## Argument types
|
||||
//!
|
||||
|
@ -103,8 +103,9 @@
|
|||
//! hexadecimal as well as an
|
||||
//! octal.
|
||||
//!
|
||||
//! There are various parameters which do require a particular type, however. Namely, the `{:.*}`
|
||||
//! syntax, which sets the number of numbers after the decimal in floating-point types:
|
||||
//! There are various parameters which do require a particular type, however.
|
||||
//! Namely, the `{:.*}` syntax, which sets the number of numbers after the
|
||||
//! decimal in floating-point types:
|
||||
//!
|
||||
//! ```
|
||||
//! let formatted_number = format!("{:.*}", 2, 1.234567);
|
||||
|
@ -112,10 +113,11 @@
|
|||
//! assert_eq!("1.23", formatted_number)
|
||||
//! ```
|
||||
//!
|
||||
//! If this syntax is used, then the number of characters to print precedes the actual object being
|
||||
//! formatted, and the number of characters must have the type `usize`. Although a `usize` can be
|
||||
//! printed with `{}`, it is illegal to reference an argument as such. For example this is another
|
||||
//! invalid format string:
|
||||
//! If this syntax is used, then the number of characters to print precedes the
|
||||
//! actual object being formatted, and the number of characters must have the
|
||||
//! type `usize`. Although a `usize` can be printed with `{}`, it is invalid to
|
||||
//! reference an argument as such. For example this is another invalid format
|
||||
//! string:
|
||||
//!
|
||||
//! ```text
|
||||
//! {:.*} {0}
|
||||
|
|
|
@ -205,7 +205,7 @@ pub trait Copy : Clone {
|
|||
/// Any types with interior mutability must also use the `std::cell::UnsafeCell`
|
||||
/// wrapper around the value(s) which can be mutated when behind a `&`
|
||||
/// reference; not doing this is undefined behaviour (for example,
|
||||
/// `transmute`-ing from `&T` to `&mut T` is illegal).
|
||||
/// `transmute`-ing from `&T` to `&mut T` is invalid).
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[lang = "sync"]
|
||||
#[rustc_on_unimplemented = "`{Self}` cannot be shared between threads safely"]
|
||||
|
|
|
@ -479,8 +479,8 @@ macro_rules! int_impl {
|
|||
/// wrapping around at the boundary of the type.
|
||||
///
|
||||
/// Such wrap-around never actually occurs mathematically;
|
||||
/// implementation artifacts make `x % y` illegal for `MIN /
|
||||
/// -1` on a signed type illegal (where `MIN` is the negative
|
||||
/// implementation artifacts make `x % y` invalid for `MIN /
|
||||
/// -1` on a signed type (where `MIN` is the negative
|
||||
/// minimal value). In such a case, this function returns `0`.
|
||||
#[stable(feature = "num_wrapping", since = "1.2.0")]
|
||||
#[inline(always)]
|
||||
|
@ -1051,8 +1051,8 @@ macro_rules! uint_impl {
|
|||
/// wrapping around at the boundary of the type.
|
||||
///
|
||||
/// Such wrap-around never actually occurs mathematically;
|
||||
/// implementation artifacts make `x % y` illegal for `MIN /
|
||||
/// -1` on a signed type illegal (where `MIN` is the negative
|
||||
/// implementation artifacts make `x % y` invalid for `MIN /
|
||||
/// -1` on a signed type (where `MIN` is the negative
|
||||
/// minimal value). In such a case, this function returns `0`.
|
||||
#[stable(feature = "num_wrapping", since = "1.2.0")]
|
||||
#[inline(always)]
|
||||
|
|
|
@ -41,7 +41,7 @@ arms.
|
|||
"##,
|
||||
|
||||
E0002: r##"
|
||||
This error indicates that an empty match expression is illegal because the type
|
||||
This error indicates that an empty match expression is invalid because the type
|
||||
it is matching on is non-empty (there exist values of this type). In safe code
|
||||
it is impossible to create an instance of an empty type, so empty match
|
||||
expressions are almost never desired. This error is typically fixed by adding
|
||||
|
@ -1055,7 +1055,7 @@ because the `'static` lifetime is a special built-in lifetime name denoting
|
|||
the lifetime of the entire program, this is an error:
|
||||
|
||||
```
|
||||
// error, illegal lifetime parameter name `'static`
|
||||
// error, invalid lifetime parameter name `'static`
|
||||
fn foo<'static>(x: &'static str) { }
|
||||
```
|
||||
"##,
|
||||
|
@ -1805,7 +1805,7 @@ For more information about `const fn`'s, see [RFC 911].
|
|||
E0394: r##"
|
||||
From [RFC 246]:
|
||||
|
||||
> It is illegal for a static to reference another static by value. It is
|
||||
> It is invalid for a static to reference another static by value. It is
|
||||
> required that all references be borrowed.
|
||||
|
||||
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
|
||||
|
|
|
@ -44,7 +44,7 @@ use metadata::csearch;
|
|||
use middle;
|
||||
use middle::cast;
|
||||
use middle::check_const;
|
||||
use middle::const_eval::{self, ConstVal};
|
||||
use middle::const_eval::{self, ConstVal, ErrKind};
|
||||
use middle::const_eval::EvalHint::UncheckedExprHint;
|
||||
use middle::def::{self, DefMap, ExportMap};
|
||||
use middle::dependency_format;
|
||||
|
@ -6107,20 +6107,20 @@ impl<'tcx> ctxt<'tcx> {
|
|||
found);
|
||||
}
|
||||
Err(err) => {
|
||||
let err_description = err.description();
|
||||
let found = match count_expr.node {
|
||||
let err_msg = match count_expr.node {
|
||||
ast::ExprPath(None, ast::Path {
|
||||
global: false,
|
||||
ref segments,
|
||||
..
|
||||
}) if segments.len() == 1 =>
|
||||
format!("{}", "found variable"),
|
||||
_ =>
|
||||
format!("but {}", err_description),
|
||||
format!("found variable"),
|
||||
_ => match err.kind {
|
||||
ErrKind::MiscCatchAll => format!("but found {}", err.description()),
|
||||
_ => format!("but {}", err.description())
|
||||
}
|
||||
};
|
||||
span_err!(self.sess, count_expr.span, E0307,
|
||||
"expected constant integer for repeat count, {}",
|
||||
found);
|
||||
"expected constant integer for repeat count, {}", err_msg);
|
||||
}
|
||||
}
|
||||
0
|
||||
|
|
|
@ -106,7 +106,7 @@ mod foo {
|
|||
use foo::MyTrait::do_something;
|
||||
```
|
||||
|
||||
It's illegal to directly import methods belonging to a trait or concrete type.
|
||||
It's invalid to directly import methods belonging to a trait or concrete type.
|
||||
"##,
|
||||
|
||||
E0255: r##"
|
||||
|
|
|
@ -584,7 +584,7 @@ extern "C" {
|
|||
```
|
||||
|
||||
Using this declaration, it must be called with at least one argument, so
|
||||
simply calling `printf()` is illegal. But the following uses are allowed:
|
||||
simply calling `printf()` is invalid. But the following uses are allowed:
|
||||
|
||||
```
|
||||
unsafe {
|
||||
|
|
|
@ -281,28 +281,23 @@ extern crate libc;
|
|||
|
||||
#[macro_use] #[no_link] extern crate rustc_bitflags;
|
||||
|
||||
// Make std testable by not duplicating lang items. See #2912
|
||||
// Make std testable by not duplicating lang items and other globals. See #2912
|
||||
#[cfg(test)] extern crate std as realstd;
|
||||
#[cfg(test)] pub use realstd::marker;
|
||||
#[cfg(test)] pub use realstd::ops;
|
||||
#[cfg(test)] pub use realstd::cmp;
|
||||
#[cfg(test)] pub use realstd::boxed;
|
||||
|
||||
|
||||
// NB: These reexports are in the order they should be listed in rustdoc
|
||||
|
||||
pub use core::any;
|
||||
pub use core::cell;
|
||||
pub use core::clone;
|
||||
#[cfg(not(test))] pub use core::cmp;
|
||||
pub use core::cmp;
|
||||
pub use core::convert;
|
||||
pub use core::default;
|
||||
pub use core::hash;
|
||||
pub use core::intrinsics;
|
||||
pub use core::iter;
|
||||
#[cfg(not(test))] pub use core::marker;
|
||||
pub use core::marker;
|
||||
pub use core::mem;
|
||||
#[cfg(not(test))] pub use core::ops;
|
||||
pub use core::ops;
|
||||
pub use core::ptr;
|
||||
pub use core::raw;
|
||||
pub use core::simd;
|
||||
|
@ -310,7 +305,7 @@ pub use core::result;
|
|||
pub use core::option;
|
||||
pub mod error;
|
||||
|
||||
#[cfg(not(test))] pub use alloc::boxed;
|
||||
pub use alloc::boxed;
|
||||
pub use alloc::rc;
|
||||
|
||||
pub use core_collections::borrow;
|
||||
|
|
|
@ -60,21 +60,22 @@ impl Condvar {
|
|||
let r = ffi::gettimeofday(&mut sys_now, ptr::null_mut());
|
||||
debug_assert_eq!(r, 0);
|
||||
|
||||
let nsec = dur.extra_nanos() as libc::c_long +
|
||||
(sys_now.tv_usec * 1000) as libc::c_long;
|
||||
let extra = (nsec / 1_000_000_000) as libc::time_t;
|
||||
let nsec = nsec % 1_000_000_000;
|
||||
let seconds = dur.secs() as libc::time_t;
|
||||
let timeout = match sys_now.tv_sec.checked_add(seconds) {
|
||||
Some(sec) => {
|
||||
libc::timespec {
|
||||
tv_sec: sec,
|
||||
tv_nsec: dur.extra_nanos() as libc::c_long,
|
||||
}
|
||||
|
||||
let timeout = sys_now.tv_sec.checked_add(extra).and_then(|s| {
|
||||
s.checked_add(seconds)
|
||||
}).map(|s| {
|
||||
libc::timespec { tv_sec: s, tv_nsec: nsec }
|
||||
}).unwrap_or_else(|| {
|
||||
libc::timespec {
|
||||
tv_sec: <libc::time_t>::max_value(),
|
||||
tv_nsec: 1_000_000_000 - 1,
|
||||
}
|
||||
None => {
|
||||
libc::timespec {
|
||||
tv_sec: <libc::time_t>::max_value(),
|
||||
tv_nsec: 1_000_000_000 - 1,
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// And wait!
|
||||
let r = ffi::pthread_cond_timedwait(self.inner.get(), mutex::raw(mutex),
|
||||
|
|
Loading…
Reference in New Issue