Skip to content

Commit

Permalink
Auto merge of #25175 - steveklabnik:rollup, r=steveklabnik
Browse files Browse the repository at this point in the history
- Successful merges: #24576, #24966, #25052, #25131, #25137, #25138, #25139, #25141, #25142, #25144, #25146, #25148, #25154, #25156, #25160, #25173
- Failed merges:
  • Loading branch information
bors committed May 7, 2015
2 parents 9560754 + 5ac5203 commit acb3aa0
Show file tree
Hide file tree
Showing 31 changed files with 199 additions and 128 deletions.
2 changes: 1 addition & 1 deletion src/doc/complement-design-faq.md
Expand Up @@ -39,7 +39,7 @@ representation as a primitive. This allows using Rust `enum`s in FFI where C
`enum`s are also used, for most use cases. The attribute can also be applied
to `struct`s to get the same layout as a C struct would.

[repr]: reference.html#miscellaneous-attributes
[repr]: reference.html#ffi-attributes

## There is no GC

Expand Down
9 changes: 4 additions & 5 deletions src/doc/reference.md
Expand Up @@ -1867,13 +1867,12 @@ macro scope.
lower to the target's SIMD instructions, if any; the `simd` feature gate
is necessary to use this attribute.
- `static_assert` - on statics whose type is `bool`, terminates compilation
with an error if it is not initialized to `true`.
- `unsafe_destructor` - allow implementations of the "drop" language item
where the type it is implemented for does not implement the "send" language
item; the `unsafe_destructor` feature gate is needed to use this attribute
with an error if it is not initialized to `true`. To use this, the `static_assert`
feature gate must be enabled.
- `unsafe_no_drop_flag` - on structs, remove the flag that prevents
destructors from being run twice. Destructors might be run multiple times on
the same object with this attribute.
the same object with this attribute. To use this, the `unsafe_no_drop_flag` feature
gate must be enabled.
- `doc` - Doc comments such as `/// foo` are equivalent to `#[doc = "foo"]`.
- `rustc_on_unimplemented` - Write a custom note to be shown along with the error
when the trait is found to be unimplemented on a type.
Expand Down
33 changes: 18 additions & 15 deletions src/doc/trpl/guessing-game.md
Expand Up @@ -82,11 +82,11 @@ fn main() {
let mut guess = String::new();
let input = io::stdin().read_line(&mut guess)
io::stdin().read_line(&mut guess)
.ok()
.expect("Failed to read line");
println!("You guessed: {}", input);
println!("You guessed: {}", guess);
}
```

Expand Down Expand Up @@ -302,12 +302,12 @@ project.
There’s just one line of this first example left:

```rust,ignore
println!("You guessed: {}", input);
println!("You guessed: {}", guess);
}
```

This prints out the string we saved our input in. The `{}`s are a placeholder,
and so we pass it `input` as an argument. If we had multiple `{}`s, we would
and so we pass it `guess` as an argument. If we had multiple `{}`s, we would
pass multiple arguments:

```rust
Expand Down Expand Up @@ -410,24 +410,29 @@ $ cargo build
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
```

So, we told Cargo we wanted any version of `rand`, and so it fetched the
latest version at the time this was written, `v0.3.8`. But what happens
when next week, version `v0.4.0` comes out, which changes something with
`rand`, and it includes a breaking change? After all, a `v0.y.z` version
in SemVer can change every release.
So, we told Cargo we wanted any version of `rand`, and so it fetched the latest
version at the time this was written, `v0.3.8`. But what happens when next
week, version `v0.3.9` comes out, with an important bugfix? While getting
bugfixes is important, what if `0.3.9` contains a regression that breaks our
code?

The answer to this problem is the `Cargo.lock` file you’ll now find in your
project directory. When you build your project for the first time, Cargo
figures out all of the versions that fit your criteria, and then writes them
to the `Cargo.lock` file. When you build your project in the future, Cargo
will see that the `Cargo.lock` file exists, and then use that specific version
rather than do all the work of figuring out versions again. This lets you
have a repeatable build automatically.
have a repeatable build automatically. In other words, we’ll stay at `0.3.8`
until we explicitly upgrade, and so will anyone who we share our code with,
thanks to the lock file.

What about when we _do_ want to use `v0.4.0`? Cargo has another command,
What about when we _do_ want to use `v0.3.9`? Cargo has another command,
`update`, which says ‘ignore the lock, figure out all the latest versions that
fit what we’ve specified. If that works, write those versions out to the lock
file’.
file’. But, by default, Cargo will only look for versions larger than `0.3.0`
and smaller than `0.4.0`. If we want to move to `0.4.x`, we’d have to update
the `Cargo.toml` directly. When we do, the next time we `cargo build`, Cargo
will update the index and re-evaluate our `rand` requirements.

There’s a lot more to say about [Cargo][doccargo] and [its
ecosystem][doccratesio], but for now, that’s all we need to know. Cargo makes
Expand Down Expand Up @@ -843,7 +848,7 @@ fn main() {
Ordering::Less => println!("Too small!"),
Ordering::Greater => println!("Too big!"),
Ordering::Equal => {
println!("You win!"),
println!("You win!");
break;
}
}
Expand Down Expand Up @@ -960,8 +965,6 @@ fn main() {
let secret_number = rand::thread_rng().gen_range(1, 101);
println!("The secret number is: {}", secret_number);
loop {
println!("Please input your guess.");
Expand Down
4 changes: 2 additions & 2 deletions src/doc/trpl/strings.md
Expand Up @@ -73,13 +73,13 @@ individual bytes, or as codepoints:
let hachiko = "忠犬ハチ公";

for b in hachiko.as_bytes() {
print!("{}, ", b);
print!("{}, ", b);
}

println!("");

for c in hachiko.chars() {
print!("{}, ", c);
print!("{}, ", c);
}

println!("");
Expand Down
8 changes: 4 additions & 4 deletions src/grammar/RustLexer.g4
Expand Up @@ -8,14 +8,14 @@ lexer grammar RustLexer;


tokens {
EQ, LT, LE, EQEQ, NE, GE, GT, ANDAND, OROR, NOT, TILDE, PLUT,
EQ, LT, LE, EQEQ, NE, GE, GT, ANDAND, OROR, NOT, TILDE, PLUS,
MINUS, STAR, SLASH, PERCENT, CARET, AND, OR, SHL, SHR, BINOP,
BINOPEQ, AT, DOT, DOTDOT, DOTDOTDOT, COMMA, SEMI, COLON,
MOD_SEP, RARROW, FAT_ARROW, LPAREN, RPAREN, LBRACKET, RBRACKET,
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR,
LBRACE, RBRACE, POUND, DOLLAR, UNDERSCORE, LIT_CHAR, LIT_BYTE,
LIT_INTEGER, LIT_FLOAT, LIT_STR, LIT_STR_RAW, LIT_BINARY,
LIT_BINARY_RAW, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
COMMENT, SHEBANG
LIT_BINARY_RAW, QUESTION, IDENT, LIFETIME, WHITESPACE, DOC_COMMENT,
COMMENT, SHEBANG, UTF8_BOM
}

import xidstart , xidcontinue;
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/verify.rs
Expand Up @@ -111,7 +111,7 @@ fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
"LIT_BINARY_RAW" => token::Literal(token::BinaryRaw(Name(0), 0), None),
"QUESTION" => token::Question,
"SHEBANG" => token::Shebang(Name(0)),
_ => continue,
_ => panic!("Bad token str `{}`", val),
};

res.insert(num.to_string(), tok);
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/boxed.rs
Expand Up @@ -37,7 +37,7 @@
//! }
//! ```
//!
//! This will print `Cons(1, Box(Cons(2, Box(Nil))))`.
//! This will print `Cons(1, Cons(2, Nil))`.
//!
//! Recursive structures must be boxed, because if the definition of `Cons` looked like this:
//!
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/iter.rs
Expand Up @@ -602,6 +602,8 @@ pub trait Iterator {
/// Performs a fold operation over the entire iterator, returning the
/// eventual state at the end of the iteration.
///
/// This operation is sometimes called 'reduce' or 'inject'.
///
/// # Examples
///
/// ```
Expand Down
127 changes: 123 additions & 4 deletions src/librustc/diagnostics.rs
Expand Up @@ -419,6 +419,74 @@ of a loop. Without a loop to break out of or continue in, no sensible action can
be taken.
"##,

E0282: r##"
This error indicates that type inference did not result in one unique possible
type, and extra information is required. In most cases this can be provided
by adding a type annotation. Sometimes you need to specify a generic type
parameter manually.
A common example is the `collect` method on `Iterator`. It has a generic type
parameter with a `FromIterator` bound, which for a `char` iterator is
implemented by `Vec` and `String` among others. Consider the following snippet
that reverses the characters of a string:
```
let x = "hello".chars().rev().collect();
```
In this case, the compiler cannot infer what the type of `x` should be:
`Vec<char>` and `String` are both suitable candidates. To specify which type to
use, you can use a type annotation on `x`:
```
let x: Vec<char> = "hello".chars().rev().collect();
```
It is not necessary to annotate the full type. Once the ambiguity is resolved,
the compiler can infer the rest:
```
let x: Vec<_> = "hello".chars().rev().collect();
```
Another way to provide the compiler with enough information, is to specify the
generic type parameter:
```
let x = "hello".chars().rev().collect::<Vec<char>>();
```
Again, you need not specify the full type if the compiler can infer it:
```
let x = "hello".chars().rev().collect::<Vec<_>>();
```
Apart from a method or function with a generic type parameter, this error can
occur when a type parameter of a struct or trait cannot be inferred. In that
case it is not always possible to use a type annotation, because all candidates
have the same return type. For instance:
```
struct Foo<T> {
// Some fields omitted.
}
impl<T> Foo<T> {
fn bar() -> i32 {
0
}
fn baz() {
let number = Foo::bar();
}
}
```
This will fail because the compiler does not know which instance of `Foo` to
call `bar` on. Change `Foo::bar()` to `Foo::<T>::bar()` to resolve the error.
"##,

E0296: r##"
This error indicates that the given recursion limit could not be parsed. Ensure
that the value provided is a positive integer between quotes, like so:
Expand Down Expand Up @@ -524,10 +592,65 @@ number cannot be negative.
E0307: r##"
The length of an array is part of its type. For this reason, this length must be
a compile-time constant.
"##,

E0308: r##"
This error occurs when the compiler was unable to infer the concrete type of a
variable. This error can occur for several cases, the most common of which is a
mismatch in the expected type that the compiler inferred for a variable's
initializing expression, and the actual type explicitly assigned to the
variable.
For example:
let x: i32 = "I am not a number!";
// ~~~ ~~~~~~~~~~~~~~~~~~~~
// | |
// | initializing expression;
// | compiler infers type `&str`
// |
// type `i32` assigned to variable `x`
"##,

E0309: r##"
Types in type definitions have lifetimes associated with them that represent
how long the data stored within them is guaranteed to be live. This lifetime
must be as long as the data needs to be alive, and missing the constraint that
denotes this will cause this error.
// This won't compile because T is not constrained, meaning the data
// stored in it is not guaranteed to last as long as the reference
struct Foo<'a, T> {
foo: &'a T
}
// This will compile, because it has the constraint on the type parameter
struct Foo<'a, T: 'a> {
foo: &'a T
}
"##,

E0310: r##"
Types in type definitions have lifetimes associated with them that represent
how long the data stored within them is guaranteed to be live. This lifetime
must be as long as the data needs to be alive, and missing the constraint that
denotes this will cause this error.
// This won't compile because T is not constrained to the static lifetime
// the reference needs
struct Foo<T> {
foo: &'static T
}
// This will compile, because it has the constraint on the type parameter
struct Foo<T: 'static> {
foo: &'static T
}
"##

}


register_diagnostics! {
E0011,
E0012,
Expand Down Expand Up @@ -562,7 +685,6 @@ register_diagnostics! {
E0279, // requirement is not satisfied
E0280, // requirement is not satisfied
E0281, // type implements trait but other trait is required
E0282, // unable to infer enough type information about
E0283, // cannot resolve type
E0284, // cannot resolve type
E0285, // overflow evaluation builtin bounds
Expand All @@ -571,9 +693,6 @@ register_diagnostics! {
E0300, // unexpanded macro
E0304, // expected signed integer constant
E0305, // expected constant
E0308,
E0309, // thing may not live long enough
E0310, // thing may not live long enough
E0311, // thing may not live long enough
E0312, // lifetime of reference outlives lifetime of borrowed content
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -374,7 +374,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v ast::Block) {
fn visit_expr(&mut self, ex: &'v ast::Expr) {
if let Some(label) = expression_label(ex) {
for &(prior, prior_span) in &self.labels_in_fn[..] {
// FIXME (#24278): non-hygienic comparision
// FIXME (#24278): non-hygienic comparison
if label.name == prior.name {
signal_shadowing_problem(self.sess,
label.name,
Expand Down Expand Up @@ -420,7 +420,7 @@ fn extract_labels<'v, 'a>(ctxt: &mut LifetimeContext<'a>, b: &'v ast::Block) {
EarlyScope(_, lifetimes, s) |
LateScope(lifetimes, s) => {
for lifetime_def in lifetimes {
// FIXME (#24278): non-hygienic comparision
// FIXME (#24278): non-hygienic comparison
if label.name == lifetime_def.lifetime.name {
signal_shadowing_problem(
sess,
Expand Down Expand Up @@ -677,7 +677,7 @@ impl<'a> LifetimeContext<'a> {
lifetime: &ast::Lifetime)
{
for &(label, label_span) in &self.labels_in_fn {
// FIXME (#24278): non-hygienic comparision
// FIXME (#24278): non-hygienic comparison
if lifetime.name == label.name {
signal_shadowing_problem(self.sess,
lifetime.name,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/traits/error_reporting.rs
Expand Up @@ -290,7 +290,7 @@ pub fn maybe_report_ambiguity<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
{
span_err!(infcx.tcx.sess, obligation.cause.span, E0282,
"unable to infer enough type information about `{}`; \
type annotations required",
type annotations or generic parameter binding required",
self_ty.user_string(infcx.tcx));
} else {
span_err!(infcx.tcx.sess, obligation.cause.span, E0283,
Expand Down

0 comments on commit acb3aa0

Please sign in to comment.