From d6227dcd6e139c3f598cd6e937cc59214e254ca6 Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Sat, 18 Apr 2015 08:25:43 -0400 Subject: [PATCH 01/23] Added error explanations for E0308, E0309, and E0310 --- src/librustc/diagnostics.rs | 56 +++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index e1eb8d7418695..2d1bf16727617 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -303,10 +303,63 @@ 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 +that there is a mismatch in the expected type that the compiler inferred, and +the actual type that the user defined a variable as. + +let a: char = 7; // An integral type can't contained in a character, so + // there is a mismatch. + +let b: u32 = 7; // Either use the right type... +let c = 7; // ...or let the compiler infer it. + +let d: char = c; // This also causes a mismatch because c is some sort + // of number whereas d is definitely a character. +"##, + +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 { + foo: &'static T +} + +// This will compile, because it has the constraint on the type parameter +struct Foo { + foo: &'static T +} "## } + register_diagnostics! { E0009, E0010, @@ -363,9 +416,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 From 99d2552c4ef409dc7232a47fbd92bb9df8c98cdc Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Sat, 18 Apr 2015 20:25:24 -0400 Subject: [PATCH 02/23] Fix typo --- src/librustc/diagnostics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 2d1bf16727617..12b65b7feb550 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -311,7 +311,7 @@ variable. This error can occur for several cases, the most common of which is that there is a mismatch in the expected type that the compiler inferred, and the actual type that the user defined a variable as. -let a: char = 7; // An integral type can't contained in a character, so +let a: char = 7; // An integral type can't be contained in a character, so // there is a mismatch. let b: u32 = 7; // Either use the right type... From 4420f318080e116dc4bf75a1a3568fe8bf4157b7 Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Sun, 19 Apr 2015 01:59:29 -0400 Subject: [PATCH 03/23] Fix trailing whitespaces --- src/librustc/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 12b65b7feb550..68dd83a3fe5f2 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -303,7 +303,7 @@ 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 @@ -311,7 +311,7 @@ variable. This error can occur for several cases, the most common of which is that there is a mismatch in the expected type that the compiler inferred, and the actual type that the user defined a variable as. -let a: char = 7; // An integral type can't be contained in a character, so +let a: char = 7; // An integral type can't be contained in a character, so // there is a mismatch. let b: u32 = 7; // Either use the right type... From 52e520e902cecc579910e6cabe1658720bfab132 Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Thu, 30 Apr 2015 00:56:33 +0200 Subject: [PATCH 04/23] rustc: Improve misleading error message for E0282 The error can also occur in cases where a type annotation will not help. --- src/librustc/middle/traits/error_reporting.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/traits/error_reporting.rs b/src/librustc/middle/traits/error_reporting.rs index d10ff060418cc..9f87a9ad65f36 100644 --- a/src/librustc/middle/traits/error_reporting.rs +++ b/src/librustc/middle/traits/error_reporting.rs @@ -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, From 6b292cd4c48f0876b4280dfdf0c38d474fe44330 Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Thu, 30 Apr 2015 00:58:43 +0200 Subject: [PATCH 05/23] rustc: Add long diagnostics for E0282 --- src/librustc/diagnostics.rs | 68 ++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 8b43f9ada9a33..250252a77cbcd 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -368,6 +368,73 @@ 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 is implemented by `Vec` and +`VecDeque` among others. Consider the following snippet: + +``` +let x = (1_i32 .. 10).collect(); +``` + +In this case, the compiler cannot infer what the type of `x` should be: +`Vec` and `VecDeque` are both suitable candidates. To specify which +type to use, you can use a type annotation on `x`: + +``` +let x: Vec = (1_i32 .. 10).collect(); +``` + +It is not necessary to annotate the full type, once the ambiguity is resolved, +the compiler can infer the rest: + +``` +let x: Vec<_> = (1_i32 .. 10).collect(); +``` + +Another way to provide the compiler with enough information, is to specify the +generic type parameter: + +``` +let x = (1_i32 .. 10).collect::>(); +``` + +Again, you need not specify the full type if the compiler can infer it: + +``` +let x = (1_i32 .. 10).collect::>(); +``` + +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 { + // Some fields omitted. +} + +impl Foo { + 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::::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: @@ -515,7 +582,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 From 414dfb13df96a373c7fd37f6beb299e176675e0e Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Thu, 30 Apr 2015 11:51:40 +0200 Subject: [PATCH 06/23] rustc: Improve long diagnostics for E0282 The new example uses a `char` iterator instead of `i32`, to avoid interplay between type inference and the default type for integer literals. --- src/librustc/diagnostics.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 250252a77cbcd..39ebcda4778c7 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -375,39 +375,40 @@ 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 is implemented by `Vec` and -`VecDeque` among others. Consider the following snippet: +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 = (1_i32 .. 10).collect(); +let x = "hello".chars().rev().collect(); ``` In this case, the compiler cannot infer what the type of `x` should be: -`Vec` and `VecDeque` are both suitable candidates. To specify which -type to use, you can use a type annotation on `x`: +`Vec` and `String` are both suitable candidates. To specify which type to +use, you can use a type annotation on `x`: ``` -let x: Vec = (1_i32 .. 10).collect(); +let x: Vec = "hello".chars().rev().collect(); ``` -It is not necessary to annotate the full type, once the ambiguity is resolved, +It is not necessary to annotate the full type. Once the ambiguity is resolved, the compiler can infer the rest: ``` -let x: Vec<_> = (1_i32 .. 10).collect(); +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 = (1_i32 .. 10).collect::>(); +let x = "hello".chars().rev().collect::>(); ``` Again, you need not specify the full type if the compiler can infer it: ``` -let x = (1_i32 .. 10).collect::>(); +let x = "hello".chars().rev().collect::>(); ``` Apart from a method or function with a generic type parameter, this error can From 685a6f70868c2abbf1577867933b3c2c69303af2 Mon Sep 17 00:00:00 2001 From: Johannes Oertel Date: Sat, 2 May 2015 12:44:57 +0200 Subject: [PATCH 07/23] Update "Miscellaneous attributes" section of reference manual --- src/doc/reference.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 3918a558cb330..c561956938941 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -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. From 93c06143dfeb0d9cad12dbd9d1f58c9c2f69c06f Mon Sep 17 00:00:00 2001 From: Jan Andersson Date: Tue, 5 May 2015 23:19:23 +0200 Subject: [PATCH 08/23] Update with correct output. --- src/liballoc/boxed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 7a089d733cfdf..a0d60be300059 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -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: //! From 4b8098bb193d82d18183a8223507f5908adeeb4c Mon Sep 17 00:00:00 2001 From: Ruud van Asseldonk Date: Tue, 5 May 2015 18:22:20 +0200 Subject: [PATCH 09/23] test: Update expected compile-fail message for E0282 --- src/test/compile-fail/issue-12187-1.rs | 4 ++-- src/test/compile-fail/issue-12187-2.rs | 4 ++-- src/test/compile-fail/issue-5062.rs | 4 ++-- src/test/compile-fail/issue-6458-2.rs | 4 ++-- src/test/compile-fail/issue-6458-3.rs | 4 ++-- src/test/compile-fail/issue-6458-4.rs | 4 ++-- src/test/compile-fail/issue-6458.rs | 5 +++-- src/test/compile-fail/issue-7813.rs | 4 ++-- .../compile-fail/method-ambig-one-trait-unknown-int-type.rs | 5 +++-- .../compile-fail/traits-multidispatch-convert-ambig-dest.rs | 5 +++-- src/test/compile-fail/unconstrained-none.rs | 4 ++-- src/test/compile-fail/unconstrained-ref.rs | 4 ++-- src/test/compile-fail/vector-no-ann.rs | 5 +++-- 13 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/test/compile-fail/issue-12187-1.rs b/src/test/compile-fail/issue-12187-1.rs index 74423b041dda3..5322966ae2ea0 100644 --- a/src/test/compile-fail/issue-12187-1.rs +++ b/src/test/compile-fail/issue-12187-1.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -14,5 +14,5 @@ fn new() -> &'static T { fn main() { let &v = new(); - //~^ ERROR type annotations required + //~^ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/issue-12187-2.rs b/src/test/compile-fail/issue-12187-2.rs index af5c8b45a483e..dabc0acba370e 100644 --- a/src/test/compile-fail/issue-12187-2.rs +++ b/src/test/compile-fail/issue-12187-2.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -14,5 +14,5 @@ fn new<'r, T>() -> &'r T { fn main() { let &v = new(); - //~^ ERROR type annotations required + //~^ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/issue-5062.rs b/src/test/compile-fail/issue-5062.rs index 7bf3449a664b1..392d38a6144f1 100644 --- a/src/test/compile-fail/issue-5062.rs +++ b/src/test/compile-fail/issue-5062.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -9,4 +9,4 @@ // except according to those terms. fn main() { format!("{:?}", None); } - //~^ ERROR type annotations required + //~^ ERROR type annotations or generic parameter binding required diff --git a/src/test/compile-fail/issue-6458-2.rs b/src/test/compile-fail/issue-6458-2.rs index 0143c75bfc604..acf1d766b6a11 100644 --- a/src/test/compile-fail/issue-6458-2.rs +++ b/src/test/compile-fail/issue-6458-2.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -11,5 +11,5 @@ fn main() { // Unconstrained type: format!("{:?}", None); - //~^ ERROR type annotations required + //~^ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/issue-6458-3.rs b/src/test/compile-fail/issue-6458-3.rs index f96faeeec4bd1..3f81e51efe2ef 100644 --- a/src/test/compile-fail/issue-6458-3.rs +++ b/src/test/compile-fail/issue-6458-3.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -12,5 +12,5 @@ use std::mem; fn main() { mem::transmute(0); - //~^ ERROR type annotations required + //~^ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/issue-6458-4.rs b/src/test/compile-fail/issue-6458-4.rs index 02274e5441e26..7f408be9c02d4 100644 --- a/src/test/compile-fail/issue-6458-4.rs +++ b/src/test/compile-fail/issue-6458-4.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,7 +10,7 @@ fn foo(b: bool) -> Result { Err("bar".to_string()); - //~^ ERROR type annotations required + //~^ ERROR type annotations or generic parameter binding required } fn main() { diff --git a/src/test/compile-fail/issue-6458.rs b/src/test/compile-fail/issue-6458.rs index 0bf9a3c2d4867..c1f9dd6a4b893 100644 --- a/src/test/compile-fail/issue-6458.rs +++ b/src/test/compile-fail/issue-6458.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -16,7 +16,8 @@ pub struct MyState; pub fn foo(_: TypeWithState) {} pub fn bar() { - foo(TypeWithState(marker::PhantomData)); //~ ERROR type annotations required + foo(TypeWithState(marker::PhantomData)); + //~^ ERROR type annotations or generic parameter binding required } fn main() { diff --git a/src/test/compile-fail/issue-7813.rs b/src/test/compile-fail/issue-7813.rs index 81421af4fa839..327fb6adf1d54 100644 --- a/src/test/compile-fail/issue-7813.rs +++ b/src/test/compile-fail/issue-7813.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,5 +10,5 @@ fn main() { let v = &[]; - let it = v.iter(); //~ ERROR type annotations required + let it = v.iter(); //~ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs index c6d45f1c9db8a..59d75c5a787a6 100644 --- a/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs +++ b/src/test/compile-fail/method-ambig-one-trait-unknown-int-type.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -31,7 +31,8 @@ impl foo for Vec { fn m1() { // we couldn't infer the type of the vector just based on calling foo()... - let mut x = Vec::new(); //~ ERROR type annotations required + let mut x = Vec::new(); + //~^ ERROR type annotations or generic parameter binding required x.foo(); } diff --git a/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs b/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs index 8fe1f4d2371c4..c77494912bc75 100644 --- a/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs +++ b/src/test/compile-fail/traits-multidispatch-convert-ambig-dest.rs @@ -1,4 +1,4 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -33,7 +33,8 @@ where T : Convert } fn a() { - test(22, std::default::Default::default()); //~ ERROR type annotations required + test(22, std::default::Default::default()); + //~^ ERROR type annotations or generic parameter binding required } fn main() {} diff --git a/src/test/compile-fail/unconstrained-none.rs b/src/test/compile-fail/unconstrained-none.rs index 9879766a8fa25..c14de98e03f14 100644 --- a/src/test/compile-fail/unconstrained-none.rs +++ b/src/test/compile-fail/unconstrained-none.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -11,5 +11,5 @@ // Issue #5062 fn main() { - None; //~ ERROR type annotations required + None; //~ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/unconstrained-ref.rs b/src/test/compile-fail/unconstrained-ref.rs index e03f60e758ce2..02a3f2b9ab8d2 100644 --- a/src/test/compile-fail/unconstrained-ref.rs +++ b/src/test/compile-fail/unconstrained-ref.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ struct S<'a, T:'a> { } fn main() { - S { o: &None }; //~ ERROR type annotations required + S { o: &None }; //~ ERROR type annotations or generic parameter binding required } diff --git a/src/test/compile-fail/vector-no-ann.rs b/src/test/compile-fail/vector-no-ann.rs index d48f5715ec1b9..419b8c4e1b015 100644 --- a/src/test/compile-fail/vector-no-ann.rs +++ b/src/test/compile-fail/vector-no-ann.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,5 +10,6 @@ fn main() { - let _foo = Vec::new(); //~ ERROR type annotations required + let _foo = Vec::new(); + //~^ ERROR type annotations or generic parameter binding required } From cdb6e1e15f691599b15a4d474952f38c7381a964 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 19:26:16 -0400 Subject: [PATCH 10/23] Correct a typo in a declared token in the reference grammar This appears to not have too much of a detrimental effect, but it doesn't seem to be what is intended either. antlr doesn't mind that `PLUS` isn't declared in `tokens` and happily uses the `PLUS` that appears later in the file, but the generated RustLexer.tokens had PLUS at the end rather than where it was intended: NOT=10 TILDE=11 PLUT=12 MINUS=13 ... PLUS=56 --- src/grammar/RustLexer.g4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grammar/RustLexer.g4 b/src/grammar/RustLexer.g4 index 3d8f3aeb28fa7..5dcf0f6935f22 100644 --- a/src/grammar/RustLexer.g4 +++ b/src/grammar/RustLexer.g4 @@ -8,7 +8,7 @@ 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, From 1ca9ed61d62b529aa403229b0a23dac69a091fe3 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 19:29:58 -0400 Subject: [PATCH 11/23] Declare other tokens used later in the reference grammar There were some tokens used in the grammar but not declared. Antlr doesn't really seem to care and happily uses them, but they appear in RustLexer.tokens in a potentially-unexpected order. --- src/grammar/RustLexer.g4 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/grammar/RustLexer.g4 b/src/grammar/RustLexer.g4 index 5dcf0f6935f22..f062d33f25e25 100644 --- a/src/grammar/RustLexer.g4 +++ b/src/grammar/RustLexer.g4 @@ -12,10 +12,10 @@ tokens { 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; From 9c7d5ae57c27ebfc019c2c23283bb905d8c3b74f Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Tue, 5 May 2015 19:32:26 -0400 Subject: [PATCH 12/23] Panic if the grammar verifier sees a token it doesn't recognize To prevent the reference grammar from getting out of sync with the real grammar, panic if RustLexer.tokens contains an unknown token in a similar way that verify.rs panics if it encounters an unknown binary operation token. --- src/grammar/verify.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grammar/verify.rs b/src/grammar/verify.rs index dec797747c270..10b8abfc78606 100644 --- a/src/grammar/verify.rs +++ b/src/grammar/verify.rs @@ -111,7 +111,7 @@ fn parse_token_list(file: &str) -> HashMap { "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); From 705f355e534807da5ea48f28dde5f7ad855a4dd7 Mon Sep 17 00:00:00 2001 From: Hika Hibariya Date: Wed, 6 May 2015 09:45:30 +0900 Subject: [PATCH 13/23] Fix indentation in the "Strings" chapter --- src/doc/trpl/strings.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/strings.md b/src/doc/trpl/strings.md index 6ed4c7cb1b379..61a6ec3eb3f4d 100644 --- a/src/doc/trpl/strings.md +++ b/src/doc/trpl/strings.md @@ -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!(""); From 8227db86eb8c9497ba81da35c012f23ece7a1ac0 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Wed, 6 May 2015 01:49:07 +0200 Subject: [PATCH 14/23] fix typos caught by codespell --- src/librustc/middle/resolve_lifetime.rs | 6 +++--- src/librustc_typeck/astconv.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/libstd/sys/unix/process2.rs | 2 +- src/rt/valgrind/valgrind.h | 2 +- src/test/run-pass/issue-20616.rs | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 6f40e17855a78..e7a03a9b7e174 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -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, @@ -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, @@ -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, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 694993cdc0aae..677254238c034 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1344,7 +1344,7 @@ pub fn ast_ty_arg_to_ty<'tcx>(this: &AstConv<'tcx>, } // Check the base def in a PathResolution and convert it to a Ty. If there are -// associated types in the PathResolution, these will need to be seperately +// associated types in the PathResolution, these will need to be separately // resolved. fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>, rscope: &RegionScope, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1e6e9a7562a7c..444e5dea89a46 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -944,7 +944,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics<'tcx>, // a Sized bound, removing the bounds as we find them. // // Note that associated types also have a sized bound by default, but we - // don't actually konw the set of associated types right here so that's + // don't actually know the set of associated types right here so that's // handled in cleaning associated types let mut sized_params = HashSet::new(); where_predicates.retain(|pred| { diff --git a/src/libstd/sys/unix/process2.rs b/src/libstd/sys/unix/process2.rs index 4e7c4d241f532..6f3c0fd63aa6d 100644 --- a/src/libstd/sys/unix/process2.rs +++ b/src/libstd/sys/unix/process2.rs @@ -328,7 +328,7 @@ impl Process { }) { Ok(0) => None, Ok(n) if n == self.pid => Some(translate_status(status)), - Ok(n) => panic!("unkown pid: {}", n), + Ok(n) => panic!("unknown pid: {}", n), Err(e) => panic!("unknown waitpid error: {}", e), } } diff --git a/src/rt/valgrind/valgrind.h b/src/rt/valgrind/valgrind.h index af01dfd71a71c..51f9de8edf057 100644 --- a/src/rt/valgrind/valgrind.h +++ b/src/rt/valgrind/valgrind.h @@ -5122,7 +5122,7 @@ VALGRIND_PRINTF_BACKTRACE(const char *format, ...) /* These requests allow control to move from the simulated CPU to the - real CPU, calling an arbitary function. + real CPU, calling an arbitrary function. Note that the current ThreadId is inserted as the first argument. So this call: diff --git a/src/test/run-pass/issue-20616.rs b/src/test/run-pass/issue-20616.rs index e6b256f7e8413..d5b799710941b 100644 --- a/src/test/run-pass/issue-20616.rs +++ b/src/test/run-pass/issue-20616.rs @@ -32,7 +32,7 @@ type TypeF = Box; // type argument with trailing comma type TypeG = Box; -// trailing comma on liftime defs +// trailing comma on lifetime defs type TypeH<'a,> = &'a (); // trailing comma on type argument From fc9bc779d22db3f9c026081e4f87e82fccdf9fe9 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 6 May 2015 04:18:56 -0400 Subject: [PATCH 15/23] Fix explanation of Cargo's behavior https://github.com/rust-lang/rust/pull/25080/files#r29634986 --- src/doc/trpl/guessing-game.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 431b7dc50a299..9f763e2fa13b8 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -410,11 +410,11 @@ $ 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 @@ -422,12 +422,17 @@ 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 From 085e1f489b1cc830cdcf3d43cb80754647dceabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=89=E3=81=84=E3=81=A9=E3=81=A3=E3=81=A8?= Date: Wed, 6 May 2015 18:11:54 +0900 Subject: [PATCH 16/23] doc: Fix link of repr attribute --- src/doc/complement-design-faq.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/complement-design-faq.md b/src/doc/complement-design-faq.md index 952416ac160e1..1a0155d4773ec 100644 --- a/src/doc/complement-design-faq.md +++ b/src/doc/complement-design-faq.md @@ -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 From 4174aa40f40e05195d73d3eb09b12d9359444f5d Mon Sep 17 00:00:00 2001 From: Kelvin Ly Date: Wed, 6 May 2015 05:43:05 -0400 Subject: [PATCH 17/23] Reword with pnkfelix's suggestion --- src/librustc/diagnostics.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 68dd83a3fe5f2..b6828f1846d85 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -307,18 +307,20 @@ 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 -that there is a mismatch in the expected type that the compiler inferred, and -the actual type that the user defined a variable as. - -let a: char = 7; // An integral type can't be contained in a character, so - // there is a mismatch. - -let b: u32 = 7; // Either use the right type... -let c = 7; // ...or let the compiler infer it. - -let d: char = c; // This also causes a mismatch because c is some sort - // of number whereas d is definitely a character. +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##" From 45c461c4292e32a4f7d21a038e7ba4ccf52c7d56 Mon Sep 17 00:00:00 2001 From: Andrei Oprea Date: Wed, 6 May 2015 15:22:35 +0300 Subject: [PATCH 18/23] Add note about type signature searching to docs --- src/librustdoc/html/layout.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index a53884ca047d1..798cc6a612cde 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -111,6 +111,10 @@ r##" trait, typedef (or tdef).

+

+ Search functions by type signature (e.g. + vec -> usize) +

From 81b90bd56f66950a73029907e79b9f26c6e20b56 Mon Sep 17 00:00:00 2001 From: Paul Banks Date: Wed, 6 May 2015 14:00:35 +0100 Subject: [PATCH 19/23] Correct initial guessing game example. Fixes #25147. r? @steveklabnik --- src/doc/trpl/guessing-game.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 431b7dc50a299..f8dfc621e3a0c 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -86,7 +86,7 @@ fn main() { .ok() .expect("Failed to read line"); - println!("You guessed: {}", input); + println!("You guessed: {}", guess); } ``` @@ -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 From 1d6285ebbace676b3c4c200135f592777178ddfa Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 6 May 2015 13:34:34 +0200 Subject: [PATCH 20/23] Iter Docs: Mention 'reduce' and 'inject' --- src/libcore/iter.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index be66623d0e151..679cb952268cd 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -578,6 +578,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 /// /// ``` From 08923fbff2d024d9b97847bf482678fcc5d9e15d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=89=E3=81=84=E3=81=A9=E3=81=A3=E3=81=A8?= Date: Thu, 7 May 2015 01:58:55 +0900 Subject: [PATCH 21/23] doc: Fix remove unused variable This commit depends on #25148. --- src/doc/trpl/guessing-game.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 431b7dc50a299..586e36585d78e 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -82,7 +82,7 @@ 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"); From 1884c87207369be9bdfc9b765d67c4dbbb08d3d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=89=E3=81=84=E3=81=A9=E3=81=A3=E3=81=A8?= Date: Thu, 7 May 2015 02:20:31 +0900 Subject: [PATCH 22/23] doc: Fix remove secret number at final source Remove printing of secret number at final source. --- src/doc/trpl/guessing-game.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 431b7dc50a299..00a938fdbb90e 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -960,8 +960,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."); From bfdbda24d970515acc453f3ace7700374b8e9324 Mon Sep 17 00:00:00 2001 From: Michael Wu Date: Wed, 6 May 2015 17:09:55 -0400 Subject: [PATCH 23/23] Remove schedule_free_slice Nothing uses it anymore. --- src/librustc_trans/trans/cleanup.rs | 60 ----------------------------- 1 file changed, 60 deletions(-) diff --git a/src/librustc_trans/trans/cleanup.rs b/src/librustc_trans/trans/cleanup.rs index 637325881436d..d23543924dd39 100644 --- a/src/librustc_trans/trans/cleanup.rs +++ b/src/librustc_trans/trans/cleanup.rs @@ -507,23 +507,6 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { self.schedule_clean(cleanup_scope, drop as CleanupObj); } - /// Schedules a call to `free(val)`. Note that this is a shallow operation. - fn schedule_free_slice(&self, - cleanup_scope: ScopeId, - val: ValueRef, - size: ValueRef, - align: ValueRef, - heap: Heap) { - let drop = box FreeSlice { ptr: val, size: size, align: align, heap: heap }; - - debug!("schedule_free_slice({:?}, val={}, heap={:?})", - cleanup_scope, - self.ccx.tn().val_to_string(val), - heap); - - self.schedule_clean(cleanup_scope, drop as CleanupObj); - } - fn schedule_clean(&self, cleanup_scope: ScopeId, cleanup: CleanupObj<'tcx>) { @@ -1106,43 +1089,6 @@ impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> { } } -#[derive(Copy, Clone)] -pub struct FreeSlice { - ptr: ValueRef, - size: ValueRef, - align: ValueRef, - heap: Heap, -} - -impl<'tcx> Cleanup<'tcx> for FreeSlice { - fn must_unwind(&self) -> bool { - true - } - - fn clean_on_unwind(&self) -> bool { - true - } - - fn is_lifetime_end(&self) -> bool { - false - } - - fn trans<'blk>(&self, - bcx: Block<'blk, 'tcx>, - debug_loc: DebugLoc) - -> Block<'blk, 'tcx> { - match self.heap { - HeapExchange => { - glue::trans_exchange_free_dyn(bcx, - self.ptr, - self.size, - self.align, - debug_loc) - } - } - } -} - #[derive(Copy, Clone)] pub struct LifetimeEnd { ptr: ValueRef, @@ -1253,12 +1199,6 @@ pub trait CleanupMethods<'blk, 'tcx> { val: ValueRef, heap: Heap, content_ty: Ty<'tcx>); - fn schedule_free_slice(&self, - cleanup_scope: ScopeId, - val: ValueRef, - size: ValueRef, - align: ValueRef, - heap: Heap); fn schedule_clean(&self, cleanup_scope: ScopeId, cleanup: CleanupObj<'tcx>);