diff options
| author | bors <bors@rust-lang.org> | 2016-08-12 08:58:55 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-12 08:58:55 -0700 |
| commit | 1deb02ea69a7ca3fd8011a45bb75ff22c3f7579a (patch) | |
| tree | e83057e10546babbb7dc4c80ce5d656b25023b83 /src | |
| parent | f55ac6944a88d4da62b30a16cc95893ca050c328 (diff) | |
| parent | 0658941cd245696068bf299184c9bc9de3d5b887 (diff) | |
| download | rust-1deb02ea69a7ca3fd8011a45bb75ff22c3f7579a.tar.gz rust-1deb02ea69a7ca3fd8011a45bb75ff22c3f7579a.zip | |
Auto merge of #35431 - GuillaumeGomez:err_codes, r=jonathandturner
Err codes r? @jonathandturner
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/diagnostics.rs | 33 | ||||
| -rw-r--r-- | src/librustc_borrowck/diagnostics.rs | 242 | ||||
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 310 | ||||
| -rw-r--r-- | src/test/compile-fail/E0365.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/E0370.rs | 20 | ||||
| -rw-r--r-- | src/test/compile-fail/E0374.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/E0375.rs | 22 | ||||
| -rw-r--r-- | src/test/compile-fail/E0376.rs | 20 | ||||
| -rw-r--r-- | src/test/compile-fail/E0388.rs | 22 | ||||
| -rw-r--r-- | src/test/compile-fail/E0389.rs | 20 | ||||
| -rw-r--r-- | src/test/compile-fail/E0390.rs | 18 | ||||
| -rw-r--r-- | src/test/compile-fail/E0392.rs | 14 | ||||
| -rw-r--r-- | src/test/compile-fail/E0393.rs | 16 |
13 files changed, 512 insertions, 263 deletions
diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 74e2c90503c..07e54dc9e87 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1399,6 +1399,38 @@ struct Foo<T: 'static> { ``` "##, +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 @@ register_diagnostics! { // 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 diff --git a/src/librustc_borrowck/diagnostics.rs b/src/librustc_borrowck/diagnostics.rs index 400ae186010..88f739d1c74 100644 --- a/src/librustc_borrowck/diagnostics.rs +++ b/src/librustc_borrowck/diagnostics.rs @@ -17,7 +17,7 @@ This error occurs when an attempt is made to use data captured by a closure, 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<Fn(u32) -> u32> { let x = 0u32; Box::new(|y| x + y) @@ -31,7 +31,7 @@ unsafe. 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 @@ about safety. 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 @@ E0382: r##" 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 @@ E0384: r##" 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 @@ By default, variables in Rust are immutable. To fix this error, add the keyword `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 @@ reference stored inside an immutable container. 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 @@ E0387: r##" 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: Fn()>(f: F) { } @@ -286,6 +286,30 @@ You can read more about cell types in the API documentation: 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 @@ -293,9 +317,9 @@ mutable reference (`&(&mut T)`). Example of erroneous code: -```compile_fail +```compile_fail,E0389 struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -315,7 +339,7 @@ To fix this, either remove the outer reference: ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -353,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; @@ -438,7 +462,7 @@ capturing. Example of erroneous code: -```compile_fail +```compile_fail,E0501 fn inside_closure(x: &mut i32) { // Actions which require unique access } @@ -508,7 +532,7 @@ has already been borrowed as immutable. 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. @@ -537,7 +561,7 @@ A value was used after it was mutably borrowed. Example of erroneous code: -```compile_fail +```compile_fail,E0503 fn main() { let mut value = 3; // Create a mutable borrow of `value`. This borrow @@ -594,9 +618,9 @@ closure. Example of erroneous code: -```compile_fail +```compile_fail,E0504 struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -622,7 +646,7 @@ rather than moving: ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -645,7 +669,7 @@ the borrow using a scoped block: ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -674,7 +698,7 @@ use std::sync::Arc; use std::thread; struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -692,14 +716,94 @@ fn main() { ``` "##, +E0505: r##" +A value was moved out while it was still borrowed. + +Erroneous code example: + +```compile_fail,E0505 +struct Value {} + +fn eat(val: Value) {} + +fn main() { + let x = Value{}; + { + let _ref_to_val: &Value = &x; + eat(x); + } +} +``` + +Here, the function `eat` takes the ownership of `x`. However, +`x` cannot be moved because it was borrowed to `_ref_to_val`. +To fix that you can do few different things: + +* Try to avoid moving the variable. +* Release borrow before move. +* Implement the `Copy` trait on the type. + +Examples: + +``` +struct Value {} + +fn eat(val: &Value) {} + +fn main() { + let x = Value{}; + { + let _ref_to_val: &Value = &x; + eat(&x); // pass by reference, if it's possible + } +} +``` + +Or: + +``` +struct Value {} + +fn eat(val: Value) {} + +fn main() { + let x = Value{}; + { + let _ref_to_val: &Value = &x; + } + eat(x); // release borrow and then move it. +} +``` + +Or: + +``` +#[derive(Clone, Copy)] // implement Copy trait +struct Value {} + +fn eat(val: Value) {} + +fn main() { + let x = Value{}; + { + let _ref_to_val: &Value = &x; + eat(x); // it will be copied here. + } +} +``` + +You can find more information about borrowing in the rust-book: +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 +```compile_fail,E0506 struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -719,7 +823,7 @@ Alternatively, we can move out of `fancy_num` into a second `fancy_num`: ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -736,7 +840,7 @@ a scoped block: ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -757,7 +861,7 @@ Or by moving the reference into a function: ``` struct FancyNum { - num: u8 + num: u8, } fn main() { @@ -776,89 +880,10 @@ fn print_fancy_ref(fancy_ref: &FancyNum){ ``` "##, -E0505: r##" -A value was moved out while it was still borrowed. -Erroneous code example: - -```compile_fail -struct Value {} - -fn eat(val: Value) {} - -fn main() { - let x = Value{}; - { - let _ref_to_val: &Value = &x; - eat(x); - } -} -``` - -Here, the function `eat` takes the ownership of `x`. However, -`x` cannot be moved because it was borrowed to `_ref_to_val`. -To fix that you can do few different things: - -* Try to avoid moving the variable. -* Release borrow before move. -* Implement the `Copy` trait on the type. - -Examples: - -``` -struct Value {} - -fn eat(val: &Value) {} - -fn main() { - let x = Value{}; - { - let _ref_to_val: &Value = &x; - eat(&x); // pass by reference, if it's possible - } -} -``` - -Or: - -``` -struct Value {} - -fn eat(val: Value) {} - -fn main() { - let x = Value{}; - { - let _ref_to_val: &Value = &x; - } - eat(x); // release borrow and then move it. -} -``` - -Or: - -``` -#[derive(Clone, Copy)] // implement Copy trait -struct Value {} - -fn eat(val: Value) {} - -fn main() { - let x = Value{}; - { - let _ref_to_val: &Value = &x; - eat(x); // it will be copied here. - } -} -``` - -You can find more information about borrowing in the rust-book: -http://doc.rust-lang.org/stable/book/references-and-borrowing.html -"##, - 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; @@ -975,7 +1000,7 @@ A value was moved out of a non-copy fixed-size array. Example of erroneous code: -```compile_fail +```compile_fail,E0508 struct NonCopy; fn main() { @@ -1020,7 +1045,7 @@ implements the `Drop` trait. Example of erroneous code: -```compile_fail +```compile_fail,E0509 struct FancyNum { num: usize } @@ -1113,6 +1138,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 } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 7b78e83b801..ac40708e25c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -43,7 +43,7 @@ match x { 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 @@ E0025: r##" 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 @@ by a different name, you should rename it explicitly. Change this: -```compile_fail +```compile_fail,E0026 struct Thing { x: u32, y: u32 @@ -159,7 +159,7 @@ definition is mentioned in the pattern, or use `..` to ignore unwanted fields. For example: -```compile_fail +```compile_fail,E0027 struct Dog { name: String, age: u32, @@ -201,7 +201,9 @@ compile-time, and is unable to evaluate arbitrary comparison functions. If you 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 @@ E0034: r##" 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 @@ E0035: r##" 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 @@ E0036: r##" 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 @@ out of scope. 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<T>(x: T); } ``` @@ -456,7 +458,9 @@ Rust only supports variadic parameters for interoperability with C code in its 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 @@ extern "C" { 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 @@ has the wrong number of type parameters. 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<T: Default>(x: T) -> Self; } @@ -541,7 +539,7 @@ For example, the trait below has a method `foo` with two function parameters (`&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 @@ and the trait definition. 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 @@ E0054: r##" 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 @@ recursion limit (which can be set via the `recursion_limit` attribute). For a somewhat artificial example: -```compile_fail,ignore +```compile_fail,E0055 #![recursion_limit="2"] struct Foo; @@ -637,7 +635,7 @@ function must match its definition. 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 @@ implemented by closures. 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: Fn<i32>>(f: F) -> F::Output { f(3) } ``` It can be fixed by adjusting the trait bound like this: -```ignore +``` +#![feature(unboxed_closures)] + fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) } ``` @@ -726,9 +728,9 @@ This error indicates that during an attempt to build a struct or struct-like 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 @@ Each field should be specified exactly one time. Example: ``` struct Foo { - x: i32 + x: i32, } fn main() { @@ -756,10 +758,10 @@ E0063: r##" 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 @@ Each field should be specified exactly once. Example: ``` struct Foo { x: i32, - y: i32 + y: i32, } fn main() { @@ -799,7 +801,7 @@ and field references. 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 @@ E0069: r##" 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 @@ https://doc.rust-lang.org/reference.html#lvalues-rvalues-and-temporaries 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 @@ not a struct-style structure or enum variant. 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 @@ operate on. This will cause an error: -```compile_fail +```compile_fail,E0075 #![feature(repr_simd)] #[repr(simd)] @@ -1000,7 +1002,7 @@ will trigger this error. This will cause an error: -```compile_fail +```compile_fail,E0076 #![feature(repr_simd)] #[repr(simd)] @@ -1023,7 +1025,7 @@ must be machine types so SIMD operations can be applied to them. This will cause an error: -```compile_fail +```compile_fail,E0077 #![feature(repr_simd)] #[repr(simd)] @@ -1047,9 +1049,9 @@ literal and is therefore invalid. For example, in the following code: -```compile_fail +```compile_fail,E0079 enum Foo { - Q = "32" + Q = "32", } ``` @@ -1060,7 +1062,7 @@ it to one: ``` enum Foo { - Q = 32 + Q = 32, } ``` @@ -1084,12 +1086,12 @@ Enum discriminants are used to differentiate enum variants stored in memory. 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 @@ Note that variants without a manually specified discriminant are numbered from 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 @@ otherwise this error is raised. For example: #[repr(u8)] enum Thing { A = 1024, - B = 5 + B = 5, } ``` @@ -1137,7 +1139,7 @@ invalid. Here is another, more subtle example which depends on target word size: ```ignore enum DependsOnPointerSize { - A = 1 << 32 + A = 1 << 32, } ``` @@ -1153,7 +1155,7 @@ An unsupported representation was attempted on a zero-variant enum. 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<T>() {} fn main() { @@ -1196,7 +1198,7 @@ parameters. 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<T, U>() {} 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<T, U>(x: T) {} fn main() { @@ -1267,7 +1269,7 @@ E0091: r##" You gave an unnecessary type parameter in a type alias. Erroneous code example: -```compile_fail +```compile_fail,E0091 type Foo<T> = u32; // error: type parameter `T` is unused // or: type Foo<A,B> = Box<A>; // error: type parameter `B` is unused @@ -1285,7 +1287,7 @@ E0092: r##" 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 @@ extern "rust-intrinsic" { 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 @@ E0094: r##" 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 @@ E0101: r##" 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 @@ You have two possibilities to solve this situation: 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 @@ E0102: r##" 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 @@ lifetime elision rules (see below). 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 @@ same as the lifetime on `&self` or `&mut self`. Here are some examples of elision errors: -```compile_fail +```compile_fail,E0106 // error, no input lifetimes fn foo() -> &str { } @@ -1473,7 +1469,7 @@ for a type (like a struct or enum) or trait. 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 @@ You can only define an inherent implementation for a type in the same crate 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<u8> { } // error ``` @@ -1518,7 +1514,7 @@ To fix this problem, you can do either of these things: 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<u8>; 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 @@ E0118: r##" 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 @@ E0119: r##" 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 @@ E0120: r##" 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 @@ placeholders are disallowed by design in item signatures. 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 @@ E0124: r##" 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 @@ E0128: r##" Type parameter defaults can only use parameters that occur before them. Erroneous code example: -```compile_fail +```compile_fail,E0128 struct Foo<T=U, U=()> { field1: T, filed2: U, @@ -1805,7 +1801,7 @@ It is not possible to define `main` with type parameters, or even with function parameters. When `main` is present, it must take no arguments and return `()`. Erroneous code example: -```compile_fail +```compile_fail,E0131 fn main<T>() { // error: main function is not allowed to have type parameters } ``` @@ -1816,7 +1812,7 @@ A function with the `start` attribute was declared with type parameters. Erroneous code example: -```compile_fail +```compile_fail,E0132 #![feature(start)] #[start] @@ -1847,7 +1843,7 @@ E0164: r##" 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 @@ This error means that the compiler found a return expression in a function 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 @@ E0172: r##" 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 @@ to use parentheses. For example: -```compile_fail +```compile_fail,E0178 trait Foo {} struct Bar<'a> { @@ -1949,7 +1945,7 @@ take a `self` parameter). Here's an example of this error: -```compile_fail +```compile_fail,E0185 trait Foo { fn foo(); } @@ -1971,7 +1967,7 @@ to be static. Here's an example of this error: -```compile_fail +```compile_fail,E0186 trait Foo { fn foo(&self); } @@ -1990,7 +1986,7 @@ E0191: r##" 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 @@ E0194: r##" A type parameter was declared which shadows an existing one. An example of this error: -```compile_fail +```compile_fail,E0194 trait Foo<T> { fn do_something(&self) -> T; fn do_something_else<T: Clone>(&self, bar: T); @@ -2082,7 +2078,7 @@ E0195: r##" 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 @@ methods associated with a type) are always safe because they are not 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 @@ Safe traits should not have unsafe implementations, therefore marking an 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 @@ Unsafe traits must have unsafe implementations. This error occurs when an 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 @@ associated functions, etc.) with the same identifier. For example: -```compile_fail +```compile_fail,E0201 struct Foo(u8); impl Foo { @@ -2258,7 +2254,7 @@ An attempt to implement the `Copy` trait for a struct failed because one of the 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<u32>, } @@ -2270,7 +2266,7 @@ This fails because `Vec<T>` does not implement `Copy` for any `T`. 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 @@ An attempt to implement the `Copy` trait for an enum failed because one of the 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<u32>), Baz, @@ -2299,11 +2295,11 @@ This fails because `Vec<T>` does not implement `Copy` for any `T`. 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 @@ You can only implement `Copy` for a struct or enum. Both of the following 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 @@ the following criteria: 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<T: Default> Foo { @@ -2372,7 +2368,7 @@ impl Foo { 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,13 @@ what this means, it is perhaps easiest to consider a few examples. 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<T> RangeArgument<T> for T { } // error -impl<T> ForeignTrait for T { } // error +fn main() {} ``` To work around this, it can be covered with a local type, `MyType`: @@ -2611,7 +2609,7 @@ E0214: r##" 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 +2624,7 @@ E0220: r##" 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 +2668,7 @@ E0221: r##" 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 +2714,7 @@ E0223: r##" 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 +2749,7 @@ E0225: r##" 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<std::io::Read + std::io::Write>; } @@ -2771,7 +2769,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 +2793,7 @@ trait. 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<T> { x: T } struct Bar { x: Foo } @@ -2809,7 +2807,7 @@ trait. 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<S, T> { x: Foo<S, T> } @@ -2820,7 +2818,7 @@ E0248: r##" 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 +2843,14 @@ E0321: r##" 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 +2872,7 @@ E0323: r##" 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 +2924,9 @@ E0324: r##" 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 +2968,9 @@ E0325: r##" 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 +3022,9 @@ types in the trait definition. This error indicates that there was a mismatch. Here's an example of this error: -```compile_fail +```compile_fail,E0326 +#![feature(associated_consts)] + trait Foo { const BAR: bool; } @@ -3078,7 +3082,7 @@ E0366: r##" 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: T } @@ -3111,7 +3115,7 @@ E0367: r##" 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<T> { @@ -3149,7 +3153,7 @@ E0368: r##" 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 +3176,7 @@ Another problem you might be facing is this: suppose you've overloaded the `+` 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 +3203,7 @@ E0369: r##" 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` @@ -3262,7 +3266,7 @@ definition, so it is not useful to do this. Example: -```compile_fail +```compile_fail,E0371 trait Foo { fn foo(&self) { } } trait Bar: Foo { } trait Baz: Bar { } @@ -3283,7 +3287,7 @@ compile time. Any struct containing an unsized type is also unsized. Example of erroneous code: -```compile_fail +```compile_fail,E0374 #![feature(coerce_unsized)] use std::ops::CoerceUnsized; @@ -3342,7 +3346,7 @@ compile time. Any struct containing an unsized type is also unsized. Example of erroneous code: -```compile_fail +```compile_fail,E0375 #![feature(coerce_unsized)] use std::ops::CoerceUnsized; @@ -3397,7 +3401,7 @@ compile time. Any struct containing an unsized type is also unsized. Example of erroneous code: -```compile_fail +```compile_fail,E0376 #![feature(coerce_unsized)] use std::ops::CoerceUnsized; @@ -3448,7 +3452,7 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust 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 +3486,7 @@ and therefore cannot be constructed. The following example contains a circular dependency between two traits: -```compile_fail +```compile_fail,E0391 trait FirstTrait : SecondTrait { } @@ -3497,9 +3501,9 @@ E0392: r##" 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<T> { - Bar + Bar, } ``` @@ -3508,7 +3512,7 @@ by simply removing the type parameter, as shown below: ``` enum Foo { - Bar + Bar, } ``` @@ -3517,7 +3521,7 @@ used. A simple fix is shown below: ``` enum Foo<T> { - Bar(T) + Bar(T), } ``` @@ -3526,9 +3530,9 @@ example, when using raw pointers one may wish to specify the lifetime for 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 +3561,7 @@ E0393: r##" A type parameter which references `Self` in its default value was not specified. Example of erroneous code: -```compile_fail +```compile_fail,E0393 trait A<T=Self> {} fn together_we_will_rule_the_galaxy(son: &A) {} @@ -3588,7 +3592,7 @@ E0439: r##" 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 +3617,7 @@ E0440: r##" 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 +3651,7 @@ E0441: r##" An unknown platform-specific intrinsic function was used. Erroneous code example: -```compile_fail +```compile_fail,E0441 #![feature(repr_simd)] #![feature(platform_intrinsics)] @@ -3681,7 +3685,7 @@ E0442: r##" 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 +3723,7 @@ E0443: r##" 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 +3758,7 @@ E0444: r##" 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 +3791,7 @@ E0516: r##" 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 +3810,7 @@ E0520: r##" 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 { diff --git a/src/test/compile-fail/E0365.rs b/src/test/compile-fail/E0365.rs new file mode 100644 index 00000000000..7b0fbcc6203 --- /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 <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. + +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 00000000000..cafe26c65ad --- /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 <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. + +#![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 00000000000..6c4782d230d --- /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 <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. + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo<T: ?Sized> { + a: i32, +} + +impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> //~ ERROR E0374 + where T: CoerceUnsized<U> {} + +fn main() {} diff --git a/src/test/compile-fail/E0375.rs b/src/test/compile-fail/E0375.rs new file mode 100644 index 00000000000..c6db7b8b64e --- /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 <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. + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo<T: ?Sized, U: ?Sized> { + a: i32, + b: T, + c: U, +} + +impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, U> {} //~ 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 00000000000..65be358cc5f --- /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 <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. + +#![feature(coerce_unsized)] +use std::ops::CoerceUnsized; + +struct Foo<T: ?Sized> { + a: T, +} + +impl<T, U> CoerceUnsized<U> for Foo<T> {} //~ 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 00000000000..13f2c23d8c4 --- /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 <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 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 00000000000..445831bf8d7 --- /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 <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 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 00000000000..cd530dbd6b4 --- /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 <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 { + 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 00000000000..4c3efcf4e8d --- /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 <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. + +enum Foo<T> { 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 00000000000..1b89555c8ce --- /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 <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 A<T=Self> {} + +fn together_we_will_rule_the_galaxy(son: &A) {} //~ ERROR E0393 + +fn main() { +} |
