From a1e240ccec087c64d0adf27d9c4cc96ab104d551 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:45:15 +0200 Subject: [PATCH 1/4] Improve E0137 error explanatIon --- src/librustc/diagnostics.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index c64f0ddac50d0..56d57d39be6e2 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -392,9 +392,30 @@ function `main()`. If there are multiple such functions, please rename one. "##, E0137: r##" +More than one function was declared with the `#[main]` attribute. + +Erroneous code example: + +```compile_fail +#![feature(main)] + +#[main] +fn foo() {} + +#[main] +fn f() {} // error: multiple functions with a #[main] attribute +``` + This error indicates that the compiler found multiple functions with the `#[main]` attribute. This is an error because there must be a unique entry -point into a Rust program. +point into a Rust program. Example: + +``` +#![feature(main)] + +#[main] +fn f() {} // ok! +``` "##, E0138: r##" From 360d7234c7ce1392c2730fba2e7d9b33f3ff9e5f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:47:59 +0200 Subject: [PATCH 2/4] Improve E0138 error explanation --- src/librustc/diagnostics.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 56d57d39be6e2..7c350987aa1e8 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -419,9 +419,32 @@ fn f() {} // ok! "##, E0138: r##" +More than one function was declared with the `#[start]` attribute. + +Erroneous code example: + +```compile_fail +#![feature(start)] + +#[start] +fn foo(argc: isize, argv: *const *const u8) -> isize {} + +#[start] +fn f(argc: isize, argv: *const *const u8) -> isize {} +// error: multiple 'start' functions +``` + This error indicates that the compiler found multiple functions with the `#[start]` attribute. This is an error because there must be a unique entry -point into a Rust program. +point into a Rust program. Example: + + +``` +#![feature(start)] + +#[start] +fn foo(argc: isize, argv: *const *const u8) -> isize {} // ok! +``` "##, // FIXME link this to the relevant turpl chapters for instilling fear of the From 4fa84830f8a91a2a8db988afec96b416ae2654c0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 21:57:06 +0200 Subject: [PATCH 3/4] improve E0152 error explanation --- src/librustc/diagnostics.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 7c350987aa1e8..a410a5949bdc8 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -525,6 +525,17 @@ call to `mem::forget(v)` in case you want to avoid destructors being called. "##, E0152: r##" +A lang item was redefined. + +Erroneous code example: + +```compile_fail +#![feature(lang_items)] + +#[lang = "panic_fmt"] +struct Foo; // error: duplicate lang item found: `panic_fmt` +``` + Lang items are already implemented in the standard library. Unless you are writing a free-standing application (e.g. a kernel), you do not need to provide them yourself. From 31b9060ede89c7c11d7d829c3d4b50649bb7f07e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 27 May 2016 22:05:10 +0200 Subject: [PATCH 4/4] Improve E0161 error explanation --- src/librustc/diagnostics.rs | 3 +-- src/librustc_passes/diagnostics.rs | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index a410a5949bdc8..d838de4a33122 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -438,12 +438,11 @@ This error indicates that the compiler found multiple functions with the `#[start]` attribute. This is an error because there must be a unique entry point into a Rust program. Example: - ``` #![feature(start)] #[start] -fn foo(argc: isize, argv: *const *const u8) -> isize {} // ok! +fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok! ``` "##, diff --git a/src/librustc_passes/diagnostics.rs b/src/librustc_passes/diagnostics.rs index 77f896e011b93..cba8bd73c014e 100644 --- a/src/librustc_passes/diagnostics.rs +++ b/src/librustc_passes/diagnostics.rs @@ -50,11 +50,36 @@ match 5u32 { "##, E0161: r##" +A value was moved. However, its size was not known at compile time, and only +values of a known size can be moved. + +Erroneous code example: + +```compile_fail +#![feature(box_syntax)] + +fn main() { + let array: &[isize] = &[1, 2, 3]; + let _x: Box<[isize]> = box *array; + // error: cannot move a value of type [isize]: the size of [isize] cannot + // be statically determined +} +``` + In Rust, you can only move a value when its size is known at compile time. To work around this restriction, consider "hiding" the value behind a reference: either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move -it around as usual. +it around as usual. Example: + +``` +#![feature(box_syntax)] + +fn main() { + let array: &[isize] = &[1, 2, 3]; + let _x: Box<&[isize]> = box array; // ok! +} +``` "##, E0265: r##"