From f1c2480d47876f094e9c11e7d5139186bbc6d990 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 6 Aug 2016 18:42:10 +0200 Subject: [PATCH 1/5] Add E0312 error explanation --- src/librustc/diagnostics.rs | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 74e2c90503cd..07e54dc9e879 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1399,6 +1399,38 @@ struct Foo { ``` "##, +E0312: r##" +A lifetime of reference outlives lifetime of borrowed content. + +Erroneous code example: + +```compile_fail,E0312 +fn make_child<'human, 'elve>(x: &mut &'human isize, y: &mut &'elve isize) { + *x = *y; + // error: lifetime of reference outlives lifetime of borrowed content +} +``` + +The compiler cannot determine if the `human` lifetime will live long enough +to keep up on the elve one. To solve this error, you have to give an +explicit lifetime hierarchy: + +``` +fn make_child<'human, 'elve: 'human>(x: &mut &'human isize, + y: &mut &'elve isize) { + *x = *y; // ok! +} +``` + +Or use the same lifetime for every variable: + +``` +fn make_child<'elve>(x: &mut &'elve isize, y: &mut &'elve isize) { + *x = *y; // ok! +} +``` +"##, + E0398: r##" In Rust 1.3, the default object lifetime bounds are expected to change, as described in RFC #1156 [1]. You are getting a warning because the compiler @@ -1674,7 +1706,6 @@ fn cookie() -> ! { // error: definition of an unknown language item: `cookie` // E0304, // expected signed integer constant // E0305, // expected constant 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 E0314, // closure outlives stack frame E0315, // cannot invoke closure outside of its lifetime From 9d8d47d894122b7c6a3538d141db22a533723bb8 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 6 Aug 2016 19:39:59 +0200 Subject: [PATCH 2/5] Improve librustc_typeck compile_fail check --- src/librustc_typeck/diagnostics.rs | 310 +++++++++++++++-------------- 1 file changed, 156 insertions(+), 154 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 64b27857d2c6..db11b9041f57 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -43,7 +43,7 @@ enum Fruit { Matching with the wrong number of fields has no sensible interpretation: -```compile_fail +```compile_fail,E0023 enum Fruit { Apple(String, String), Pear(u32), @@ -66,7 +66,7 @@ enum Fruit { Each field of a struct can only be bound once in a pattern. Erroneous code example: -```compile_fail +```compile_fail,E0025 struct Foo { a: u8, b: u8, @@ -123,7 +123,7 @@ struct Thing { Change this: -```compile_fail +```compile_fail,E0026 struct Thing { x: u32, y: u32 @@ -159,7 +159,7 @@ struct Thing { For example: -```compile_fail +```compile_fail,E0027 struct Dog { name: String, age: u32, @@ -201,7 +201,9 @@ struct Dog { want to capture values of an orderable type between two end-points, you can use a guard. -```compile_fail +```compile_fail,E0029 +let string = "salutations !"; + // The ordering relation for strings can't be evaluated at compile time, // so this doesn't work: match string { @@ -245,7 +247,7 @@ struct Dog { The compiler doesn't know what method to call because more than one method has the same prototype. Erroneous code example: -```compile_fail +```compile_fail,E0034 struct Test; trait Trait1 { @@ -332,7 +334,7 @@ fn main() { You tried to give a type parameter where it wasn't needed. Erroneous code example: -```compile_fail +```compile_fail,E0035 struct Test; impl Test { @@ -367,7 +369,7 @@ fn main() { This error occurrs when you pass too many or not enough type parameters to a method. Erroneous code example: -```compile_fail +```compile_fail,E0036 struct Test; impl Test { @@ -417,7 +419,7 @@ fn main() { Here's an example of this error: -```compile_fail +```compile_fail,E0040 struct Foo { x: i32, } @@ -438,7 +440,7 @@ fn main() { E0044: r##" You can't use type parameters on foreign items. Example of erroneous code: -```compile_fail +```compile_fail,E0044 extern { fn some_func(x: T); } ``` @@ -456,7 +458,9 @@ fn main() { FFI. As such, variadic parameters can only be used with functions which are using the C ABI. Examples of erroneous code: -```compile_fail +```compile_fail,E0045 +#![feature(unboxed_closures)] + extern "rust-call" { fn foo(x: u8, ...); } // or @@ -466,12 +470,6 @@ fn foo(x: u8, ...) {} To fix such code, put them in an extern "C" block: -```ignore -extern "C" fn foo(x: u8, ...); -``` - -Or: - ``` extern "C" { fn foo (x: u8, ...); @@ -482,7 +480,7 @@ fn foo(x: u8, ...) {} E0046: r##" Items are missing in a trait implementation. Erroneous code example: -```compile_fail +```compile_fail,E0046 trait Foo { fn foo(); } @@ -518,7 +516,7 @@ fn foo() {} // ok! For example, the trait below has a method `foo` with a type parameter `T`, but the implementation of `foo` for the type `Bar` is missing this parameter: -```compile_fail +```compile_fail,E0049 trait Foo { fn foo(x: T) -> Self; } @@ -541,7 +539,7 @@ fn foo(x: bool) -> Self { Bar } (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits the `u8` parameter: -```compile_fail +```compile_fail,E0050 trait Foo { fn foo(&self, x: u8) -> bool; } @@ -562,7 +560,7 @@ fn foo(&self) -> bool { true } Here are a couple examples of this error: -```compile_fail +```compile_fail,E0053 trait Foo { fn foo(x: u16); fn bar(&self); @@ -584,7 +582,7 @@ fn bar(&mut self) { } It is not allowed to cast to a bool. If you are trying to cast a numeric type to a bool, you can compare it with zero instead: -```compile_fail +```compile_fail,E0054 let x = 5; // Not allowed, won't compile @@ -607,7 +605,7 @@ fn bar(&mut self) { } For a somewhat artificial example: -```compile_fail,ignore +```compile_fail,E0055 #![recursion_limit="2"] struct Foo; @@ -637,7 +635,7 @@ fn main() { An example using a closure: -```compile_fail +```compile_fail,E0057 let f = |x| x * 3; let a = f(); // invalid, too few parameters let b = f(4); // this works! @@ -663,13 +661,17 @@ fn foo(f: F) { The most likely source of this error is using angle-bracket notation without wrapping the function argument type into a tuple, for example: -```compile_fail +```compile_fail,E0059 +#![feature(unboxed_closures)] + fn foo>(f: F) -> F::Output { f(3) } ``` It can be fixed by adjusting the trait bound like this: -```ignore +``` +#![feature(unboxed_closures)] + fn foo>(f: F) -> F::Output { f(3) } ``` @@ -726,9 +728,9 @@ fn f(a: u16, b: &str) {} enum variant, one of the fields was specified more than once. Erroneous code example: -```compile_fail +```compile_fail,E0062 struct Foo { - x: i32 + x: i32, } fn main() { @@ -743,7 +745,7 @@ fn main() { ``` struct Foo { - x: i32 + x: i32, } fn main() { @@ -756,10 +758,10 @@ fn main() { This error indicates that during an attempt to build a struct or struct-like enum variant, one of the fields was not provided. Erroneous code example: -```compile_fail +```compile_fail,E0063 struct Foo { x: i32, - y: i32 + y: i32, } fn main() { @@ -772,7 +774,7 @@ fn main() { ``` struct Foo { x: i32, - y: i32 + y: i32, } fn main() { @@ -799,7 +801,7 @@ fn main() { Let's start with some erroneous code examples: -```compile_fail +```compile_fail,E0067 use std::collections::LinkedList; // Bad: assignment to non-lvalue expression @@ -831,7 +833,7 @@ fn some_func(i: &mut i32) { The compiler found a function whose body contains a `return;` statement but whose return type is not `()`. An example of this is: -```compile_fail +```compile_fail,E0069 // error fn foo() -> u8 { return; @@ -853,7 +855,7 @@ fn foo() -> u8 { Now, we can go further. Here are some erroneous code examples: -```compile_fail +```compile_fail,E0070 struct SomeStruct { x: i32, y: i32 @@ -897,7 +899,7 @@ fn some_func(x: &mut i32) { Example of erroneous code: -```compile_fail +```compile_fail,E0071 enum Foo { FirstValue(i32) }; let u = Foo::FirstValue { value: 0 }; // error: Foo::FirstValue @@ -976,7 +978,7 @@ struct Foo { x: Option> } This will cause an error: -```compile_fail +```compile_fail,E0075 #![feature(repr_simd)] #[repr(simd)] @@ -1000,7 +1002,7 @@ struct Foo { x: Option> } This will cause an error: -```compile_fail +```compile_fail,E0076 #![feature(repr_simd)] #[repr(simd)] @@ -1023,7 +1025,7 @@ struct Foo { x: Option> } This will cause an error: -```compile_fail +```compile_fail,E0077 #![feature(repr_simd)] #[repr(simd)] @@ -1047,9 +1049,9 @@ struct Foo { x: Option> } For example, in the following code: -```compile_fail +```compile_fail,E0079 enum Foo { - Q = "32" + Q = "32", } ``` @@ -1060,7 +1062,7 @@ enum Foo { ``` enum Foo { - Q = 32 + Q = 32, } ``` @@ -1084,12 +1086,12 @@ fn get_str(&self) -> &'static str { This error indicates that the same value was used for two or more variants, making them impossible to tell apart. -```compile_fail +```compile_fail,E0081 // Bad. enum Enum { P = 3, X = 3, - Y = 5 + Y = 5, } ``` @@ -1098,7 +1100,7 @@ enum Enum { enum Enum { P, X = 3, - Y = 5 + Y = 5, } ``` @@ -1106,7 +1108,7 @@ enum Enum { top to bottom starting from 0, so clashes can occur with seemingly unrelated variants. -```compile_fail +```compile_fail,E0081 enum Bad { X, Y = 0 @@ -1128,7 +1130,7 @@ enum Bad { #[repr(u8)] enum Thing { A = 1024, - B = 5 + B = 5, } ``` @@ -1137,7 +1139,7 @@ enum Thing { ```ignore enum DependsOnPointerSize { - A = 1 << 32 + A = 1 << 32, } ``` @@ -1153,7 +1155,7 @@ enum DependsOnPointerSize { Erroneous code example: -```compile_fail +```compile_fail,E0084 #[repr(i32)] enum NightsWatch {} // error: unsupported representation for zero-variant enum ``` @@ -1181,7 +1183,7 @@ enum NightsWatch {} E0087: r##" Too many type parameters were supplied for a function. For example: -```compile_fail +```compile_fail,E0087 fn foo() {} fn main() { @@ -1196,7 +1198,7 @@ fn main() { E0088: r##" You gave too many lifetime parameters. Erroneous code example: -```compile_fail +```compile_fail,E0088 fn f() {} fn main() { @@ -1241,7 +1243,7 @@ fn main() { E0089: r##" Not enough type parameters were supplied for a function. For example: -```compile_fail +```compile_fail,E0089 fn foo() {} fn main() { @@ -1252,7 +1254,7 @@ fn main() { Note that if a function takes multiple type parameters but you want the compiler to infer some of them, you can use type placeholders: -```compile_fail +```compile_fail,E0089 fn foo(x: T) {} fn main() { @@ -1267,7 +1269,7 @@ fn main() { You gave an unnecessary type parameter in a type alias. Erroneous code example: -```compile_fail +```compile_fail,E0091 type Foo = u32; // error: type parameter `T` is unused // or: type Foo = Box; // error: type parameter `B` is unused @@ -1285,7 +1287,7 @@ fn main() { You tried to declare an undefined atomic operation function. Erroneous code example: -```compile_fail +```compile_fail,E0092 #![feature(intrinsics)] extern "rust-intrinsic" { @@ -1310,7 +1312,7 @@ fn main() { E0093: r##" You declared an unknown intrinsic function. Erroneous code example: -```compile_fail +```compile_fail,E0093 #![feature(intrinsics)] extern "rust-intrinsic" { @@ -1347,7 +1349,7 @@ fn main() { You gave an invalid number of type parameters to an intrinsic function. Erroneous code example: -```compile_fail +```compile_fail,E0094 #![feature(intrinsics)] extern "rust-intrinsic" { @@ -1373,10 +1375,8 @@ fn main() { You hit this error because the compiler lacks the information to determine a type for this expression. Erroneous code example: -```compile_fail -fn main() { - let x = |_| {}; // error: cannot determine a type for this expression -} +```compile_fail,E0101 +let x = |_| {}; // error: cannot determine a type for this expression ``` You have two possibilities to solve this situation: @@ -1386,12 +1386,10 @@ fn main() { Examples: ``` -fn main() { - let x = |_ : u32| {}; // ok! - // or: - let x = |_| {}; - x(0u32); -} +let x = |_ : u32| {}; // ok! +// or: +let x = |_| {}; +x(0u32); ``` "##, @@ -1399,11 +1397,9 @@ fn main() { You hit this error because the compiler lacks the information to determine the type of this variable. Erroneous code example: -```compile_fail -fn main() { - // could be an array of anything - let x = []; // error: cannot determine a type for this local variable -} +```compile_fail,E0102 +// could be an array of anything +let x = []; // error: cannot determine a type for this local variable ``` To solve this situation, constrain the type of the variable. @@ -1425,7 +1421,7 @@ fn main() { Here are some simple examples of where you'll run into this error: -```compile_fail +```compile_fail,E0106 struct Foo { x: &bool } // error struct Foo<'a> { x: &'a bool } // correct @@ -1453,7 +1449,7 @@ enum Bar<'a> { A(u8), B(&'a bool), } // correct Here are some examples of elision errors: -```compile_fail +```compile_fail,E0106 // error, no input lifetimes fn foo() -> &str { } @@ -1473,7 +1469,7 @@ fn baz<'a>(x: &'a str, y: &str) -> &str { } Some basic examples include: -```compile_fail +```compile_fail,E0107 struct Foo<'a>(&'a str); enum Bar { A, B, C } @@ -1486,7 +1482,7 @@ struct Baz<'a> { Here's an example that is currently an error, but may work in a future version of Rust: -```compile_fail +```compile_fail,E0107 struct Foo<'a>(&'a str); trait Quux { } @@ -1504,7 +1500,7 @@ impl Quux for Foo { } // error: expected 1, found 0 where the type was defined. For example, an `impl` block as below is not allowed since `Vec` is defined in the standard library: -```compile_fail +```compile_fail,E0116 impl Vec { } // error ``` @@ -1518,7 +1514,7 @@ impl Vec { } // error Note that using the `type` keyword does not work here because `type` only introduces a type alias: -```compile_fail +```compile_fail,E0116 type Bytes = Vec; impl Bytes { } // error, same as above @@ -1536,7 +1532,7 @@ trait defined in another crate) where Here's one example of this error: -```compile_fail +```compile_fail,E0117 impl Drop for u32 {} ``` @@ -1579,7 +1575,7 @@ fn get(&self) -> usize { 0 } You're trying to write an inherent implementation for something which isn't a struct nor an enum. Erroneous code example: -```compile_fail +```compile_fail,E0118 impl (u8, u8) { // error: no base type found for inherent implementation fn get_state(&self) -> String { // ... @@ -1623,7 +1619,7 @@ fn get_state(&self) -> String { There are conflicting trait implementations for the same type. Example of erroneous code: -```compile_fail +```compile_fail,E0119 trait MyTrait { fn get(&self) -> usize; } @@ -1684,7 +1680,7 @@ fn main() { An attempt was made to implement Drop on a trait, which is not allowed: only structs and enums can implement Drop. An example causing this error: -```compile_fail +```compile_fail,E0120 trait MyTrait {} impl Drop for MyTrait { @@ -1725,7 +1721,7 @@ fn drop(&mut self) {} Examples of this error include: -```compile_fail +```compile_fail,E0121 fn foo() -> _ { 5 } // error, explicitly write out the return type instead static BAR: _ = "test"; // error, explicitly write out the type instead @@ -1756,7 +1752,7 @@ fn main() { You declared two fields of a struct with the same name. Erroneous code example: -```compile_fail +```compile_fail,E0124 struct Foo { field1: i32, field1: i32, // error: field is already declared @@ -1777,7 +1773,7 @@ struct Foo { Type parameter defaults can only use parameters that occur before them. Erroneous code example: -```compile_fail +```compile_fail,E0128 struct Foo { field1: T, filed2: U, @@ -1805,7 +1801,7 @@ struct Foo { parameters. When `main` is present, it must take no arguments and return `()`. Erroneous code example: -```compile_fail +```compile_fail,E0131 fn main() { // error: main function is not allowed to have type parameters } ``` @@ -1816,7 +1812,7 @@ fn main() { // error: main function is not allowed to have type parameters Erroneous code example: -```compile_fail +```compile_fail,E0132 #![feature(start)] #[start] @@ -1847,7 +1843,7 @@ fn my_start(argc: isize, argv: *const *const u8) -> isize { This error means that an attempt was made to match a struct type enum variant as a non-struct type: -```compile_fail +```compile_fail,E0164 enum Foo { B { i: u32 } } fn bar(foo: Foo) -> u32 { @@ -1875,7 +1871,7 @@ fn bar(foo: Foo) -> u32 { marked as diverging. A function diverges if it has `!` in the place of the return type in its signature. For example: -```compile_fail +```compile_fail,E0166 fn foo() -> ! { return; } // error ``` @@ -1888,7 +1884,7 @@ fn bar(foo: Foo) -> u32 { This error means that an attempt was made to specify the type of a variable with a combination of a concrete type and a trait. Consider the following example: -```compile_fail +```compile_fail,E0172 fn foo(bar: i32+std::fmt::Display) {} ``` @@ -1917,7 +1913,7 @@ fn foo(bar: i32) {} For example: -```compile_fail +```compile_fail,E0178 trait Foo {} struct Bar<'a> { @@ -1949,7 +1945,7 @@ struct Bar<'a> { Here's an example of this error: -```compile_fail +```compile_fail,E0185 trait Foo { fn foo(); } @@ -1971,7 +1967,7 @@ fn foo(&self) {} Here's an example of this error: -```compile_fail +```compile_fail,E0186 trait Foo { fn foo(&self); } @@ -1990,7 +1986,7 @@ fn foo() {} Trait objects need to have all associated types specified. Erroneous code example: -```compile_fail +```compile_fail,E0191 trait Trait { type Bar; } @@ -2066,7 +2062,7 @@ fn bar(&self) { } A type parameter was declared which shadows an existing one. An example of this error: -```compile_fail +```compile_fail,E0194 trait Foo { fn do_something(&self) -> T; fn do_something_else(&self, bar: T); @@ -2082,7 +2078,7 @@ trait Foo { Your method's lifetime parameters do not match the trait declaration. Erroneous code example: -```compile_fail +```compile_fail,E0195 trait Trait { fn bar<'a,'b:'a>(x: &'a str, y: &'b str); } @@ -2121,7 +2117,7 @@ fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok! implementing an unsafe trait. Removing the `unsafe` keyword from the inherent implementation will resolve this error. -```compile_fail +```compile_fail,E0197 struct Foo; // this will cause this error @@ -2168,7 +2164,7 @@ impl !Enterprise for Foo { } implementation for a safe trait unsafe will cause a compiler error. Removing the unsafe marker on the trait noted in the error will resolve this problem. -```compile_fail +```compile_fail,E0199 struct Foo; trait Bar { } @@ -2185,7 +2181,7 @@ impl Bar for Foo { } implementation for an unsafe trait isn't marked as unsafe. This may be resolved by marking the unsafe implementation as unsafe. -```compile_fail +```compile_fail,E0200 struct Foo; unsafe trait Bar { } @@ -2203,7 +2199,7 @@ unsafe impl Bar for Foo { } For example: -```compile_fail +```compile_fail,E0201 struct Foo(u8); impl Foo { @@ -2258,7 +2254,7 @@ fn bar(&self) -> bool { self.0 } fields does not implement `Copy`. To fix this, you must implement `Copy` for the mentioned field. Note that this may not be possible, as in the example of -```compile_fail +```compile_fail,E0204 struct Foo { foo : Vec, } @@ -2270,7 +2266,7 @@ impl Copy for Foo { } Here's another example that will fail: -```compile_fail +```compile_fail,E0204 #[derive(Copy)] struct Foo<'a> { ty: &'a mut bool, @@ -2286,7 +2282,7 @@ struct Foo<'a> { variants does not implement `Copy`. To fix this, you must implement `Copy` for the mentioned variant. Note that this may not be possible, as in the example of -```compile_fail +```compile_fail,E0205 enum Foo { Bar(Vec), Baz, @@ -2299,11 +2295,11 @@ impl Copy for Foo { } Here's another example that will fail: -```compile_fail +```compile_fail,E0205 #[derive(Copy)] enum Foo<'a> { Bar(&'a mut bool), - Baz + Baz, } ``` @@ -2316,7 +2312,7 @@ enum Foo<'a> { examples will fail, because neither `i32` (primitive type) nor `&'static Bar` (reference to `Bar`) is a struct or enum: -```compile_fail +```compile_fail,E0206 type Foo = i32; impl Copy for Foo { } // error @@ -2339,7 +2335,7 @@ impl Copy for &'static Bar { } // error Suppose we have a struct `Foo` and we would like to define some methods for it. The following definition leads to a compiler error: -```compile_fail +```compile_fail,E0207 struct Foo; impl Foo { @@ -2372,7 +2368,7 @@ fn get(&self) -> T { As another example, suppose we have a `Maker` trait and want to establish a type `FooMaker` that makes `Foo`s: -```compile_fail +```compile_fail,E0207 trait Maker { type Item; fn make(&mut self) -> Self::Item; @@ -2468,11 +2464,11 @@ fn make(&mut self) -> Foo { If `ForeignTrait` is a trait defined in some external crate `foo`, then the following trait `impl` is an error: -```compile_fail -extern crate foo; -use foo::ForeignTrait; +```compile_fail,E0210 +extern crate collections; +use collections::range::RangeArgument; -impl ForeignTrait for T { } // error +impl RangeArgument for T { } // error ``` To work around this, it can be covered with a local type, `MyType`: @@ -2611,7 +2607,7 @@ fn x(self: Box) {} // ok! A generic type was described using parentheses rather than angle brackets. For example: -```compile_fail +```compile_fail,E0214 fn main() { let v: Vec(&str) = vec!["foo"]; } @@ -2626,7 +2622,7 @@ fn main() { You used an associated type which isn't defined in the trait. Erroneous code example: -```compile_fail +```compile_fail,E0220 trait T1 { type Bar; } @@ -2670,7 +2666,7 @@ trait T2 { An attempt was made to retrieve an associated type, but the type was ambiguous. For example: -```compile_fail +```compile_fail,E0221 trait T1 {} trait T2 {} @@ -2716,7 +2712,7 @@ fn do_something() { An attempt was made to retrieve an associated type, but the type was ambiguous. For example: -```compile_fail +```compile_fail,E0223 trait MyTrait {type X; } fn main() { @@ -2751,7 +2747,7 @@ fn main() { You attempted to use multiple types as bounds for a closure or trait object. Rust does not currently support this. A simple example that causes this error: -```compile_fail +```compile_fail,E0225 fn main() { let _: Box; } @@ -2771,7 +2767,7 @@ fn main() { E0232: r##" The attribute must have a value. Erroneous code example: -```compile_fail +```compile_fail,E0232 #![feature(on_unimplemented)] #[rustc_on_unimplemented] // error: this attribute must have a value @@ -2795,7 +2791,7 @@ trait Bar {} For example, the `Foo` struct below is defined to be generic in `T`, but the type parameter is missing in the definition of `Bar`: -```compile_fail +```compile_fail,E0243 struct Foo { x: T } struct Bar { x: Foo } @@ -2809,7 +2805,7 @@ struct Bar { x: Foo } For example, the `Foo` struct below has no type parameters, but is supplied with two in the definition of `Bar`: -```compile_fail +```compile_fail,E0244 struct Foo { x: bool } struct Bar { x: Foo } @@ -2820,7 +2816,7 @@ struct Bar { x: Foo } This error indicates an attempt to use a value where a type is expected. For example: -```compile_fail +```compile_fail,E0248 enum Foo { Bar(u32) } @@ -2845,14 +2841,14 @@ fn do_something(x: Foo::Bar) { } A cross-crate opt-out trait was implemented on something which wasn't a struct or enum type. Erroneous code example: -```compile_fail +```compile_fail,E0321 #![feature(optin_builtin_traits)] struct Foo; impl !Sync for Foo {} -unsafe impl Send for &'static Foo { +unsafe impl Send for &'static Foo {} // error: cross-crate traits with a default impl, like `core::marker::Send`, // can only be implemented for a struct/enum type, not // `&'static Foo` @@ -2874,7 +2870,7 @@ unsafe impl Send for &'static Foo { An associated const was implemented when another trait item was expected. Erroneous code example: -```compile_fail +```compile_fail,E0323 #![feature(associated_consts)] trait Foo { @@ -2926,7 +2922,9 @@ impl Foo for Bar { A method was implemented when another trait item was expected. Erroneous code example: -```compile_fail +```compile_fail,E0324 +#![feature(associated_consts)] + struct Bar; trait Foo { @@ -2968,7 +2966,9 @@ fn M() {} // ok! An associated type was implemented when another trait item was expected. Erroneous code example: -```compile_fail +```compile_fail,E0325 +#![feature(associated_consts)] + struct Bar; trait Foo { @@ -3020,7 +3020,9 @@ impl Foo for Bar { Here's an example of this error: -```compile_fail +```compile_fail,E0326 +#![feature(associated_consts)] + trait Foo { const BAR: bool; } @@ -3078,7 +3080,7 @@ fn get_bar_good() -> f64 { An attempt was made to implement `Drop` on a concrete specialization of a generic type. An example is shown below: -```compile_fail +```compile_fail,E0366 struct Foo { t: T } @@ -3111,7 +3113,7 @@ fn drop(&mut self) {} An attempt was made to implement `Drop` on a specialization of a generic type. An example is shown below: -```compile_fail +```compile_fail,E0367 trait Foo{} struct MyStruct { @@ -3149,7 +3151,7 @@ fn drop(&mut self) {} This error indicates that a binary assignment operator like `+=` or `^=` was applied to a type that doesn't support it. For example: -```compile_fail +```compile_fail,E0368 let mut x = 12f32; // error: binary operation `<<` cannot be applied to // type `f32` @@ -3172,7 +3174,7 @@ fn drop(&mut self) {} operator for some type `Foo` by implementing the `std::ops::Add` trait for `Foo`, but you find that using `+=` does not work, as in this example: -```compile_fail +```compile_fail,E0368 use std::ops::Add; struct Foo(u32); @@ -3199,7 +3201,7 @@ fn main() { A binary operation was attempted on a type which doesn't support it. Erroneous code example: -```compile_fail +```compile_fail,E0369 let x = 12f32; // error: binary operation `<<` cannot be applied to // type `f32` @@ -3224,7 +3226,7 @@ fn main() { The maximum value of an enum was reached, so it cannot be automatically set in the next enum value. Erroneous code example: -```compile_fail +```compile_fail,E0370 #[deny(overflowing_literals)] enum Foo { X = 0x7fffffffffffffff, @@ -3262,7 +3264,7 @@ enum Foo { Example: -```compile_fail +```compile_fail,E0371 trait Foo { fn foo(&self) { } } trait Bar: Foo { } trait Baz: Bar { } @@ -3283,7 +3285,7 @@ impl Baz for Bar { } // Note: This is OK Example of erroneous code: -```compile_fail +```compile_fail,E0374 #![feature(coerce_unsized)] use std::ops::CoerceUnsized; @@ -3342,7 +3344,7 @@ impl `CoerceUnsized` from `T` to `U` which are both types that the struct Example of erroneous code: -```compile_fail +```compile_fail,E0375 #![feature(coerce_unsized)] use std::ops::CoerceUnsized; @@ -3397,7 +3399,7 @@ fn coerce_foo, U>(t: T) -> Foo { Example of erroneous code: -```compile_fail +```compile_fail,E0376 #![feature(coerce_unsized)] use std::ops::CoerceUnsized; @@ -3448,7 +3450,7 @@ impl CoerceUnsized> for Foo where T: CoerceUnsized {} E0390: r##" You tried to implement methods for a primitive type. Erroneous code example: -```compile_fail +```compile_fail,E0390 struct Foo { x: i32 } @@ -3482,7 +3484,7 @@ fn bar() {} // ok! The following example contains a circular dependency between two traits: -```compile_fail +```compile_fail,E0391 trait FirstTrait : SecondTrait { } @@ -3497,9 +3499,9 @@ trait SecondTrait : FirstTrait { This error indicates that a type or lifetime parameter has been declared but not actually used. Here is an example that demonstrates the error: -```compile_fail +```compile_fail,E0392 enum Foo { - Bar + Bar, } ``` @@ -3508,7 +3510,7 @@ enum Foo { ``` enum Foo { - Bar + Bar, } ``` @@ -3517,7 +3519,7 @@ enum Foo { ``` enum Foo { - Bar(T) + Bar(T), } ``` @@ -3526,9 +3528,9 @@ enum Foo { which the pointed-at data is valid. An initial attempt (below) causes this error: -```compile_fail +```compile_fail,E0392 struct Foo<'a, T> { - x: *const T + x: *const T, } ``` @@ -3557,7 +3559,7 @@ struct Foo<'a, T: 'a> { A type parameter which references `Self` in its default value was not specified. Example of erroneous code: -```compile_fail +```compile_fail,E0393 trait A {} fn together_we_will_rule_the_galaxy(son: &A) {} @@ -3588,7 +3590,7 @@ fn together_we_will_rule_the_galaxy(son: &A) {} // Ok! The length of the platform-intrinsic function `simd_shuffle` wasn't specified. Erroneous code example: -```compile_fail +```compile_fail,E0439 #![feature(platform_intrinsics)] extern "platform-intrinsic" { @@ -3613,7 +3615,7 @@ fn together_we_will_rule_the_galaxy(son: &A) {} // Ok! A platform-specific intrinsic function has the wrong number of type parameters. Erroneous code example: -```compile_fail +```compile_fail,E0440 #![feature(repr_simd)] #![feature(platform_intrinsics)] @@ -3647,7 +3649,7 @@ fn together_we_will_rule_the_galaxy(son: &A) {} // Ok! An unknown platform-specific intrinsic function was used. Erroneous code example: -```compile_fail +```compile_fail,E0441 #![feature(repr_simd)] #![feature(platform_intrinsics)] @@ -3681,7 +3683,7 @@ fn together_we_will_rule_the_galaxy(son: &A) {} // Ok! Intrinsic argument(s) and/or return value have the wrong type. Erroneous code example: -```compile_fail +```compile_fail,E0442 #![feature(repr_simd)] #![feature(platform_intrinsics)] @@ -3719,7 +3721,7 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8, Intrinsic argument(s) and/or return value have the wrong type. Erroneous code example: -```compile_fail +```compile_fail,E0443 #![feature(repr_simd)] #![feature(platform_intrinsics)] @@ -3754,7 +3756,7 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8, A platform-specific intrinsic function has wrong number of arguments. Erroneous code example: -```compile_fail +```compile_fail,E0444 #![feature(repr_simd)] #![feature(platform_intrinsics)] @@ -3787,7 +3789,7 @@ struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8, The `typeof` keyword is currently reserved but unimplemented. Erroneous code example: -```compile_fail +```compile_fail,E0516 fn main() { let x: typeof(92) = 92; } @@ -3806,7 +3808,7 @@ fn main() { A non-default implementation was already made on this type so it cannot be specialized further. Erroneous code example: -```compile_fail +```compile_fail,E0520 #![feature(specialization)] trait SpaceLlama { From 574fbbf92cd07006e2aa588ded23fc0ee5d04384 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 6 Aug 2016 19:52:21 +0200 Subject: [PATCH 3/5] Add E0388 error explanation --- src/librustc_borrowck/diagnostics.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 400ae186010e..f1792c7f6f5a 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -286,6 +286,30 @@ fn mutable() { https://doc.rust-lang.org/std/cell/ "##, +E0388: r##" +A mutable borrow was attempted in a static location. + +Erroneous code example: + +```compile_fail,E0388 +static X: i32 = 1; + +static STATIC_REF: &'static mut i32 = &mut X; +// error: cannot borrow data mutably in a static location + +const CONST_REF: &'static mut i32 = &mut X; +// error: cannot borrow data mutably in a static location +``` + +To fix this error, you have to use constant borrow: + +``` +static X: i32 = 1; + +static STATIC_REF: &'static i32 = &X; +``` +"##, + E0389: r##" An attempt was made to mutate data using a non-mutable reference. This commonly occurs when attempting to assign to a non-mutable reference of a @@ -1113,6 +1137,5 @@ fn main() { register_diagnostics! { E0385, // {} in an aliasable location - E0388, // {} in a static location E0524, // two closures require unique access to `..` at the same time } From 4da9bdc563598739100e4d73ef6e0803626311a7 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 6 Aug 2016 21:24:16 +0200 Subject: [PATCH 4/5] Update librustc_borrowck error codes check --- src/librustc_borrowck/diagnostics.rs | 219 ++++++++++++++------------- src/librustc_typeck/diagnostics.rs | 4 +- 2 files changed, 113 insertions(+), 110 deletions(-) diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index f1792c7f6f5a..88f739d1c74b 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -17,7 +17,7 @@ when that data may no longer exist. It's most commonly seen when attempting to return a closure: -```compile_fail +```compile_fail,E0373 fn foo() -> Box u32> { let x = 0u32; Box::new(|y| x + y) @@ -31,7 +31,7 @@ fn foo() -> Box u32> { Another situation where this might be encountered is when spawning threads: -```compile_fail +```compile_fail,E0373 fn foo() { let x = 0u32; let y = 1u32; @@ -66,7 +66,7 @@ fn foo() -> Box u32> { E0381: r##" It is not allowed to use or capture an uninitialized variable. For example: -```compile_fail +```compile_fail,E0381 fn main() { let x: i32; let y = x; // error, use of possibly uninitialized variable @@ -88,7 +88,7 @@ fn main() { This error occurs when an attempt is made to use a variable after its contents have been moved elsewhere. For example: -```compile_fail +```compile_fail,E0382 struct MyStruct { s: u32 } fn main() { @@ -180,8 +180,8 @@ struct Foo { This error occurs when an attempt is made to reassign an immutable variable. For example: -```compile_fail -fn main(){ +```compile_fail,E0384 +fn main() { let x = 3; x = 5; // error, reassignment of immutable variable } @@ -191,7 +191,7 @@ fn main(){ `mut` after the keyword `let` when declaring the variable. For example: ``` -fn main(){ +fn main() { let mut x = 3; x = 5; } @@ -204,7 +204,7 @@ fn main(){ For example, this can happen when storing a `&mut` inside an immutable `Box`: -```compile_fail +```compile_fail,E0386 let mut x: i64 = 1; let y: Box<_> = Box::new(&mut x); **y = 2; // error, cannot assign to data in an immutable container @@ -234,7 +234,7 @@ fn main(){ This error occurs when an attempt is made to mutate or mutably reference data that a closure has captured immutably. Examples of this error are shown below: -```compile_fail +```compile_fail,E0387 // Accepts a function or a closure that captures its environment immutably. // Closures passed to foo will not be able to mutate their closed-over state. fn foo(f: F) { } @@ -317,9 +317,9 @@ fn mutable() { Example of erroneous code: -```compile_fail +```compile_fail,E0389 struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -339,7 +339,7 @@ fn main() { ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -377,7 +377,7 @@ fn main() { E0499: r##" A variable was borrowed as mutable more than once. Erroneous code example: -```compile_fail +```compile_fail,E0499 let mut i = 0; let mut x = &mut i; let mut a = &mut i; @@ -462,7 +462,7 @@ fn you_know_nothing(jon_snow: &mut i32) { Example of erroneous code: -```compile_fail +```compile_fail,E0501 fn inside_closure(x: &mut i32) { // Actions which require unique access } @@ -532,7 +532,7 @@ fn foo(a: &mut i32) { Example of erroneous code: -```compile_fail +```compile_fail,E0502 fn bar(x: &mut i32) {} fn foo(a: &mut i32) { let ref y = a; // a is borrowed as immutable. @@ -561,7 +561,7 @@ fn foo(a: &mut i32) { Example of erroneous code: -```compile_fail +```compile_fail,E0503 fn main() { let mut value = 3; // Create a mutable borrow of `value`. This borrow @@ -618,9 +618,9 @@ fn main() { Example of erroneous code: -```compile_fail +```compile_fail,E0504 struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -646,7 +646,7 @@ fn main() { ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -669,7 +669,7 @@ fn main() { ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -698,7 +698,7 @@ fn main() { use std::thread; struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -716,95 +716,12 @@ fn main() { ``` "##, -E0506: r##" -This error occurs when an attempt is made to assign to a borrowed value. - -Example of erroneous code: - -```compile_fail -struct FancyNum { - num: u8 -} - -fn main() { - let mut fancy_num = FancyNum { num: 5 }; - let fancy_ref = &fancy_num; - fancy_num = FancyNum { num: 6 }; - // error: cannot assign to `fancy_num` because it is borrowed - - println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num); -} -``` - -Because `fancy_ref` still holds a reference to `fancy_num`, `fancy_num` can't -be assigned to a new value as it would invalidate the reference. - -Alternatively, we can move out of `fancy_num` into a second `fancy_num`: - -``` -struct FancyNum { - num: u8 -} - -fn main() { - let mut fancy_num = FancyNum { num: 5 }; - let moved_num = fancy_num; - fancy_num = FancyNum { num: 6 }; - - println!("Num: {}, Moved num: {}", fancy_num.num, moved_num.num); -} -``` - -If the value has to be borrowed, try limiting the lifetime of the borrow using -a scoped block: - -``` -struct FancyNum { - num: u8 -} - -fn main() { - let mut fancy_num = FancyNum { num: 5 }; - - { - let fancy_ref = &fancy_num; - println!("Ref: {}", fancy_ref.num); - } - - // Works because `fancy_ref` is no longer in scope - fancy_num = FancyNum { num: 6 }; - println!("Num: {}", fancy_num.num); -} -``` - -Or by moving the reference into a function: - -``` -struct FancyNum { - num: u8 -} - -fn main() { - let mut fancy_num = FancyNum { num: 5 }; - - print_fancy_ref(&fancy_num); - - // Works because function borrow has ended - fancy_num = FancyNum { num: 6 }; - println!("Num: {}", fancy_num.num); -} - -fn print_fancy_ref(fancy_ref: &FancyNum){ - println!("Ref: {}", fancy_ref.num); -} -``` -"##, - E0505: r##" A value was moved out while it was still borrowed. + Erroneous code example: -```compile_fail +```compile_fail,E0505 struct Value {} fn eat(val: Value) {} @@ -879,10 +796,94 @@ fn main() { http://doc.rust-lang.org/stable/book/references-and-borrowing.html "##, +E0506: r##" +This error occurs when an attempt is made to assign to a borrowed value. + +Example of erroneous code: + +```compile_fail,E0506 +struct FancyNum { + num: u8, +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + let fancy_ref = &fancy_num; + fancy_num = FancyNum { num: 6 }; + // error: cannot assign to `fancy_num` because it is borrowed + + println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num); +} +``` + +Because `fancy_ref` still holds a reference to `fancy_num`, `fancy_num` can't +be assigned to a new value as it would invalidate the reference. + +Alternatively, we can move out of `fancy_num` into a second `fancy_num`: + +``` +struct FancyNum { + num: u8, +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + let moved_num = fancy_num; + fancy_num = FancyNum { num: 6 }; + + println!("Num: {}, Moved num: {}", fancy_num.num, moved_num.num); +} +``` + +If the value has to be borrowed, try limiting the lifetime of the borrow using +a scoped block: + +``` +struct FancyNum { + num: u8, +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + + { + let fancy_ref = &fancy_num; + println!("Ref: {}", fancy_ref.num); + } + + // Works because `fancy_ref` is no longer in scope + fancy_num = FancyNum { num: 6 }; + println!("Num: {}", fancy_num.num); +} +``` + +Or by moving the reference into a function: + +``` +struct FancyNum { + num: u8, +} + +fn main() { + let mut fancy_num = FancyNum { num: 5 }; + + print_fancy_ref(&fancy_num); + + // Works because function borrow has ended + fancy_num = FancyNum { num: 6 }; + println!("Num: {}", fancy_num.num); +} + +fn print_fancy_ref(fancy_ref: &FancyNum){ + println!("Ref: {}", fancy_ref.num); +} +``` +"##, + E0507: r##" You tried to move out of a value which was borrowed. Erroneous code example: -```compile_fail +```compile_fail,E0507 use std::cell::RefCell; struct TheDarkKnight; @@ -999,7 +1000,7 @@ fn main() { Example of erroneous code: -```compile_fail +```compile_fail,E0508 struct NonCopy; fn main() { @@ -1044,7 +1045,7 @@ fn main() { Example of erroneous code: -```compile_fail +```compile_fail,E0509 struct FancyNum { num: usize } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index db11b9041f57..5956d35d84aa 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2469,6 +2469,8 @@ fn make(&mut self) -> Foo { use collections::range::RangeArgument; impl RangeArgument for T { } // error + +fn main() {} ``` To work around this, it can be covered with a local type, `MyType`: @@ -3226,7 +3228,7 @@ fn main() { The maximum value of an enum was reached, so it cannot be automatically set in the next enum value. Erroneous code example: -```compile_fail,E0370 +```compile_fail #[deny(overflowing_literals)] enum Foo { X = 0x7fffffffffffffff, From 0658941cd245696068bf299184c9bc9de3d5b887 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 6 Aug 2016 21:44:49 +0200 Subject: [PATCH 5/5] Add new error code tests --- src/test/compile-fail/E0365.rs | 17 +++++++++++++++++ src/test/compile-fail/E0370.rs | 20 ++++++++++++++++++++ src/test/compile-fail/E0374.rs | 21 +++++++++++++++++++++ src/test/compile-fail/E0375.rs | 22 ++++++++++++++++++++++ src/test/compile-fail/E0376.rs | 20 ++++++++++++++++++++ src/test/compile-fail/E0388.rs | 22 ++++++++++++++++++++++ src/test/compile-fail/E0389.rs | 20 ++++++++++++++++++++ src/test/compile-fail/E0390.rs | 18 ++++++++++++++++++ src/test/compile-fail/E0392.rs | 14 ++++++++++++++ src/test/compile-fail/E0393.rs | 16 ++++++++++++++++ 10 files changed, 190 insertions(+) create mode 100644 src/test/compile-fail/E0365.rs create mode 100644 src/test/compile-fail/E0370.rs create mode 100644 src/test/compile-fail/E0374.rs create mode 100644 src/test/compile-fail/E0375.rs create mode 100644 src/test/compile-fail/E0376.rs create mode 100644 src/test/compile-fail/E0388.rs create mode 100644 src/test/compile-fail/E0389.rs create mode 100644 src/test/compile-fail/E0390.rs create mode 100644 src/test/compile-fail/E0392.rs create mode 100644 src/test/compile-fail/E0393.rs diff --git a/src/test/compile-fail/E0365.rs b/src/test/compile-fail/E0365.rs new file mode 100644 index 000000000000..7b0fbcc6203d --- /dev/null +++ b/src/test/compile-fail/E0365.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. + +mod foo { + pub const X: u32 = 1; +} + +pub use foo as foo2; //~ ERROR E0365 + +fn main() {} diff --git a/src/test/compile-fail/E0370.rs b/src/test/compile-fail/E0370.rs new file mode 100644 index 000000000000..cafe26c65ada --- /dev/null +++ b/src/test/compile-fail/E0370.rs @@ -0,0 +1,20 @@ +// 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. + +#![allow(dead_code)] + +#[deny(overflowing_literals)] +#[repr(i64)] +enum Foo { + X = 0x7fffffffffffffff, + Y, //~ ERROR E0370 +} + +fn main() {} diff --git a/src/test/compile-fail/E0374.rs b/src/test/compile-fail/E0374.rs new file mode 100644 index 000000000000..6c4782d230dd --- /dev/null +++ b/src/test/compile-fail/E0374.rs @@ -0,0 +1,21 @@ +// 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. + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo { + a: i32, +} + +impl CoerceUnsized> for Foo //~ ERROR E0374 + where T: CoerceUnsized {} + +fn main() {} diff --git a/src/test/compile-fail/E0375.rs b/src/test/compile-fail/E0375.rs new file mode 100644 index 000000000000..c6db7b8b64e6 --- /dev/null +++ b/src/test/compile-fail/E0375.rs @@ -0,0 +1,22 @@ +// 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. + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo { + a: i32, + b: T, + c: U, +} + +impl CoerceUnsized> for Foo {} //~ ERROR E0375 + +fn main() {} diff --git a/src/test/compile-fail/E0376.rs b/src/test/compile-fail/E0376.rs new file mode 100644 index 000000000000..65be358cc5fe --- /dev/null +++ b/src/test/compile-fail/E0376.rs @@ -0,0 +1,20 @@ +// 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. + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo { + a: T, +} + +impl CoerceUnsized for Foo {} //~ ERROR E0376 + +fn main() {} diff --git a/src/test/compile-fail/E0388.rs b/src/test/compile-fail/E0388.rs new file mode 100644 index 000000000000..13f2c23d8c4a --- /dev/null +++ b/src/test/compile-fail/E0388.rs @@ -0,0 +1,22 @@ +// 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 X: i32 = 1; +const C: i32 = 2; + +const CR: &'static mut i32 = &mut C; //~ ERROR E0017 + //~| ERROR E0017 +static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017 + //~| ERROR E0017 + //~| ERROR E0388 +static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017 + //~| ERROR E0017 + +fn main() {} diff --git a/src/test/compile-fail/E0389.rs b/src/test/compile-fail/E0389.rs new file mode 100644 index 000000000000..445831bf8d7f --- /dev/null +++ b/src/test/compile-fail/E0389.rs @@ -0,0 +1,20 @@ +// 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 FancyNum { + num: u8, +} + +fn main() { + let mut fancy = FancyNum{ num: 5 }; + let fancy_ref = &(&mut fancy); + fancy_ref.num = 6; //~ ERROR E0389 + println!("{}", fancy_ref.num); +} diff --git a/src/test/compile-fail/E0390.rs b/src/test/compile-fail/E0390.rs new file mode 100644 index 000000000000..cd530dbd6b46 --- /dev/null +++ b/src/test/compile-fail/E0390.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. + +struct Foo { + x: i32 +} + +impl *mut Foo {} //~ ERROR E0390 + +fn main() { +} diff --git a/src/test/compile-fail/E0392.rs b/src/test/compile-fail/E0392.rs new file mode 100644 index 000000000000..4c3efcf4e8d7 --- /dev/null +++ b/src/test/compile-fail/E0392.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. + +enum Foo { Bar } //~ ERROR E0392 + +fn main() { +} diff --git a/src/test/compile-fail/E0393.rs b/src/test/compile-fail/E0393.rs new file mode 100644 index 000000000000..1b89555c8ced --- /dev/null +++ b/src/test/compile-fail/E0393.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. + +trait A {} + +fn together_we_will_rule_the_galaxy(son: &A) {} //~ ERROR E0393 + +fn main() { +}