Skip to content

Commit e5d90d9

Browse files
committed
Auto merge of #27378 - GuillaumeGomez:patch-2, r=brson
Part of #24407. r? @Manishearth
2 parents 1b5d521 + c3d147e commit e5d90d9

File tree

2 files changed

+220
-10
lines changed

2 files changed

+220
-10
lines changed

src/librustc_resolve/diagnostics.rs

Lines changed: 178 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,114 @@ impl Bar {
397397
```
398398
"##,
399399

400+
E0412: r##"
401+
An undeclared type name was used. Example of erroneous codes:
402+
403+
```
404+
impl Something {} // error: use of undeclared type name `Something`
405+
// or:
406+
trait Foo {
407+
fn bar(N); // error: use of undeclared type name `N`
408+
}
409+
// or:
410+
fn foo(x: T) {} // error: use of undeclared type name `T`
411+
```
412+
413+
To fix this error, please verify you didn't misspell the type name,
414+
you did declare it or imported it into the scope. Examples:
415+
416+
```
417+
struct Something;
418+
419+
impl Something {} // ok!
420+
// or:
421+
trait Foo {
422+
type N;
423+
424+
fn bar(Self::N); // ok!
425+
}
426+
//or:
427+
fn foo<T>(x: T) {} // ok!
428+
```
429+
"##,
430+
431+
E0413: r##"
432+
A declaration shadows an enum variant or unit-like struct in scope.
433+
Example of erroneous code:
434+
435+
```
436+
struct Foo;
437+
438+
let Foo = 12i32; // error: declaration of `Foo` shadows an enum variant or
439+
// unit-like struct in scope
440+
```
441+
442+
443+
To fix this error, rename the variable such that it doesn't shadow any enum
444+
variable or structure in scope. Example:
445+
446+
```
447+
struct Foo;
448+
449+
let foo = 12i32; // ok!
450+
```
451+
452+
Or:
453+
454+
```
455+
struct FooStruct;
456+
457+
let Foo = 12i32; // ok!
458+
```
459+
460+
The goal here is to avoid a conflict of names.
461+
"##,
462+
463+
E0415: r##"
464+
More than one function parameter have the same name. Example of erroneous
465+
code:
466+
467+
```
468+
fn foo(f: i32, f: i32) {} // error: identifier `f` is bound more than
469+
// once in this parameter list
470+
```
471+
472+
Please verify you didn't misspell parameters' name. Example:
473+
474+
```
475+
fn foo(f: i32, g: i32) {} // ok!
476+
```
477+
"##,
478+
479+
E0416: r##"
480+
An identifier is bound more than once in a pattern. Example of erroneous
481+
code:
482+
483+
```
484+
match (1, 2) {
485+
(x, x) => {} // error: identifier `x` is bound more than once in the
486+
// same pattern
487+
}
488+
```
489+
490+
Please verify you didn't misspell identifiers' name. Example:
491+
492+
```
493+
match (1, 2) {
494+
(x, y) => {} // ok!
495+
}
496+
```
497+
498+
Or maybe did you mean to unify? Consider using a guard:
499+
500+
```
501+
match (A, B, C) {
502+
(x, x2, see) if x == x2 => { /* A and B are equal, do one thing */ }
503+
(y, z, see) => { /* A and B unequal; do another thing */ }
504+
}
505+
```
506+
"##,
507+
400508
E0417: r##"
401509
A static variable was referenced in a pattern. Example of erroneous code:
402510
@@ -425,6 +533,55 @@ match 0 {
425533
```
426534
"##,
427535

536+
E0419: r##"
537+
An unknown enum variant, struct or const was used. Example of
538+
erroneous code:
539+
540+
```
541+
match 0 {
542+
Something::Foo => {} // error: unresolved enum variant, struct
543+
// or const `Foo`
544+
}
545+
```
546+
547+
Please verify you didn't misspell it and the enum variant, struct or const has
548+
been declared and imported into scope. Example:
549+
550+
```
551+
enum Something {
552+
Foo,
553+
NotFoo,
554+
}
555+
556+
match Something::NotFoo {
557+
Something::Foo => {} // ok!
558+
_ => {}
559+
}
560+
```
561+
"##,
562+
563+
E0423: r##"
564+
A `struct` variant name was used like a function name. Example of
565+
erroneous code:
566+
567+
```
568+
struct Foo { a: bool};
569+
570+
let f = Foo();
571+
// error: `Foo` is a struct variant name, but this expression uses
572+
// it like a function name
573+
```
574+
575+
Please verify you didn't misspell the name of what you actually wanted
576+
to use here. Example:
577+
578+
```
579+
fn Foo() -> u32 { 0 }
580+
581+
let f = Foo(); // ok!
582+
```
583+
"##,
584+
428585
E0424: r##"
429586
The `self` keyword was used in a static method. Example of erroneous code:
430587
@@ -582,6 +739,27 @@ use something_which_doesnt_exist;
582739
Please verify you didn't misspell the import's name.
583740
"##,
584741

742+
E0435: r##"
743+
A non-constant value was used to initialise a constant. Example of erroneous
744+
code:
745+
746+
```
747+
let foo = 42u32;
748+
const FOO : u32 = foo; // error: attempt to use a non-constant value in a
749+
// constant
750+
```
751+
752+
To fix this error, please replace the value with a constant. Example:
753+
754+
```
755+
const FOO : u32 = 42u32; // ok!
756+
757+
// or:
758+
const OTHER_FOO : u32 = 42u32;
759+
const FOO : u32 = OTHER_FOO; // ok!
760+
```
761+
"##,
762+
585763
E0437: r##"
586764
Trait implementations can only implement associated types that are members of
587765
the trait in question. This error indicates that you attempted to implement
@@ -650,21 +828,12 @@ register_diagnostics! {
650828
// pattern #1
651829
E0410, // variable from pattern is not bound in pattern 1
652830
E0411, // use of `Self` outside of an impl or trait
653-
E0412, // use of undeclared
654-
E0413, // declaration of shadows an enum variant or unit-like struct in
655-
// scope
656831
E0414, // only irrefutable patterns allowed here
657-
E0415, // identifier is bound more than once in this parameter list
658-
E0416, // identifier is bound more than once in the same pattern
659832
E0418, // is not an enum variant, struct or const
660-
E0419, // unresolved enum variant, struct or const
661833
E0420, // is not an associated const
662834
E0421, // unresolved associated const
663835
E0422, // does not name a structure
664-
E0423, // is a struct variant name, but this expression uses it like a
665-
// function name
666836
E0427, // cannot use `ref` binding mode with ...
667837
E0429, // `self` imports are only allowed within a { } list
668838
E0434, // can't capture dynamic environment in a fn item
669-
E0435, // attempt to use a non-constant value in a constant
670839
}

src/librustc_typeck/diagnostics.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,48 @@ fn main() {
12331233
```
12341234
"##,
12351235

1236+
E0102: r##"
1237+
You hit this error because the compiler lacks information to
1238+
determine a type for this variable. Erroneous code example:
1239+
1240+
```
1241+
fn demo(devil: fn () -> !) {
1242+
let x: &_ = devil();
1243+
// error: cannot determine a type for this local variable
1244+
}
1245+
1246+
fn oh_no() -> ! { panic!("the devil is in the details") }
1247+
1248+
fn main() {
1249+
demo(oh_no);
1250+
}
1251+
```
1252+
1253+
To solve this situation, constrain the type of the variable.
1254+
Examples:
1255+
1256+
```
1257+
fn some_func(x: &u32) {
1258+
// some code
1259+
}
1260+
1261+
fn demo(devil: fn () -> !) {
1262+
let x: &u32 = devil();
1263+
// Here we defined the type at the variable creation
1264+
1265+
let x: &_ = devil();
1266+
some_func(x);
1267+
// Here, the type is determined by the function argument type
1268+
}
1269+
1270+
fn oh_no() -> ! { panic!("the devil is in the details") }
1271+
1272+
fn main() {
1273+
demo(oh_no);
1274+
}
1275+
```
1276+
"##,
1277+
12361278
E0106: r##"
12371279
This error indicates that a lifetime is missing from a type. If it is an error
12381280
inside a function signature, the problem may be with failing to adhere to the
@@ -2496,7 +2538,6 @@ register_diagnostics! {
24962538
E0085,
24972539
E0086,
24982540
E0090,
2499-
E0102,
25002541
E0103,
25012542
E0104,
25022543
E0118,

0 commit comments

Comments
 (0)