From c680f0818289dfcf5583a6a46aef0a3e4e7c54d2 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Wed, 17 Jun 2015 19:46:33 -0700 Subject: [PATCH 01/12] Add regression test for #21622 Closes #21622 --- src/test/run-pass/issue-21622.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/run-pass/issue-21622.rs diff --git a/src/test/run-pass/issue-21622.rs b/src/test/run-pass/issue-21622.rs new file mode 100644 index 000000000000..32f52308af16 --- /dev/null +++ b/src/test/run-pass/issue-21622.rs @@ -0,0 +1,28 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + + +struct Index; + +impl Index { + fn new() -> Self { Index } +} + +fn user() { + let new = Index::new; + + fn inner() { + let index = Index::new(); + } + + let index2 = new(); +} + +fn main() {} From d234b0bb5f3210ca255d1ad71eb13add272fd078 Mon Sep 17 00:00:00 2001 From: Johannes Oertel Date: Thu, 18 Jun 2015 17:11:44 +0200 Subject: [PATCH 02/12] rustdoc: Update document title when displaying search results Fixes #26360. --- src/librustdoc/html/static/main.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 7f8f40ff08a4..fb8f511795e8 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -571,6 +571,9 @@ return; } + // Update document title to maintain a meaningful browser history + $(document).prop("title", "Results for " + query.query + " - Rust"); + // Because searching is incremental by character, only the most // recent search query is added to the browser history. if (browserSupportsHistoryApi()) { From 57260262e76ec35f05d4a9fad4d13cda212f2c62 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Jun 2015 15:24:36 -0700 Subject: [PATCH 03/12] rustc_trans: Disable landing pads on MSVC Currently all these do is cause linker errors as they try to lower to GNU-like exception handling, none of which exists with MSVC. --- src/librustc_trans/trans/base.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index c2293dcc6d48..b382b71343f4 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -756,7 +756,12 @@ pub fn invoke<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } pub fn need_invoke(bcx: Block) -> bool { - if bcx.sess().no_landing_pads() { + // FIXME(#25869) currently unwinding is not implemented for MSVC and our + // normal unwinding infrastructure ends up just causing linker + // errors with the current LLVM implementation, so landing + // pads are disabled entirely for MSVC targets + if bcx.sess().no_landing_pads() || + bcx.sess().target.target.options.is_like_msvc { return false; } From 98205afe0b09b22e9d88968ed61095b15fcfb1e3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:54:57 +0200 Subject: [PATCH 04/12] Add E0036 error explanation --- src/librustc_typeck/diagnostics.rs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d89174295a89..5b981ed141d1 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -211,6 +211,53 @@ struct Dog { http://doc.rust-lang.org/reference.html#trait-objects "##, +E0036: r##" +This error occurred when you pass too many or not enough type parameters to a +method. Example: + +``` +struct Test; + +impl Test { + fn method(&self, v: &[T]) -> usize { + v.len() + } +} + +fn main() { + let x = Test; + let v = &[0i32]; + + x.method::(v); // error: only one type parameter is expected! +} +``` + +To fix it, just specify a correct number of type parameters: + +``` +struct Test; + +impl Test { + fn method(&self, v: &[T]) -> usize { + v.len() + } +} + +fn main() { + let x = Test; + let v = &[0i32]; + + x.method::(v); // OK, we're good! +} +``` + +Please note on the last example that we could have called `method` like this: + +``` +x.method(v); +``` +"##, + E0040: r##" It is not allowed to manually call destructors in Rust. It is also not necessary to do this since `drop` is called automatically whenever a value goes From 00e115d090180c9fe13856500576978ff3007cda Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:56:53 +0200 Subject: [PATCH 05/12] Good time concordance --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 5b981ed141d1..a9fe1a1f82b9 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -212,8 +212,8 @@ struct Dog { "##, E0036: r##" -This error occurred when you pass too many or not enough type parameters to a -method. Example: +This error occurrs when you pass too many or not enough type parameters to +a method. Example: ``` struct Test; From 04888e7c600fed71d989937cc8f582bea83423a2 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:58:15 +0200 Subject: [PATCH 06/12] Add E0035 error explanation --- src/librustc_typeck/diagnostics.rs | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a9fe1a1f82b9..c95dbd3ca13b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -211,6 +211,40 @@ struct Dog { http://doc.rust-lang.org/reference.html#trait-objects "##, +E0035: r##" +You tried to give a type parameter where it wasn't needed. Bad example: + +``` +struct Test; + +impl Test { + fn method(&self) {} +} + +fn main() { + let x = Test; + + x.method::(); // Error: Test::method doesn't need type parameter! +} +``` + +To fix this error, just remove the type parameter: + +``` +struct Test; + +impl Test { + fn method(&self) {} +} + +fn main() { + let x = Test; + + x.method(); // OK, we're good! +} +``` +"##, + E0036: r##" This error occurrs when you pass too many or not enough type parameters to a method. Example: From b4481e68deeffc9e6cf4648d10c51750adbb4c3b Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:58:52 +0200 Subject: [PATCH 07/12] Remove unneeded indentation --- src/librustc_typeck/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index c95dbd3ca13b..f338a774e90e 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -223,7 +223,7 @@ fn method(&self) {} fn main() { let x = Test; - + x.method::(); // Error: Test::method doesn't need type parameter! } ``` @@ -239,7 +239,7 @@ fn method(&self) {} fn main() { let x = Test; - + x.method(); // OK, we're good! } ``` From d4c37088ca873a23e58d512d9418f59056477226 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 13:59:51 +0200 Subject: [PATCH 08/12] Add E0034 error explanation --- src/librustc_typeck/diagnostics.rs | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index f338a774e90e..431880c2076b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -211,6 +211,47 @@ struct Dog { http://doc.rust-lang.org/reference.html#trait-objects "##, +E0034: r##" +The compiler doesn't know what method to call because more than one does +have the same prototype. Example: + +``` +struct Test; + +trait Trait1 { + fn foo(); +} + +trait Trait2 { + fn foo(); +} + +impl Trait1 for Test { fn foo() {} } +impl Trait2 for Test { fn foo() {} } + +fn main() { + Test::foo() // error, what foo() to call? +} +``` + +To avoid this error, you have to keep only one of them and remove the others. +So let's take our example and fix it: + +``` +struct Test; + +trait Trait1 { + fn foo(); +} + +impl Trait1 for Test { fn foo() {} } + +fn main() { + Test::foo() // and now that's good! +} +``` +"##, + E0035: r##" You tried to give a type parameter where it wasn't needed. Bad example: From 8c5572fc2114fa2e8156c89cda89c799c9c3e9e0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:01:55 +0200 Subject: [PATCH 09/12] Add Universal Function Call Syntax example --- src/librustc_typeck/diagnostics.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 431880c2076b..bcc415e4e1a6 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -212,8 +212,8 @@ struct Dog { "##, E0034: r##" -The compiler doesn't know what method to call because more than one does -have the same prototype. Example: +The compiler doesn't know what method to call because more than one method +has the same prototype. Example: ``` struct Test; @@ -230,7 +230,7 @@ impl Trait1 for Test { fn foo() {} } impl Trait2 for Test { fn foo() {} } fn main() { - Test::foo() // error, what foo() to call? + Test::foo() // error, which foo() to call? } ``` @@ -250,6 +250,28 @@ fn main() { Test::foo() // and now that's good! } ``` + +However, a better solution would be using fully explicit naming of type and +trait: + +``` +struct Test; + +trait Trait1 { + fn foo(); +} + +trait Trait2 { + fn foo(); +} + +impl Trait1 for Test { fn foo() {} } +impl Trait2 for Test { fn foo() {} } + +fn main() { + ::foo() +} +``` "##, E0035: r##" From 6471dccd3b3a5b83b4fccecffc94047e1086ca2f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:03:07 +0200 Subject: [PATCH 10/12] Add E0016 explanation --- src/librustc/diagnostics.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 0857fb3258ee..124117ca80bc 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -256,6 +256,21 @@ fn index<'a>(&'a self, idx: u8) -> &'a u8 { &self.a } [RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md "##, +E0016: r##" +Blocks in constants may only contain items (such as constant, function +definition, etc...) and a tail expression. Example: + +``` +const FOO: i32 = { let x = 0; x }; // 'x' isn't an item! +``` + +To avoid it, you have to replace the non-item object: + +``` +const FOO: i32 = { const X : i32 = 0; X }; +``` +"##, + E0018: r##" The value of static and const variables must be known at compile time. You can't cast a pointer as an integer because we can't know what value the From 2015eb881e8d9e82c1a889595c5b7b33440b2ae7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:05:11 +0200 Subject: [PATCH 11/12] Replace "Bad example" by a better sentence --- src/librustc/diagnostics.rs | 38 +++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 124117ca80bc..0f83cdff5372 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -294,6 +294,42 @@ fn index<'a>(&'a self, idx: u8) -> &'a u8 { &self.a } ``` "##, +E0019: r##" +A function call isn't allowed in the const's initialization expression +because the expression's value must be known at compile-time. Example of +erroneous code: + +``` +enum Test { + V1 +} + +impl Test { + fn test(&self) -> i32 { + 12 + } +} + +fn main() { + const FOO: Test = Test::V1; + + const A: i32 = FOO.test(); // You can't call Test::func() here ! +} +``` + +Remember: you can't use a function call inside a const's initialization +expression! However, you can totally use it elsewhere you want: + +``` +fn main() { + const FOO: Test = Test::V1; + + FOO.func(); // here is good + let x = FOO.func(); // or even here! +} +``` +"##, + E0020: r##" This error indicates that an attempt was made to divide by zero (or take the remainder of a zero divisor) in a static or constant expression. @@ -965,9 +1001,7 @@ fn bar(&self) -> i32 { self.0 } register_diagnostics! { - E0016, E0017, - E0019, E0022, E0038, E0109, From 9679faa97afbdb9738df16b81175b7090915897f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 19 Jun 2015 14:06:33 +0200 Subject: [PATCH 12/12] Remove error codes from macro --- src/librustc_typeck/diagnostics.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index bcc415e4e1a6..fa29f8f1dcea 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1464,9 +1464,6 @@ impl Baz for Bar { } // Note: This is OK } register_diagnostics! { - E0034, // multiple applicable methods in scope - E0035, // does not take type parameters - E0036, // incorrect number of type parameters given for this method E0044, // foreign items may not have type parameters E0045, // variadic function must have C calling convention E0068,