Skip to content

Commit eea27b8

Browse files
committed
Mention trait alias on the E0404 note
1 parent 539242a commit eea27b8

File tree

1 file changed

+20
-6
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+20
-6
lines changed

compiler/rustc_error_codes/src/error_codes/E0404.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ struct Foo;
88
struct Bar;
99
1010
impl Foo for Bar {} // error: `Foo` is not a trait
11+
fn baz<T: Foo>(t: T) {} // error: `Foo` is not a trait
1112
```
1213

1314
Another erroneous code example:
1415

1516
```compile_fail,E0404
16-
struct Foo;
17+
type Foo = Iterator<Item=String>;
1718
18-
fn bar<T: Foo>(t: T) {} // error: `Foo` is not a trait
19+
fn bar<T: Foo>(t: T) {} // error: `Foo` is a type alias
1920
```
2021

2122
Please verify that the trait's name was not misspelled or that the right
@@ -30,14 +31,27 @@ struct Bar;
3031
impl Foo for Bar { // ok!
3132
// functions implementation
3233
}
34+
35+
fn baz<T: Foo>(t: T) {} // ok!
3336
```
3437

35-
or:
38+
Alternatively, you could introduce a new trait with your desired restrictions
39+
as a super trait:
3640

3741
```
38-
trait Foo {
39-
// some functions
40-
}
42+
# trait Foo {}
43+
# struct Bar;
44+
# impl Foo for Bar {}
45+
trait Qux: Foo {} // Anything that implements Qux also needs to implement Foo
46+
fn baz<T: Qux>(t: T) {} // also ok!
47+
```
48+
49+
Finally, if you are on nightly and want to use a trait alias
50+
instead of a type alias, you should use `#![feature(trait_alias)]`:
51+
52+
```
53+
#![feature(trait_alias)]
54+
trait Foo = Iterator<Item=String>;
4155
4256
fn bar<T: Foo>(t: T) {} // ok!
4357
```

0 commit comments

Comments
 (0)