mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-21 17:52:12 +03:00
Auto merge of #26428 - Manishearth:rollup, r=Manishearth
- Successful merges: #26388, #26401, #26414, #26427 - Failed merges:
This commit is contained in:
@@ -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
|
||||
@@ -279,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.
|
||||
@@ -950,9 +1001,7 @@ fn bar(&self) -> i32 { self.0 }
|
||||
|
||||
|
||||
register_diagnostics! {
|
||||
E0016,
|
||||
E0017,
|
||||
E0019,
|
||||
E0022,
|
||||
E0038,
|
||||
E0109,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -211,6 +211,150 @@ 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 method
|
||||
has 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, which 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!
|
||||
}
|
||||
```
|
||||
|
||||
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() {
|
||||
<Test as Trait1>::foo()
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
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::<i32>(); // 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:
|
||||
|
||||
```
|
||||
struct Test;
|
||||
|
||||
impl Test {
|
||||
fn method<T>(&self, v: &[T]) -> usize {
|
||||
v.len()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Test;
|
||||
let v = &[0i32];
|
||||
|
||||
x.method::<i32, i32>(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<T>(&self, v: &[T]) -> usize {
|
||||
v.len()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = Test;
|
||||
let v = &[0i32];
|
||||
|
||||
x.method::<i32>(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
|
||||
@@ -1320,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,
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() {}
|
||||
Reference in New Issue
Block a user