Skip to content

Rollup of 16 pull requests #25172

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 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d6227dc
Added error explanations for E0308, E0309, and E0310
cactorium Apr 18, 2015
99d2552
Fix typo
cactorium Apr 19, 2015
4420f31
Fix trailing whitespaces
cactorium Apr 19, 2015
52e520e
rustc: Improve misleading error message for E0282
ruuda Apr 29, 2015
6b292cd
rustc: Add long diagnostics for E0282
ruuda Apr 29, 2015
414dfb1
rustc: Improve long diagnostics for E0282
ruuda Apr 30, 2015
685a6f7
Update "Miscellaneous attributes" section of reference manual
jooert May 2, 2015
93c0614
Update with correct output.
janne May 5, 2015
4b8098b
test: Update expected compile-fail message for E0282
ruuda May 5, 2015
cdb6e1e
Correct a typo in a declared token in the reference grammar
carols10cents May 5, 2015
1ca9ed6
Declare other tokens used later in the reference grammar
carols10cents May 5, 2015
9c7d5ae
Panic if the grammar verifier sees a token it doesn't recognize
carols10cents May 5, 2015
dff7676
Fix MIPS build errors in libstd/os/linux/raw.rs
kevinmehall May 5, 2015
6c6b200
Add TCP_* constants for mips/mipsel Linux
kevinmehall May 5, 2015
705f355
Fix indentation in the "Strings" chapter
hibariya May 6, 2015
8227db8
fix typos caught by codespell
tshepang May 5, 2015
fc9bc77
Fix explanation of Cargo's behavior
steveklabnik May 6, 2015
085e1f4
doc: Fix link of repr attribute
rydotyosh May 6, 2015
4174aa4
Reword with pnkfelix's suggestion
cactorium May 6, 2015
45c461c
Add note about type signature searching to docs
piatra May 6, 2015
81b90bd
Correct initial guessing game example. Fixes #25147. r? @steveklabnik
banks May 6, 2015
1d6285e
Iter Docs: Mention 'reduce' and 'inject'
killercup May 6, 2015
08923fb
doc: Fix remove unused variable
rydotyosh May 6, 2015
1884c87
doc: Fix remove secret number at final source
rydotyosh May 6, 2015
bfdbda2
Remove schedule_free_slice
michaelwu May 6, 2015
592d271
Rollup merge of #24576 - cactorium:errorcodes, r=pnkfelix
steveklabnik May 7, 2015
ee80321
Rollup merge of #24966 - ruud-v-a:explain, r=pnkfelix
steveklabnik May 7, 2015
3080809
Rollup merge of #25052 - jooert:misc_attr_reference, r=steveklabnik
steveklabnik May 7, 2015
f59f07d
Rollup merge of #25131 - janne:patch-1, r=alexcrichton
steveklabnik May 7, 2015
872132f
Rollup merge of #25137 - carols10cents:fix-token-declaration, r=alexc…
steveklabnik May 7, 2015
fa55b4c
Rollup merge of #25138 - tshepang:typos, r=sanxiyn
steveklabnik May 7, 2015
c13c3f9
Rollup merge of #25139 - hibariya:fix-indentation, r=alexcrichton
steveklabnik May 7, 2015
a9d696f
Rollup merge of #25140 - kevinmehall:mips, r=sanxiyn
steveklabnik May 7, 2015
7b643df
Rollup merge of #25141 - steveklabnik:fix_guessing_game, r=huonw
steveklabnik May 7, 2015
901f334
Rollup merge of #25142 - rydotyosh:patch-1, r=alexcrichton
steveklabnik May 7, 2015
5f6b588
Rollup merge of #25144 - killercup:docs/iter-fold-reduce, r=steveklabnik
steveklabnik May 7, 2015
2e9cc99
Rollup merge of #25146 - piatra:doc-search-patch, r=steveklabnik
steveklabnik May 7, 2015
54eb0aa
Rollup merge of #25148 - banks:master, r=steveklabnik
steveklabnik May 7, 2015
26ff571
Rollup merge of #25154 - rydotyosh:patch-3, r=steveklabnik
steveklabnik May 7, 2015
e53cd43
Rollup merge of #25156 - rydotyosh:patch-4, r=alexcrichton
steveklabnik May 7, 2015
6499747
Rollup merge of #25160 - michaelwu:remove-schedule_free_slice, r=cmr
steveklabnik May 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/complement-design-faq.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
31 changes: 17 additions & 14 deletions src/doc/trpl/guessing-game.md
Original file line number Diff line number Diff line change
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
24 changes: 24 additions & 0 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3624,6 +3624,30 @@ pub mod consts {
pub const IPV6_DROP_MEMBERSHIP: c_int = 21;

pub const TCP_NODELAY: c_int = 1;
pub const TCP_MAXSEG: c_int = 2;
pub const TCP_CORK: c_int = 3;
pub const TCP_KEEPIDLE: c_int = 4;
pub const TCP_KEEPINTVL: c_int = 5;
pub const TCP_KEEPCNT: c_int = 6;
pub const TCP_SYNCNT: c_int = 7;
pub const TCP_LINGER2: c_int = 8;
pub const TCP_DEFER_ACCEPT: c_int = 9;
pub const TCP_WINDOW_CLAMP: c_int = 10;
pub const TCP_INFO: c_int = 11;
pub const TCP_QUICKACK: c_int = 12;
pub const TCP_CONGESTION: c_int = 13;
pub const TCP_MD5SIG: c_int = 14;
pub const TCP_COOKIE_TRANSACTIONS: c_int = 15;
pub const TCP_THIN_LINEAR_TIMEOUTS: c_int = 16;
pub const TCP_THIN_DUPACK: c_int = 17;
pub const TCP_USER_TIMEOUT: c_int = 18;
pub const TCP_REPAIR: c_int = 19;
pub const TCP_REPAIR_QUEUE: c_int = 20;
pub const TCP_QUEUE_SEQ: c_int = 21;
pub const TCP_REPAIR_OPTIONS: c_int = 22;
pub const TCP_FASTOPEN: c_int = 23;
pub const TCP_TIMESTAMP: c_int = 24;

pub const SOL_SOCKET: c_int = 65535;

pub const SO_DEBUG: c_int = 0x0001;
Expand Down
127 changes: 123 additions & 4 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading