mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
Auto merge of #35680 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
This commit is contained in:
commit
197be89f36
@ -188,12 +188,30 @@ avoid mutation if possible.
|
||||
"##,
|
||||
|
||||
E0394: r##"
|
||||
From [RFC 246]:
|
||||
A static was referred to by value by another static.
|
||||
|
||||
> It is invalid for a static to reference another static by value. It is
|
||||
> required that all references be borrowed.
|
||||
Erroneous code examples:
|
||||
|
||||
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
|
||||
```compile_fail,E0394
|
||||
static A: u32 = 0;
|
||||
static B: u32 = A; // error: cannot refer to other statics by value, use the
|
||||
// address-of operator or a constant instead
|
||||
```
|
||||
|
||||
A static cannot be referred by value. To fix this issue, either use a
|
||||
constant:
|
||||
|
||||
```
|
||||
const A: u32 = 0; // `A` is now a constant
|
||||
static B: u32 = A; // ok!
|
||||
```
|
||||
|
||||
Or refer to `A` by reference:
|
||||
|
||||
```
|
||||
static A: u32 = 0;
|
||||
static B: &'static u32 = &A; // ok!
|
||||
```
|
||||
"##,
|
||||
|
||||
|
||||
|
15
src/test/compile-fail/E0394.rs
Normal file
15
src/test/compile-fail/E0394.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
static A: u32 = 0;
|
||||
static B: u32 = A; //~ ERROR E0394
|
||||
|
||||
fn main() {
|
||||
}
|
17
src/test/compile-fail/E0395.rs
Normal file
17
src/test/compile-fail/E0395.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
static FOO: i32 = 42;
|
||||
static BAR: i32 = 42;
|
||||
|
||||
static BAZ: bool = { (&FOO as *const i32) == (&BAR as *const i32) }; //~ ERROR E0395
|
||||
|
||||
fn main() {
|
||||
}
|
16
src/test/compile-fail/E0396.rs
Normal file
16
src/test/compile-fail/E0396.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
const REG_ADDR: *const u8 = 0x5f3759df as *const u8;
|
||||
|
||||
const VALUE: u8 = unsafe { *REG_ADDR }; //~ ERROR E0396
|
||||
|
||||
fn main() {
|
||||
}
|
18
src/test/compile-fail/E0401.rs
Normal file
18
src/test/compile-fail/E0401.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn foo<T>(x: T) {
|
||||
fn bar(y: T) { //~ ERROR E0401
|
||||
}
|
||||
bar(x);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
14
src/test/compile-fail/E0403.rs
Normal file
14
src/test/compile-fail/E0403.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn foo<T, T>(s: T, u: T) {} //~ ERROR E0403
|
||||
|
||||
fn main() {
|
||||
}
|
17
src/test/compile-fail/E0404.rs
Normal file
17
src/test/compile-fail/E0404.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2016 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 Foo;
|
||||
struct Bar;
|
||||
|
||||
impl Foo for Bar {} //~ ERROR E0404
|
||||
|
||||
fn main() {
|
||||
}
|
16
src/test/compile-fail/E0405.rs
Normal file
16
src/test/compile-fail/E0405.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2016 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 Foo;
|
||||
|
||||
impl SomeTrait for Foo {} //~ ERROR E0405
|
||||
|
||||
fn main() {
|
||||
}
|
23
src/test/compile-fail/E0407.rs
Normal file
23
src/test/compile-fail/E0407.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
trait Foo {
|
||||
fn a();
|
||||
}
|
||||
|
||||
struct Bar;
|
||||
|
||||
impl Foo for Bar {
|
||||
fn a() {}
|
||||
fn b() {} //~ ERROR E0407
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
18
src/test/compile-fail/E0408.rs
Normal file
18
src/test/compile-fail/E0408.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn main() {
|
||||
let x = Some(0);
|
||||
|
||||
match x {
|
||||
Some(y) | None => {} //~ ERROR E0408
|
||||
_ => ()
|
||||
}
|
||||
}
|
19
src/test/compile-fail/E0409.rs
Normal file
19
src/test/compile-fail/E0409.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn main() {
|
||||
let x = (0, 2);
|
||||
|
||||
match x {
|
||||
(0, ref y) | (y, 0) => {} //~ ERROR E0409
|
||||
//~^ ERROR E0308
|
||||
_ => ()
|
||||
}
|
||||
}
|
13
src/test/compile-fail/E0411.rs
Normal file
13
src/test/compile-fail/E0411.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn main() {
|
||||
<Self>::foo; //~ ERROR E0411
|
||||
}
|
14
src/test/compile-fail/E0412.rs
Normal file
14
src/test/compile-fail/E0412.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
impl Something {} //~ ERROR E0412
|
||||
|
||||
fn main() {
|
||||
}
|
14
src/test/compile-fail/E0415.rs
Normal file
14
src/test/compile-fail/E0415.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn foo(f: i32, f: i32) {} //~ ERROR E0415
|
||||
|
||||
fn main() {
|
||||
}
|
15
src/test/compile-fail/E0416.rs
Normal file
15
src/test/compile-fail/E0416.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn main() {
|
||||
match (1, 2) {
|
||||
(x, x) => {} //~ ERROR E0416
|
||||
}
|
||||
}
|
13
src/test/compile-fail/E0422.rs
Normal file
13
src/test/compile-fail/E0422.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright 2016 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.
|
||||
|
||||
fn main () {
|
||||
let x = Foo { x: 1, y: 2 }; //~ ERROR E0422
|
||||
}
|
Loading…
Reference in New Issue
Block a user