Skip to content

Commit deb6bc6

Browse files
Rollup merge of #33914 - GuillaumeGomez:improve_err_expl, r=GuillaumeGomez
Improve err expl r? @steveklabnik
2 parents 7475236 + 31b9060 commit deb6bc6

File tree

2 files changed

+82
-3
lines changed

2 files changed

+82
-3
lines changed

src/librustc/diagnostics.rs

+56-2
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,58 @@ function `main()`. If there are multiple such functions, please rename one.
406406
"##,
407407

408408
E0137: r##"
409+
More than one function was declared with the `#[main]` attribute.
410+
411+
Erroneous code example:
412+
413+
```compile_fail
414+
#![feature(main)]
415+
416+
#[main]
417+
fn foo() {}
418+
419+
#[main]
420+
fn f() {} // error: multiple functions with a #[main] attribute
421+
```
422+
409423
This error indicates that the compiler found multiple functions with the
410424
`#[main]` attribute. This is an error because there must be a unique entry
411-
point into a Rust program.
425+
point into a Rust program. Example:
426+
427+
```
428+
#![feature(main)]
429+
430+
#[main]
431+
fn f() {} // ok!
432+
```
412433
"##,
413434

414435
E0138: r##"
436+
More than one function was declared with the `#[start]` attribute.
437+
438+
Erroneous code example:
439+
440+
```compile_fail
441+
#![feature(start)]
442+
443+
#[start]
444+
fn foo(argc: isize, argv: *const *const u8) -> isize {}
445+
446+
#[start]
447+
fn f(argc: isize, argv: *const *const u8) -> isize {}
448+
// error: multiple 'start' functions
449+
```
450+
415451
This error indicates that the compiler found multiple functions with the
416452
`#[start]` attribute. This is an error because there must be a unique entry
417-
point into a Rust program.
453+
point into a Rust program. Example:
454+
455+
```
456+
#![feature(start)]
457+
458+
#[start]
459+
fn foo(argc: isize, argv: *const *const u8) -> isize { 0 } // ok!
460+
```
418461
"##,
419462

420463
// FIXME link this to the relevant turpl chapters for instilling fear of the
@@ -495,6 +538,17 @@ call to `mem::forget(v)` in case you want to avoid destructors being called.
495538
"##,
496539

497540
E0152: r##"
541+
A lang item was redefined.
542+
543+
Erroneous code example:
544+
545+
```compile_fail
546+
#![feature(lang_items)]
547+
548+
#[lang = "panic_fmt"]
549+
struct Foo; // error: duplicate lang item found: `panic_fmt`
550+
```
551+
498552
Lang items are already implemented in the standard library. Unless you are
499553
writing a free-standing application (e.g. a kernel), you do not need to provide
500554
them yourself.

src/librustc_passes/diagnostics.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,36 @@ match 5u32 {
5050
"##,
5151

5252
E0161: r##"
53+
A value was moved. However, its size was not known at compile time, and only
54+
values of a known size can be moved.
55+
56+
Erroneous code example:
57+
58+
```compile_fail
59+
#![feature(box_syntax)]
60+
61+
fn main() {
62+
let array: &[isize] = &[1, 2, 3];
63+
let _x: Box<[isize]> = box *array;
64+
// error: cannot move a value of type [isize]: the size of [isize] cannot
65+
// be statically determined
66+
}
67+
```
68+
5369
In Rust, you can only move a value when its size is known at compile time.
5470
5571
To work around this restriction, consider "hiding" the value behind a reference:
5672
either `&x` or `&mut x`. Since a reference has a fixed size, this lets you move
57-
it around as usual.
73+
it around as usual. Example:
74+
75+
```
76+
#![feature(box_syntax)]
77+
78+
fn main() {
79+
let array: &[isize] = &[1, 2, 3];
80+
let _x: Box<&[isize]> = box array; // ok!
81+
}
82+
```
5883
"##,
5984

6085
E0265: r##"

0 commit comments

Comments
 (0)