Skip to content

Commit 28d2b39

Browse files
Add E0277 error explanation
1 parent d2e6dda commit 28d2b39

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ struct Foo {
13581358
}
13591359
```
13601360
1361-
Please check you didn't mispelled one field. Example:
1361+
Please verify that the field names have been correctly spelled. Example:
13621362
13631363
```
13641364
struct Foo {

0 commit comments

Comments
 (0)