diff --git a/src/librustc_mir/diagnostics.rs b/src/librustc_mir/diagnostics.rs index 65d51d205285a..4a731d898a937 100644 --- a/src/librustc_mir/diagnostics.rs +++ b/src/librustc_mir/diagnostics.rs @@ -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! +``` "##, diff --git a/src/test/compile-fail/E0394.rs b/src/test/compile-fail/E0394.rs new file mode 100644 index 0000000000000..1b86b8ad67496 --- /dev/null +++ b/src/test/compile-fail/E0394.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0395.rs b/src/test/compile-fail/E0395.rs new file mode 100644 index 0000000000000..6ab66313a0472 --- /dev/null +++ b/src/test/compile-fail/E0395.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0396.rs b/src/test/compile-fail/E0396.rs new file mode 100644 index 0000000000000..7f34acdfb9007 --- /dev/null +++ b/src/test/compile-fail/E0396.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0401.rs b/src/test/compile-fail/E0401.rs new file mode 100644 index 0000000000000..09bc950efd2d6 --- /dev/null +++ b/src/test/compile-fail/E0401.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo(x: T) { + fn bar(y: T) { //~ ERROR E0401 + } + bar(x); +} + +fn main() { +} diff --git a/src/test/compile-fail/E0403.rs b/src/test/compile-fail/E0403.rs new file mode 100644 index 0000000000000..6a68013dc6ffe --- /dev/null +++ b/src/test/compile-fail/E0403.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn foo(s: T, u: T) {} //~ ERROR E0403 + +fn main() { +} diff --git a/src/test/compile-fail/E0404.rs b/src/test/compile-fail/E0404.rs new file mode 100644 index 0000000000000..1c088a71d7d4b --- /dev/null +++ b/src/test/compile-fail/E0404.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0405.rs b/src/test/compile-fail/E0405.rs new file mode 100644 index 0000000000000..45d4b219ba818 --- /dev/null +++ b/src/test/compile-fail/E0405.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0407.rs b/src/test/compile-fail/E0407.rs new file mode 100644 index 0000000000000..b861cf1b37817 --- /dev/null +++ b/src/test/compile-fail/E0407.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0408.rs b/src/test/compile-fail/E0408.rs new file mode 100644 index 0000000000000..43f6d9d757d7e --- /dev/null +++ b/src/test/compile-fail/E0408.rs @@ -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 or the MIT license +// , 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 + _ => () + } +} diff --git a/src/test/compile-fail/E0409.rs b/src/test/compile-fail/E0409.rs new file mode 100644 index 0000000000000..366ad15207250 --- /dev/null +++ b/src/test/compile-fail/E0409.rs @@ -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 or the MIT license +// , 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 + _ => () + } +} diff --git a/src/test/compile-fail/E0411.rs b/src/test/compile-fail/E0411.rs new file mode 100644 index 0000000000000..187986fbadbe0 --- /dev/null +++ b/src/test/compile-fail/E0411.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + ::foo; //~ ERROR E0411 +} diff --git a/src/test/compile-fail/E0412.rs b/src/test/compile-fail/E0412.rs new file mode 100644 index 0000000000000..f62901cac31c1 --- /dev/null +++ b/src/test/compile-fail/E0412.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +impl Something {} //~ ERROR E0412 + +fn main() { +} diff --git a/src/test/compile-fail/E0415.rs b/src/test/compile-fail/E0415.rs new file mode 100644 index 0000000000000..2a5f0d3c229b1 --- /dev/null +++ b/src/test/compile-fail/E0415.rs @@ -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 or the MIT license +// , 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() { +} diff --git a/src/test/compile-fail/E0416.rs b/src/test/compile-fail/E0416.rs new file mode 100644 index 0000000000000..91077ab37f322 --- /dev/null +++ b/src/test/compile-fail/E0416.rs @@ -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 or the MIT license +// , 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 + } +} diff --git a/src/test/compile-fail/E0422.rs b/src/test/compile-fail/E0422.rs new file mode 100644 index 0000000000000..d1cb7fd9640da --- /dev/null +++ b/src/test/compile-fail/E0422.rs @@ -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 or the MIT license +// , 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 +}