Skip to content

Commit 99ca63f

Browse files
committed
Auto merge of #26712 - GuillaumeGomez:patch-2, r=Manishearth
Part of #24407. cc @michaelsproul r? @Manishearth
2 parents c4b4f07 + 28d2b39 commit 99ca63f

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

src/librustc/diagnostics.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,54 @@ for v in &vs {
749749
```
750750
"##,
751751

752+
E0277: r##"
753+
You tried to use a type which doesn't implement some trait in a place which
754+
expected that trait. Erroneous code example:
755+
756+
```
757+
// here we declare the Foo trait with a bar method
758+
trait Foo {
759+
fn bar(&self);
760+
}
761+
762+
// we now declare a function which takes an object with Foo trait implemented
763+
// as parameter
764+
fn some_func<T: Foo>(foo: T) {
765+
foo.bar();
766+
}
767+
768+
fn main() {
769+
// we now call the method with the i32 type, which doesn't implement
770+
// the Foo trait
771+
some_func(5i32); // error: the trait `Foo` is not implemented for the
772+
// type `i32`
773+
}
774+
```
775+
776+
In order to fix this error, verify that the type you're using does implement
777+
the trait. Example:
778+
779+
```
780+
trait Foo {
781+
fn bar(&self);
782+
}
783+
784+
fn some_func<T: Foo>(foo: T) {
785+
foo.bar(); // we can now use this method since i32 implements the
786+
// Foo trait
787+
}
788+
789+
// we implement the trait on the i32 type
790+
impl Foo for i32 {
791+
fn bar(&self) {}
792+
}
793+
794+
fn main() {
795+
some_func(5i32); // ok!
796+
}
797+
```
798+
"##,
799+
752800
E0282: r##"
753801
This error indicates that type inference did not result in one unique possible
754802
type, and extra information is required. In most cases this can be provided
@@ -1103,7 +1151,6 @@ register_diagnostics! {
11031151
E0274, // rustc_on_unimplemented must have a value
11041152
E0275, // overflow evaluating requirement
11051153
E0276, // requirement appears on impl method but not on corresponding trait method
1106-
E0277, // trait is not implemented for type
11071154
E0278, // requirement is not satisfied
11081155
E0279, // requirement is not satisfied
11091156
E0280, // requirement is not satisfied

src/librustc_typeck/diagnostics.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,27 @@ static BAR: _ = "test"; // error, explicitly write out the type instead
13471347
```
13481348
"##,
13491349

1350+
E0124: r##"
1351+
You declared two fields of a struct with the same name. Erroneous code
1352+
example:
1353+
1354+
```
1355+
struct Foo {
1356+
field1: i32,
1357+
field1: i32 // error: field is already declared
1358+
}
1359+
```
1360+
1361+
Please verify that the field names have been correctly spelled. Example:
1362+
1363+
```
1364+
struct Foo {
1365+
field1: i32,
1366+
field2: i32 // ok!
1367+
}
1368+
```
1369+
"##,
1370+
13501371
E0131: r##"
13511372
It is not possible to define `main` with type parameters, or even with function
13521373
parameters. When `main` is present, it must take no arguments and return `()`.
@@ -1956,7 +1977,6 @@ register_diagnostics! {
19561977
E0120,
19571978
E0122,
19581979
E0123,
1959-
E0124,
19601980
E0127,
19611981
E0128,
19621982
E0129,

0 commit comments

Comments
 (0)