]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2014 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | #![allow(non_snake_case)] | |
12 | ||
d9579d0f AL |
13 | register_long_diagnostics! { |
14 | ||
62682a34 SL |
15 | E0023: r##" |
16 | A pattern used to match against an enum variant must provide a sub-pattern for | |
17 | each field of the enum variant. This error indicates that a pattern attempted to | |
18 | extract an incorrect number of fields from a variant. | |
19 | ||
20 | ``` | |
21 | enum Fruit { | |
7453a54e SL |
22 | Apple(String, String), |
23 | Pear(u32), | |
62682a34 SL |
24 | } |
25 | ``` | |
26 | ||
27 | Here the `Apple` variant has two fields, and should be matched against like so: | |
28 | ||
29 | ``` | |
7453a54e SL |
30 | enum Fruit { |
31 | Apple(String, String), | |
32 | Pear(u32), | |
33 | } | |
34 | ||
35 | let x = Fruit::Apple(String::new(), String::new()); | |
36 | ||
62682a34 SL |
37 | // Correct. |
38 | match x { | |
7453a54e SL |
39 | Fruit::Apple(a, b) => {}, |
40 | _ => {} | |
62682a34 SL |
41 | } |
42 | ``` | |
43 | ||
44 | Matching with the wrong number of fields has no sensible interpretation: | |
45 | ||
7453a54e SL |
46 | ```compile_fail |
47 | enum Fruit { | |
48 | Apple(String, String), | |
49 | Pear(u32), | |
50 | } | |
51 | ||
52 | let x = Fruit::Apple(String::new(), String::new()); | |
53 | ||
62682a34 SL |
54 | // Incorrect. |
55 | match x { | |
7453a54e SL |
56 | Apple(a) => {}, |
57 | Apple(a, b, c) => {}, | |
62682a34 SL |
58 | } |
59 | ``` | |
60 | ||
61 | Check how many fields the enum was declared with and ensure that your pattern | |
62 | uses the same number. | |
63 | "##, | |
64 | ||
65 | E0024: r##" | |
66 | This error indicates that a pattern attempted to extract the fields of an enum | |
67 | variant with no fields. Here's a tiny example of this error: | |
68 | ||
7453a54e | 69 | ```compile_fail |
62682a34 SL |
70 | // This enum has two variants. |
71 | enum Number { | |
72 | // This variant has no fields. | |
73 | Zero, | |
74 | // This variant has one field. | |
75 | One(u32) | |
76 | } | |
77 | ||
78 | // Assuming x is a Number we can pattern match on its contents. | |
79 | match x { | |
7453a54e SL |
80 | Zero(inside) => {}, |
81 | One(inside) => {}, | |
62682a34 SL |
82 | } |
83 | ``` | |
84 | ||
85 | The pattern match `Zero(inside)` is incorrect because the `Zero` variant | |
86 | contains no fields, yet the `inside` name attempts to bind the first field of | |
87 | the enum. | |
88 | "##, | |
89 | ||
90 | E0025: r##" | |
e9174d1e SL |
91 | Each field of a struct can only be bound once in a pattern. Erroneous code |
92 | example: | |
93 | ||
7453a54e | 94 | ```compile_fail |
e9174d1e SL |
95 | struct Foo { |
96 | a: u8, | |
97 | b: u8, | |
98 | } | |
99 | ||
100 | fn main(){ | |
101 | let x = Foo { a:1, b:2 }; | |
102 | ||
103 | let Foo { a: x, a: y } = x; | |
104 | // error: field `a` bound multiple times in the pattern | |
105 | } | |
106 | ``` | |
107 | ||
108 | Each occurrence of a field name binds the value of that field, so to fix this | |
109 | error you will have to remove or alter the duplicate uses of the field name. | |
110 | Perhaps you misspelled another field name? Example: | |
111 | ||
112 | ``` | |
113 | struct Foo { | |
114 | a: u8, | |
115 | b: u8, | |
116 | } | |
117 | ||
118 | fn main(){ | |
119 | let x = Foo { a:1, b:2 }; | |
120 | ||
121 | let Foo { a: x, b: y } = x; // ok! | |
122 | } | |
123 | ``` | |
62682a34 SL |
124 | "##, |
125 | ||
126 | E0026: r##" | |
b039eaaf | 127 | This error indicates that a struct pattern attempted to extract a non-existent |
62682a34 SL |
128 | field from a struct. Struct fields are identified by the name used before the |
129 | colon `:` so struct patterns should resemble the declaration of the struct type | |
130 | being matched. | |
131 | ||
132 | ``` | |
133 | // Correct matching. | |
134 | struct Thing { | |
135 | x: u32, | |
136 | y: u32 | |
137 | } | |
138 | ||
139 | let thing = Thing { x: 1, y: 2 }; | |
7453a54e | 140 | |
62682a34 | 141 | match thing { |
7453a54e | 142 | Thing { x: xfield, y: yfield } => {} |
62682a34 SL |
143 | } |
144 | ``` | |
145 | ||
146 | If you are using shorthand field patterns but want to refer to the struct field | |
147 | by a different name, you should rename it explicitly. | |
148 | ||
7453a54e SL |
149 | Change this: |
150 | ||
151 | ```compile_fail | |
152 | struct Thing { | |
153 | x: u32, | |
154 | y: u32 | |
155 | } | |
156 | ||
157 | let thing = Thing { x: 0, y: 0 }; | |
158 | ||
62682a34 | 159 | match thing { |
7453a54e | 160 | Thing { x, z } => {} |
62682a34 | 161 | } |
7453a54e SL |
162 | ``` |
163 | ||
164 | To this: | |
165 | ||
166 | ``` | |
167 | struct Thing { | |
168 | x: u32, | |
169 | y: u32 | |
170 | } | |
171 | ||
172 | let thing = Thing { x: 0, y: 0 }; | |
62682a34 | 173 | |
62682a34 | 174 | match thing { |
7453a54e | 175 | Thing { x, y: z } => {} |
62682a34 SL |
176 | } |
177 | ``` | |
178 | "##, | |
179 | ||
180 | E0027: r##" | |
181 | This error indicates that a pattern for a struct fails to specify a sub-pattern | |
182 | for every one of the struct's fields. Ensure that each field from the struct's | |
183 | definition is mentioned in the pattern, or use `..` to ignore unwanted fields. | |
184 | ||
185 | For example: | |
186 | ||
7453a54e | 187 | ```compile_fail |
62682a34 SL |
188 | struct Dog { |
189 | name: String, | |
7453a54e | 190 | age: u32, |
62682a34 SL |
191 | } |
192 | ||
193 | let d = Dog { name: "Rusty".to_string(), age: 8 }; | |
194 | ||
195 | // This is incorrect. | |
196 | match d { | |
7453a54e SL |
197 | Dog { age: x } => {} |
198 | } | |
199 | ``` | |
200 | ||
201 | This is correct (explicit): | |
202 | ||
203 | ``` | |
204 | struct Dog { | |
205 | name: String, | |
206 | age: u32, | |
62682a34 SL |
207 | } |
208 | ||
7453a54e SL |
209 | let d = Dog { name: "Rusty".to_string(), age: 8 }; |
210 | ||
62682a34 | 211 | match d { |
7453a54e | 212 | Dog { name: ref n, age: x } => {} |
62682a34 SL |
213 | } |
214 | ||
215 | // This is also correct (ignore unused fields). | |
216 | match d { | |
7453a54e | 217 | Dog { age: x, .. } => {} |
62682a34 SL |
218 | } |
219 | ``` | |
220 | "##, | |
221 | ||
222 | E0029: r##" | |
223 | In a match expression, only numbers and characters can be matched against a | |
224 | range. This is because the compiler checks that the range is non-empty at | |
225 | compile-time, and is unable to evaluate arbitrary comparison functions. If you | |
226 | want to capture values of an orderable type between two end-points, you can use | |
227 | a guard. | |
228 | ||
7453a54e | 229 | ```compile_fail |
62682a34 SL |
230 | // The ordering relation for strings can't be evaluated at compile time, |
231 | // so this doesn't work: | |
232 | match string { | |
7453a54e SL |
233 | "hello" ... "world" => {} |
234 | _ => {} | |
62682a34 SL |
235 | } |
236 | ||
237 | // This is a more general version, using a guard: | |
238 | match string { | |
7453a54e SL |
239 | s if s >= "hello" && s <= "world" => {} |
240 | _ => {} | |
62682a34 SL |
241 | } |
242 | ``` | |
243 | "##, | |
244 | ||
62682a34 SL |
245 | E0033: r##" |
246 | This error indicates that a pointer to a trait type cannot be implicitly | |
247 | dereferenced by a pattern. Every trait defines a type, but because the | |
248 | size of trait implementors isn't fixed, this type has no compile-time size. | |
249 | Therefore, all accesses to trait types must be through pointers. If you | |
250 | encounter this error you should try to avoid dereferencing the pointer. | |
251 | ||
7453a54e | 252 | ```ignore |
62682a34 SL |
253 | let trait_obj: &SomeTrait = ...; |
254 | ||
255 | // This tries to implicitly dereference to create an unsized local variable. | |
256 | let &invalid = trait_obj; | |
257 | ||
258 | // You can call methods without binding to the value being pointed at. | |
259 | trait_obj.method_one(); | |
260 | trait_obj.method_two(); | |
261 | ``` | |
262 | ||
263 | You can read more about trait objects in the Trait Object section of the | |
264 | Reference: | |
265 | ||
e9174d1e | 266 | https://doc.rust-lang.org/reference.html#trait-objects |
62682a34 SL |
267 | "##, |
268 | ||
269 | E0034: r##" | |
270 | The compiler doesn't know what method to call because more than one method | |
7453a54e | 271 | has the same prototype. Erroneous code example: |
62682a34 | 272 | |
7453a54e | 273 | ```compile_fail |
62682a34 SL |
274 | struct Test; |
275 | ||
276 | trait Trait1 { | |
277 | fn foo(); | |
278 | } | |
279 | ||
280 | trait Trait2 { | |
281 | fn foo(); | |
282 | } | |
283 | ||
284 | impl Trait1 for Test { fn foo() {} } | |
285 | impl Trait2 for Test { fn foo() {} } | |
286 | ||
287 | fn main() { | |
288 | Test::foo() // error, which foo() to call? | |
289 | } | |
290 | ``` | |
291 | ||
292 | To avoid this error, you have to keep only one of them and remove the others. | |
293 | So let's take our example and fix it: | |
294 | ||
295 | ``` | |
296 | struct Test; | |
297 | ||
298 | trait Trait1 { | |
299 | fn foo(); | |
300 | } | |
301 | ||
302 | impl Trait1 for Test { fn foo() {} } | |
303 | ||
304 | fn main() { | |
305 | Test::foo() // and now that's good! | |
306 | } | |
307 | ``` | |
308 | ||
309 | However, a better solution would be using fully explicit naming of type and | |
310 | trait: | |
311 | ||
312 | ``` | |
313 | struct Test; | |
314 | ||
315 | trait Trait1 { | |
316 | fn foo(); | |
317 | } | |
318 | ||
319 | trait Trait2 { | |
320 | fn foo(); | |
321 | } | |
322 | ||
323 | impl Trait1 for Test { fn foo() {} } | |
324 | impl Trait2 for Test { fn foo() {} } | |
325 | ||
326 | fn main() { | |
327 | <Test as Trait1>::foo() | |
328 | } | |
329 | ``` | |
54a0048b SL |
330 | |
331 | One last example: | |
332 | ||
333 | ``` | |
334 | trait F { | |
335 | fn m(&self); | |
336 | } | |
337 | ||
338 | trait G { | |
339 | fn m(&self); | |
340 | } | |
341 | ||
342 | struct X; | |
343 | ||
344 | impl F for X { fn m(&self) { println!("I am F"); } } | |
345 | impl G for X { fn m(&self) { println!("I am G"); } } | |
346 | ||
347 | fn main() { | |
348 | let f = X; | |
349 | ||
350 | F::m(&f); // it displays "I am F" | |
351 | G::m(&f); // it displays "I am G" | |
352 | } | |
353 | ``` | |
62682a34 SL |
354 | "##, |
355 | ||
356 | E0035: r##" | |
7453a54e SL |
357 | You tried to give a type parameter where it wasn't needed. Erroneous code |
358 | example: | |
62682a34 | 359 | |
7453a54e | 360 | ```compile_fail |
62682a34 SL |
361 | struct Test; |
362 | ||
363 | impl Test { | |
364 | fn method(&self) {} | |
365 | } | |
366 | ||
367 | fn main() { | |
368 | let x = Test; | |
369 | ||
370 | x.method::<i32>(); // Error: Test::method doesn't need type parameter! | |
371 | } | |
372 | ``` | |
373 | ||
374 | To fix this error, just remove the type parameter: | |
375 | ||
376 | ``` | |
377 | struct Test; | |
378 | ||
379 | impl Test { | |
380 | fn method(&self) {} | |
381 | } | |
382 | ||
383 | fn main() { | |
384 | let x = Test; | |
385 | ||
386 | x.method(); // OK, we're good! | |
387 | } | |
388 | ``` | |
389 | "##, | |
390 | ||
391 | E0036: r##" | |
392 | This error occurrs when you pass too many or not enough type parameters to | |
7453a54e | 393 | a method. Erroneous code example: |
62682a34 | 394 | |
7453a54e | 395 | ```compile_fail |
62682a34 SL |
396 | struct Test; |
397 | ||
398 | impl Test { | |
399 | fn method<T>(&self, v: &[T]) -> usize { | |
400 | v.len() | |
401 | } | |
402 | } | |
403 | ||
404 | fn main() { | |
405 | let x = Test; | |
54a0048b | 406 | let v = &[0]; |
62682a34 SL |
407 | |
408 | x.method::<i32, i32>(v); // error: only one type parameter is expected! | |
409 | } | |
410 | ``` | |
411 | ||
412 | To fix it, just specify a correct number of type parameters: | |
413 | ||
414 | ``` | |
415 | struct Test; | |
416 | ||
417 | impl Test { | |
418 | fn method<T>(&self, v: &[T]) -> usize { | |
419 | v.len() | |
420 | } | |
421 | } | |
422 | ||
423 | fn main() { | |
424 | let x = Test; | |
54a0048b | 425 | let v = &[0]; |
62682a34 SL |
426 | |
427 | x.method::<i32>(v); // OK, we're good! | |
428 | } | |
429 | ``` | |
430 | ||
431 | Please note on the last example that we could have called `method` like this: | |
432 | ||
7453a54e | 433 | ```ignore |
62682a34 SL |
434 | x.method(v); |
435 | ``` | |
436 | "##, | |
437 | ||
438 | E0040: r##" | |
439 | It is not allowed to manually call destructors in Rust. It is also not | |
440 | necessary to do this since `drop` is called automatically whenever a value goes | |
441 | out of scope. | |
442 | ||
443 | Here's an example of this error: | |
444 | ||
7453a54e | 445 | ```compile_fail |
62682a34 SL |
446 | struct Foo { |
447 | x: i32, | |
448 | } | |
449 | ||
450 | impl Drop for Foo { | |
451 | fn drop(&mut self) { | |
452 | println!("kaboom"); | |
453 | } | |
454 | } | |
455 | ||
456 | fn main() { | |
457 | let mut x = Foo { x: -7 }; | |
458 | x.drop(); // error: explicit use of destructor method | |
459 | } | |
460 | ``` | |
461 | "##, | |
462 | ||
c1a9b12d SL |
463 | E0044: r##" |
464 | You can't use type parameters on foreign items. Example of erroneous code: | |
465 | ||
7453a54e | 466 | ```compile_fail |
c1a9b12d SL |
467 | extern { fn some_func<T>(x: T); } |
468 | ``` | |
469 | ||
470 | To fix this, replace the type parameter with the specializations that you | |
471 | need: | |
472 | ||
473 | ``` | |
474 | extern { fn some_func_i32(x: i32); } | |
475 | extern { fn some_func_i64(x: i64); } | |
476 | ``` | |
477 | "##, | |
478 | ||
62682a34 SL |
479 | E0045: r##" |
480 | Rust only supports variadic parameters for interoperability with C code in its | |
481 | FFI. As such, variadic parameters can only be used with functions which are | |
482 | using the C ABI. Examples of erroneous code: | |
483 | ||
7453a54e | 484 | ```compile_fail |
62682a34 | 485 | extern "rust-call" { fn foo(x: u8, ...); } |
7453a54e | 486 | |
62682a34 | 487 | // or |
7453a54e | 488 | |
62682a34 SL |
489 | fn foo(x: u8, ...) {} |
490 | ``` | |
491 | ||
492 | To fix such code, put them in an extern "C" block: | |
493 | ||
7453a54e SL |
494 | ```ignore |
495 | extern "C" fn foo(x: u8, ...); | |
496 | ``` | |
497 | ||
498 | Or: | |
499 | ||
62682a34 | 500 | ``` |
62682a34 SL |
501 | extern "C" { |
502 | fn foo (x: u8, ...); | |
503 | } | |
504 | ``` | |
505 | "##, | |
506 | ||
d9579d0f | 507 | E0046: r##" |
e9174d1e SL |
508 | Items are missing in a trait implementation. Erroneous code example: |
509 | ||
7453a54e | 510 | ```compile_fail |
e9174d1e SL |
511 | trait Foo { |
512 | fn foo(); | |
513 | } | |
514 | ||
515 | struct Bar; | |
516 | ||
517 | impl Foo for Bar {} | |
518 | // error: not all trait items implemented, missing: `foo` | |
519 | ``` | |
520 | ||
d9579d0f AL |
521 | When trying to make some type implement a trait `Foo`, you must, at minimum, |
522 | provide implementations for all of `Foo`'s required methods (meaning the | |
523 | methods that do not have default implementations), as well as any required | |
e9174d1e SL |
524 | trait items like associated types or constants. Example: |
525 | ||
526 | ``` | |
527 | trait Foo { | |
528 | fn foo(); | |
529 | } | |
530 | ||
531 | struct Bar; | |
532 | ||
533 | impl Foo for Bar { | |
534 | fn foo() {} // ok! | |
535 | } | |
536 | ``` | |
d9579d0f AL |
537 | "##, |
538 | ||
539 | E0049: r##" | |
540 | This error indicates that an attempted implementation of a trait method | |
541 | has the wrong number of type parameters. | |
542 | ||
543 | For example, the trait below has a method `foo` with a type parameter `T`, | |
544 | but the implementation of `foo` for the type `Bar` is missing this parameter: | |
545 | ||
7453a54e | 546 | ```compile_fail |
d9579d0f AL |
547 | trait Foo { |
548 | fn foo<T: Default>(x: T) -> Self; | |
549 | } | |
550 | ||
551 | struct Bar; | |
552 | ||
553 | // error: method `foo` has 0 type parameters but its trait declaration has 1 | |
554 | // type parameter | |
555 | impl Foo for Bar { | |
556 | fn foo(x: bool) -> Self { Bar } | |
557 | } | |
558 | ``` | |
559 | "##, | |
560 | ||
561 | E0050: r##" | |
562 | This error indicates that an attempted implementation of a trait method | |
563 | has the wrong number of function parameters. | |
564 | ||
565 | For example, the trait below has a method `foo` with two function parameters | |
566 | (`&self` and `u8`), but the implementation of `foo` for the type `Bar` omits | |
567 | the `u8` parameter: | |
568 | ||
7453a54e | 569 | ```compile_fail |
d9579d0f AL |
570 | trait Foo { |
571 | fn foo(&self, x: u8) -> bool; | |
572 | } | |
573 | ||
574 | struct Bar; | |
575 | ||
576 | // error: method `foo` has 1 parameter but the declaration in trait `Foo::foo` | |
577 | // has 2 | |
578 | impl Foo for Bar { | |
579 | fn foo(&self) -> bool { true } | |
580 | } | |
581 | ``` | |
582 | "##, | |
583 | ||
584 | E0053: r##" | |
62682a34 SL |
585 | The parameters of any trait method must match between a trait implementation |
586 | and the trait definition. | |
d9579d0f | 587 | |
62682a34 | 588 | Here are a couple examples of this error: |
d9579d0f | 589 | |
7453a54e | 590 | ```compile_fail |
62682a34 SL |
591 | trait Foo { |
592 | fn foo(x: u16); | |
593 | fn bar(&self); | |
594 | } | |
d9579d0f AL |
595 | |
596 | struct Bar; | |
597 | ||
598 | impl Foo for Bar { | |
62682a34 SL |
599 | // error, expected u16, found i16 |
600 | fn foo(x: i16) { } | |
601 | ||
602 | // error, values differ in mutability | |
603 | fn bar(&mut self) { } | |
d9579d0f | 604 | } |
62682a34 SL |
605 | ``` |
606 | "##, | |
607 | ||
608 | E0054: r##" | |
609 | It is not allowed to cast to a bool. If you are trying to cast a numeric type | |
610 | to a bool, you can compare it with zero instead: | |
d9579d0f | 611 | |
7453a54e SL |
612 | ```compile_fail |
613 | let x = 5; | |
614 | ||
615 | // Not allowed, won't compile | |
616 | let x_is_nonzero = x as bool; | |
617 | ``` | |
618 | ||
d9579d0f | 619 | ``` |
62682a34 | 620 | let x = 5; |
d9579d0f | 621 | |
62682a34 SL |
622 | // Ok |
623 | let x_is_nonzero = x != 0; | |
d9579d0f | 624 | ``` |
62682a34 | 625 | "##, |
d9579d0f | 626 | |
62682a34 SL |
627 | E0055: r##" |
628 | During a method call, a value is automatically dereferenced as many times as | |
629 | needed to make the value's type match the method's receiver. The catch is that | |
630 | the compiler will only attempt to dereference a number of times up to the | |
631 | recursion limit (which can be set via the `recursion_limit` attribute). | |
d9579d0f | 632 | |
62682a34 SL |
633 | For a somewhat artificial example: |
634 | ||
7453a54e | 635 | ```compile_fail |
62682a34 SL |
636 | #![recursion_limit="2"] |
637 | ||
638 | struct Foo; | |
639 | ||
640 | impl Foo { | |
641 | fn foo(&self) {} | |
642 | } | |
643 | ||
644 | fn main() { | |
645 | let foo = Foo; | |
646 | let ref_foo = &&Foo; | |
647 | ||
648 | // error, reached the recursion limit while auto-dereferencing &&Foo | |
649 | ref_foo.foo(); | |
650 | } | |
651 | ``` | |
652 | ||
653 | One fix may be to increase the recursion limit. Note that it is possible to | |
654 | create an infinite recursion of dereferencing, in which case the only fix is to | |
655 | somehow break the recursion. | |
656 | "##, | |
657 | ||
658 | E0057: r##" | |
659 | When invoking closures or other implementations of the function traits `Fn`, | |
660 | `FnMut` or `FnOnce` using call notation, the number of parameters passed to the | |
661 | function must match its definition. | |
662 | ||
663 | An example using a closure: | |
664 | ||
7453a54e | 665 | ```compile_fail |
62682a34 SL |
666 | let f = |x| x * 3; |
667 | let a = f(); // invalid, too few parameters | |
668 | let b = f(4); // this works! | |
669 | let c = f(2, 3); // invalid, too many parameters | |
670 | ``` | |
671 | ||
672 | A generic function must be treated similarly: | |
673 | ||
674 | ``` | |
675 | fn foo<F: Fn()>(f: F) { | |
676 | f(); // this is valid, but f(3) would not work | |
d9579d0f | 677 | } |
62682a34 SL |
678 | ``` |
679 | "##, | |
680 | ||
681 | E0059: r##" | |
682 | The built-in function traits are generic over a tuple of the function arguments. | |
683 | If one uses angle-bracket notation (`Fn<(T,), Output=U>`) instead of parentheses | |
684 | (`Fn(T) -> U`) to denote the function trait, the type parameter should be a | |
685 | tuple. Otherwise function call notation cannot be used and the trait will not be | |
686 | implemented by closures. | |
d9579d0f | 687 | |
62682a34 SL |
688 | The most likely source of this error is using angle-bracket notation without |
689 | wrapping the function argument type into a tuple, for example: | |
690 | ||
7453a54e | 691 | ```compile_fail |
62682a34 | 692 | fn foo<F: Fn<i32>>(f: F) -> F::Output { f(3) } |
d9579d0f AL |
693 | ``` |
694 | ||
62682a34 SL |
695 | It can be fixed by adjusting the trait bound like this: |
696 | ||
7453a54e | 697 | ```ignore |
62682a34 SL |
698 | fn foo<F: Fn<(i32,)>>(f: F) -> F::Output { f(3) } |
699 | ``` | |
d9579d0f | 700 | |
62682a34 SL |
701 | Note that `(T,)` always denotes the type of a 1-tuple containing an element of |
702 | type `T`. The comma is necessary for syntactic disambiguation. | |
d9579d0f AL |
703 | "##, |
704 | ||
62682a34 SL |
705 | E0060: r##" |
706 | External C functions are allowed to be variadic. However, a variadic function | |
707 | takes a minimum number of arguments. For example, consider C's variadic `printf` | |
708 | function: | |
d9579d0f | 709 | |
7453a54e | 710 | ```ignore |
62682a34 SL |
711 | extern crate libc; |
712 | use libc::{ c_char, c_int }; | |
d9579d0f | 713 | |
62682a34 SL |
714 | extern "C" { |
715 | fn printf(_: *const c_char, ...) -> c_int; | |
716 | } | |
717 | ``` | |
718 | ||
719 | Using this declaration, it must be called with at least one argument, so | |
c1a9b12d | 720 | simply calling `printf()` is invalid. But the following uses are allowed: |
d9579d0f | 721 | |
7453a54e | 722 | ```ignore |
62682a34 SL |
723 | unsafe { |
724 | use std::ffi::CString; | |
725 | ||
726 | printf(CString::new("test\n").unwrap().as_ptr()); | |
727 | printf(CString::new("number = %d\n").unwrap().as_ptr(), 3); | |
728 | printf(CString::new("%d, %d\n").unwrap().as_ptr(), 10, 5); | |
729 | } | |
730 | ``` | |
731 | "##, | |
732 | ||
733 | E0061: r##" | |
734 | The number of arguments passed to a function must match the number of arguments | |
735 | specified in the function signature. | |
736 | ||
7453a54e | 737 | For example, a function like: |
62682a34 SL |
738 | |
739 | ``` | |
740 | fn f(a: u16, b: &str) {} | |
741 | ``` | |
742 | ||
7453a54e | 743 | Must always be called with exactly two arguments, e.g. `f(2, "test")`. |
62682a34 SL |
744 | |
745 | Note, that Rust does not have a notion of optional function arguments or | |
746 | variadic functions (except for its C-FFI). | |
d9579d0f AL |
747 | "##, |
748 | ||
749 | E0062: r##" | |
750 | This error indicates that during an attempt to build a struct or struct-like | |
e9174d1e SL |
751 | enum variant, one of the fields was specified more than once. Erroneous code |
752 | example: | |
753 | ||
7453a54e | 754 | ```compile_fail |
e9174d1e SL |
755 | struct Foo { |
756 | x: i32 | |
757 | } | |
758 | ||
759 | fn main() { | |
760 | let x = Foo { | |
761 | x: 0, | |
762 | x: 0, // error: field `x` specified more than once | |
763 | }; | |
764 | } | |
765 | ``` | |
766 | ||
767 | Each field should be specified exactly one time. Example: | |
768 | ||
769 | ``` | |
770 | struct Foo { | |
771 | x: i32 | |
772 | } | |
773 | ||
774 | fn main() { | |
775 | let x = Foo { x: 0 }; // ok! | |
776 | } | |
777 | ``` | |
d9579d0f AL |
778 | "##, |
779 | ||
780 | E0063: r##" | |
781 | This error indicates that during an attempt to build a struct or struct-like | |
e9174d1e SL |
782 | enum variant, one of the fields was not provided. Erroneous code example: |
783 | ||
7453a54e | 784 | ```compile_fail |
e9174d1e SL |
785 | struct Foo { |
786 | x: i32, | |
787 | y: i32 | |
788 | } | |
789 | ||
790 | fn main() { | |
791 | let x = Foo { x: 0 }; // error: missing field: `y` | |
792 | } | |
793 | ``` | |
794 | ||
795 | Each field should be specified exactly once. Example: | |
796 | ||
797 | ``` | |
798 | struct Foo { | |
799 | x: i32, | |
800 | y: i32 | |
801 | } | |
802 | ||
803 | fn main() { | |
804 | let x = Foo { x: 0, y: 0 }; // ok! | |
805 | } | |
806 | ``` | |
d9579d0f AL |
807 | "##, |
808 | ||
809 | E0066: r##" | |
810 | Box placement expressions (like C++'s "placement new") do not yet support any | |
811 | place expression except the exchange heap (i.e. `std::boxed::HEAP`). | |
812 | Furthermore, the syntax is changing to use `in` instead of `box`. See [RFC 470] | |
813 | and [RFC 809] for more details. | |
814 | ||
815 | [RFC 470]: https://github.com/rust-lang/rfcs/pull/470 | |
816 | [RFC 809]: https://github.com/rust-lang/rfcs/pull/809 | |
817 | "##, | |
818 | ||
819 | E0067: r##" | |
62682a34 SL |
820 | The left-hand side of a compound assignment expression must be an lvalue |
821 | expression. An lvalue expression represents a memory location and includes | |
822 | item paths (ie, namespaced variables), dereferences, indexing expressions, | |
823 | and field references. | |
d9579d0f | 824 | |
7453a54e | 825 | Let's start with some erroneous code examples: |
e9174d1e | 826 | |
7453a54e | 827 | ```compile_fail |
d9579d0f AL |
828 | use std::collections::LinkedList; |
829 | ||
d9579d0f AL |
830 | // Bad: assignment to non-lvalue expression |
831 | LinkedList::new() += 1; | |
62682a34 SL |
832 | |
833 | // ... | |
834 | ||
835 | fn some_func(i: &mut i32) { | |
836 | i += 12; // Error : '+=' operation cannot be applied on a reference ! | |
837 | } | |
e9174d1e | 838 | ``` |
62682a34 | 839 | |
7453a54e | 840 | And now some working examples: |
e9174d1e | 841 | |
62682a34 SL |
842 | ``` |
843 | let mut i : i32 = 0; | |
844 | ||
845 | i += 12; // Good ! | |
846 | ||
847 | // ... | |
848 | ||
849 | fn some_func(i: &mut i32) { | |
850 | *i += 12; // Good ! | |
851 | } | |
d9579d0f AL |
852 | ``` |
853 | "##, | |
854 | ||
855 | E0069: r##" | |
856 | The compiler found a function whose body contains a `return;` statement but | |
857 | whose return type is not `()`. An example of this is: | |
858 | ||
7453a54e | 859 | ```compile_fail |
d9579d0f AL |
860 | // error |
861 | fn foo() -> u8 { | |
862 | return; | |
863 | } | |
864 | ``` | |
865 | ||
866 | Since `return;` is just like `return ();`, there is a mismatch between the | |
867 | function's return type and the value being returned. | |
868 | "##, | |
869 | ||
62682a34 SL |
870 | E0070: r##" |
871 | The left-hand side of an assignment operator must be an lvalue expression. An | |
872 | lvalue expression represents a memory location and can be a variable (with | |
873 | optional namespacing), a dereference, an indexing expression or a field | |
874 | reference. | |
875 | ||
876 | More details can be found here: | |
9cc50fc6 | 877 | https://doc.rust-lang.org/reference.html#lvalues-rvalues-and-temporaries |
62682a34 | 878 | |
7453a54e | 879 | Now, we can go further. Here are some erroneous code examples: |
e9174d1e | 880 | |
7453a54e | 881 | ```compile_fail |
62682a34 SL |
882 | struct SomeStruct { |
883 | x: i32, | |
884 | y: i32 | |
885 | } | |
7453a54e | 886 | |
62682a34 SL |
887 | const SOME_CONST : i32 = 12; |
888 | ||
889 | fn some_other_func() {} | |
890 | ||
891 | fn some_function() { | |
892 | SOME_CONST = 14; // error : a constant value cannot be changed! | |
893 | 1 = 3; // error : 1 isn't a valid lvalue! | |
894 | some_other_func() = 4; // error : we can't assign value to a function! | |
895 | SomeStruct.x = 12; // error : SomeStruct a structure name but it is used | |
896 | // like a variable! | |
897 | } | |
898 | ``` | |
899 | ||
7453a54e | 900 | And now let's give working examples: |
62682a34 SL |
901 | |
902 | ``` | |
903 | struct SomeStruct { | |
904 | x: i32, | |
905 | y: i32 | |
906 | } | |
907 | let mut s = SomeStruct {x: 0, y: 0}; | |
908 | ||
909 | s.x = 3; // that's good ! | |
910 | ||
911 | // ... | |
912 | ||
913 | fn some_func(x: &mut i32) { | |
914 | *x = 12; // that's good ! | |
915 | } | |
916 | ``` | |
917 | "##, | |
918 | ||
c1a9b12d | 919 | E0071: r##" |
e9174d1e SL |
920 | You tried to use structure-literal syntax to create an item that is |
921 | not a struct-style structure or enum variant. | |
922 | ||
c1a9b12d SL |
923 | Example of erroneous code: |
924 | ||
7453a54e | 925 | ```compile_fail |
e9174d1e | 926 | enum Foo { FirstValue(i32) }; |
c1a9b12d | 927 | |
54a0048b | 928 | let u = Foo::FirstValue { value: 0 }; // error: Foo::FirstValue |
c1a9b12d | 929 | // isn't a structure! |
e9174d1e SL |
930 | // or even simpler, if the name doesn't refer to a structure at all. |
931 | let t = u32 { value: 4 }; // error: `u32` does not name a structure. | |
c1a9b12d SL |
932 | ``` |
933 | ||
e9174d1e SL |
934 | To fix this, ensure that the name was correctly spelled, and that |
935 | the correct form of initializer was used. | |
c1a9b12d | 936 | |
e9174d1e | 937 | For example, the code above can be fixed to: |
c1a9b12d SL |
938 | |
939 | ``` | |
c1a9b12d | 940 | enum Foo { |
e9174d1e | 941 | FirstValue(i32) |
c1a9b12d SL |
942 | } |
943 | ||
944 | fn main() { | |
e9174d1e | 945 | let u = Foo::FirstValue(0i32); |
c1a9b12d | 946 | |
e9174d1e | 947 | let t = 4; |
c1a9b12d SL |
948 | } |
949 | ``` | |
950 | "##, | |
951 | ||
62682a34 SL |
952 | E0073: r##" |
953 | You cannot define a struct (or enum) `Foo` that requires an instance of `Foo` | |
954 | in order to make a new `Foo` value. This is because there would be no way a | |
955 | first instance of `Foo` could be made to initialize another instance! | |
956 | ||
957 | Here's an example of a struct that has this problem: | |
958 | ||
7453a54e | 959 | ```compile_fail |
62682a34 SL |
960 | struct Foo { x: Box<Foo> } // error |
961 | ``` | |
962 | ||
963 | One fix is to use `Option`, like so: | |
964 | ||
965 | ``` | |
966 | struct Foo { x: Option<Box<Foo>> } | |
967 | ``` | |
968 | ||
969 | Now it's possible to create at least one instance of `Foo`: `Foo { x: None }`. | |
970 | "##, | |
971 | ||
c1a9b12d SL |
972 | E0074: r##" |
973 | When using the `#[simd]` attribute on a tuple struct, the components of the | |
974 | tuple struct must all be of a concrete, nongeneric type so the compiler can | |
975 | reason about how to use SIMD with them. This error will occur if the types | |
976 | are generic. | |
977 | ||
7453a54e SL |
978 | This will cause an error: |
979 | ||
980 | ```compile_fail | |
981 | #![feature(simd)] | |
982 | ||
c1a9b12d | 983 | #[simd] |
7453a54e SL |
984 | struct Bad<T>(T, T, T); |
985 | ``` | |
986 | ||
987 | This will not: | |
988 | ||
989 | ``` | |
990 | #![feature(simd)] | |
c1a9b12d SL |
991 | |
992 | #[simd] | |
7453a54e | 993 | struct Good(u32, u32, u32); |
c1a9b12d SL |
994 | ``` |
995 | "##, | |
996 | ||
997 | E0075: r##" | |
998 | The `#[simd]` attribute can only be applied to non empty tuple structs, because | |
999 | it doesn't make sense to try to use SIMD operations when there are no values to | |
1000 | operate on. | |
1001 | ||
7453a54e SL |
1002 | This will cause an error: |
1003 | ||
1004 | ```compile_fail | |
1005 | #![feature(simd)] | |
1006 | ||
c1a9b12d | 1007 | #[simd] |
7453a54e SL |
1008 | struct Bad; |
1009 | ``` | |
1010 | ||
1011 | This will not: | |
1012 | ||
1013 | ``` | |
1014 | #![feature(simd)] | |
c1a9b12d SL |
1015 | |
1016 | #[simd] | |
7453a54e | 1017 | struct Good(u32); |
c1a9b12d SL |
1018 | ``` |
1019 | "##, | |
1020 | ||
1021 | E0076: r##" | |
1022 | When using the `#[simd]` attribute to automatically use SIMD operations in tuple | |
1023 | struct, the types in the struct must all be of the same type, or the compiler | |
1024 | will trigger this error. | |
1025 | ||
7453a54e SL |
1026 | This will cause an error: |
1027 | ||
1028 | ```compile_fail | |
1029 | #![feature(simd)] | |
c1a9b12d SL |
1030 | |
1031 | #[simd] | |
7453a54e | 1032 | struct Bad(u16, u32, u32); |
c1a9b12d SL |
1033 | ``` |
1034 | ||
7453a54e SL |
1035 | This will not: |
1036 | ||
1037 | ``` | |
1038 | #![feature(simd)] | |
1039 | ||
1040 | #[simd] | |
1041 | struct Good(u32, u32, u32); | |
1042 | ``` | |
c1a9b12d SL |
1043 | "##, |
1044 | ||
1045 | E0077: r##" | |
1046 | When using the `#[simd]` attribute on a tuple struct, the elements in the tuple | |
1047 | must be machine types so SIMD operations can be applied to them. | |
1048 | ||
7453a54e SL |
1049 | This will cause an error: |
1050 | ||
1051 | ```compile_fail | |
1052 | #![feature(simd)] | |
1053 | ||
c1a9b12d | 1054 | #[simd] |
7453a54e SL |
1055 | struct Bad(String); |
1056 | ``` | |
1057 | ||
1058 | This will not: | |
1059 | ||
1060 | ``` | |
1061 | #![feature(simd)] | |
c1a9b12d SL |
1062 | |
1063 | #[simd] | |
7453a54e | 1064 | struct Good(u32, u32, u32); |
c1a9b12d SL |
1065 | ``` |
1066 | "##, | |
1067 | ||
e9174d1e SL |
1068 | E0079: r##" |
1069 | Enum variants which contain no data can be given a custom integer | |
1070 | representation. This error indicates that the value provided is not an integer | |
1071 | literal and is therefore invalid. | |
1072 | ||
7453a54e | 1073 | For example, in the following code: |
e9174d1e | 1074 | |
7453a54e | 1075 | ```compile_fail |
e9174d1e SL |
1076 | enum Foo { |
1077 | Q = "32" | |
1078 | } | |
1079 | ``` | |
1080 | ||
7453a54e | 1081 | We try to set the representation to a string. |
e9174d1e SL |
1082 | |
1083 | There's no general fix for this; if you can work with an integer then just set | |
1084 | it to one: | |
1085 | ||
1086 | ``` | |
1087 | enum Foo { | |
1088 | Q = 32 | |
1089 | } | |
1090 | ``` | |
1091 | ||
7453a54e | 1092 | However if you actually wanted a mapping between variants and non-integer |
e9174d1e SL |
1093 | objects, it may be preferable to use a method with a match instead: |
1094 | ||
1095 | ``` | |
1096 | enum Foo { Q } | |
1097 | impl Foo { | |
1098 | fn get_str(&self) -> &'static str { | |
1099 | match *self { | |
1100 | Foo::Q => "32", | |
1101 | } | |
1102 | } | |
1103 | } | |
1104 | ``` | |
1105 | "##, | |
1106 | ||
1107 | E0080: r##" | |
1108 | This error indicates that the compiler was unable to sensibly evaluate an | |
1109 | integer expression provided as an enum discriminant. Attempting to divide by 0 | |
1110 | or causing integer overflow are two ways to induce this error. For example: | |
1111 | ||
7453a54e | 1112 | ```compile_fail |
e9174d1e SL |
1113 | enum Enum { |
1114 | X = (1 << 500), | |
1115 | Y = (1 / 0) | |
1116 | } | |
1117 | ``` | |
1118 | ||
1119 | Ensure that the expressions given can be evaluated as the desired integer type. | |
1120 | See the FFI section of the Reference for more information about using a custom | |
1121 | integer type: | |
1122 | ||
1123 | https://doc.rust-lang.org/reference.html#ffi-attributes | |
1124 | "##, | |
1125 | ||
d9579d0f AL |
1126 | E0081: r##" |
1127 | Enum discriminants are used to differentiate enum variants stored in memory. | |
1128 | This error indicates that the same value was used for two or more variants, | |
1129 | making them impossible to tell apart. | |
1130 | ||
7453a54e SL |
1131 | ```compile_fail |
1132 | // Bad. | |
d9579d0f | 1133 | enum Enum { |
7453a54e | 1134 | P = 3, |
d9579d0f AL |
1135 | X = 3, |
1136 | Y = 5 | |
1137 | } | |
7453a54e | 1138 | ``` |
d9579d0f | 1139 | |
7453a54e SL |
1140 | ``` |
1141 | // Good. | |
d9579d0f | 1142 | enum Enum { |
7453a54e | 1143 | P, |
d9579d0f AL |
1144 | X = 3, |
1145 | Y = 5 | |
1146 | } | |
1147 | ``` | |
1148 | ||
1149 | Note that variants without a manually specified discriminant are numbered from | |
1150 | top to bottom starting from 0, so clashes can occur with seemingly unrelated | |
1151 | variants. | |
1152 | ||
7453a54e | 1153 | ```compile_fail |
d9579d0f AL |
1154 | enum Bad { |
1155 | X, | |
1156 | Y = 0 | |
1157 | } | |
1158 | ``` | |
1159 | ||
54a0048b | 1160 | Here `X` will have already been specified the discriminant 0 by the time `Y` is |
d9579d0f AL |
1161 | encountered, so a conflict occurs. |
1162 | "##, | |
1163 | ||
1164 | E0082: r##" | |
54a0048b SL |
1165 | When you specify enum discriminants with `=`, the compiler expects `isize` |
1166 | values by default. Or you can add the `repr` attibute to the enum declaration | |
1167 | for an explicit choice of the discriminant type. In either cases, the | |
1168 | discriminant values must fall within a valid range for the expected type; | |
1169 | otherwise this error is raised. For example: | |
d9579d0f | 1170 | |
7453a54e | 1171 | ```compile_fail |
d9579d0f AL |
1172 | #[repr(u8)] |
1173 | enum Thing { | |
1174 | A = 1024, | |
1175 | B = 5 | |
1176 | } | |
1177 | ``` | |
1178 | ||
1179 | Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is | |
54a0048b SL |
1180 | invalid. Here is another, more subtle example which depends on target word size: |
1181 | ||
1182 | ```compile_fail | |
1183 | enum DependsOnPointerSize { | |
1184 | A = 1 << 32 | |
1185 | } | |
1186 | ``` | |
1187 | ||
1188 | Here, `1 << 32` is interpreted as an `isize` value. So it is invalid for 32 bit | |
1189 | target (`target_pointer_width = "32"`) but valid for 64 bit target. | |
d9579d0f | 1190 | |
54a0048b SL |
1191 | You may want to change representation types to fix this, or else change invalid |
1192 | discriminant values so that they fit within the existing type. | |
d9579d0f AL |
1193 | "##, |
1194 | ||
d9579d0f AL |
1195 | E0084: r##" |
1196 | It is impossible to define an integer type to be used to represent zero-variant | |
1197 | enum values because there are no zero-variant enum values. There is no way to | |
1198 | construct an instance of the following type using only safe code: | |
1199 | ||
1200 | ``` | |
1201 | enum Empty {} | |
1202 | ``` | |
1203 | "##, | |
1204 | ||
62682a34 SL |
1205 | E0087: r##" |
1206 | Too many type parameters were supplied for a function. For example: | |
1207 | ||
7453a54e | 1208 | ```compile_fail |
62682a34 SL |
1209 | fn foo<T>() {} |
1210 | ||
1211 | fn main() { | |
1212 | foo::<f64, bool>(); // error, expected 1 parameter, found 2 parameters | |
1213 | } | |
1214 | ``` | |
1215 | ||
e9174d1e | 1216 | The number of supplied parameters must exactly match the number of defined type |
62682a34 SL |
1217 | parameters. |
1218 | "##, | |
1219 | ||
c1a9b12d SL |
1220 | E0088: r##" |
1221 | You gave too many lifetime parameters. Erroneous code example: | |
1222 | ||
7453a54e | 1223 | ```compile_fail |
c1a9b12d SL |
1224 | fn f() {} |
1225 | ||
1226 | fn main() { | |
1227 | f::<'static>() // error: too many lifetime parameters provided | |
1228 | } | |
1229 | ``` | |
1230 | ||
1231 | Please check you give the right number of lifetime parameters. Example: | |
1232 | ||
1233 | ``` | |
1234 | fn f() {} | |
1235 | ||
1236 | fn main() { | |
1237 | f() // ok! | |
1238 | } | |
1239 | ``` | |
1240 | ||
1241 | It's also important to note that the Rust compiler can generally | |
1242 | determine the lifetime by itself. Example: | |
1243 | ||
1244 | ``` | |
1245 | struct Foo { | |
1246 | value: String | |
1247 | } | |
1248 | ||
1249 | impl Foo { | |
1250 | // it can be written like this | |
1251 | fn get_value<'a>(&'a self) -> &'a str { &self.value } | |
1252 | // but the compiler works fine with this too: | |
1253 | fn without_lifetime(&self) -> &str { &self.value } | |
1254 | } | |
1255 | ||
1256 | fn main() { | |
1257 | let f = Foo { value: "hello".to_owned() }; | |
1258 | ||
1259 | println!("{}", f.get_value()); | |
1260 | println!("{}", f.without_lifetime()); | |
1261 | } | |
1262 | ``` | |
1263 | "##, | |
1264 | ||
62682a34 SL |
1265 | E0089: r##" |
1266 | Not enough type parameters were supplied for a function. For example: | |
1267 | ||
7453a54e | 1268 | ```compile_fail |
62682a34 SL |
1269 | fn foo<T, U>() {} |
1270 | ||
1271 | fn main() { | |
1272 | foo::<f64>(); // error, expected 2 parameters, found 1 parameter | |
1273 | } | |
1274 | ``` | |
1275 | ||
1276 | Note that if a function takes multiple type parameters but you want the compiler | |
1277 | to infer some of them, you can use type placeholders: | |
1278 | ||
7453a54e | 1279 | ```compile_fail |
62682a34 SL |
1280 | fn foo<T, U>(x: T) {} |
1281 | ||
1282 | fn main() { | |
1283 | let x: bool = true; | |
1284 | foo::<f64>(x); // error, expected 2 parameters, found 1 parameter | |
1285 | foo::<_, f64>(x); // same as `foo::<bool, f64>(x)` | |
1286 | } | |
1287 | ``` | |
1288 | "##, | |
1289 | ||
c1a9b12d SL |
1290 | E0091: r##" |
1291 | You gave an unnecessary type parameter in a type alias. Erroneous code | |
1292 | example: | |
1293 | ||
7453a54e | 1294 | ```compile_fail |
c1a9b12d SL |
1295 | type Foo<T> = u32; // error: type parameter `T` is unused |
1296 | // or: | |
1297 | type Foo<A,B> = Box<A>; // error: type parameter `B` is unused | |
1298 | ``` | |
1299 | ||
1300 | Please check you didn't write too many type parameters. Example: | |
1301 | ||
1302 | ``` | |
1303 | type Foo = u32; // ok! | |
7453a54e | 1304 | type Foo2<A> = Box<A>; // ok! |
c1a9b12d SL |
1305 | ``` |
1306 | "##, | |
1307 | ||
1308 | E0092: r##" | |
1309 | You tried to declare an undefined atomic operation function. | |
1310 | Erroneous code example: | |
1311 | ||
7453a54e | 1312 | ```compile_fail |
c1a9b12d SL |
1313 | #![feature(intrinsics)] |
1314 | ||
1315 | extern "rust-intrinsic" { | |
1316 | fn atomic_foo(); // error: unrecognized atomic operation | |
1317 | // function | |
1318 | } | |
1319 | ``` | |
1320 | ||
1321 | Please check you didn't make a mistake in the function's name. All intrinsic | |
1322 | functions are defined in librustc_trans/trans/intrinsic.rs and in | |
1323 | libcore/intrinsics.rs in the Rust source code. Example: | |
1324 | ||
1325 | ``` | |
1326 | #![feature(intrinsics)] | |
1327 | ||
1328 | extern "rust-intrinsic" { | |
1329 | fn atomic_fence(); // ok! | |
1330 | } | |
1331 | ``` | |
1332 | "##, | |
1333 | ||
1334 | E0093: r##" | |
1335 | You declared an unknown intrinsic function. Erroneous code example: | |
1336 | ||
7453a54e | 1337 | ```compile_fail |
c1a9b12d SL |
1338 | #![feature(intrinsics)] |
1339 | ||
1340 | extern "rust-intrinsic" { | |
1341 | fn foo(); // error: unrecognized intrinsic function: `foo` | |
1342 | } | |
1343 | ||
1344 | fn main() { | |
1345 | unsafe { | |
1346 | foo(); | |
1347 | } | |
1348 | } | |
1349 | ``` | |
1350 | ||
1351 | Please check you didn't make a mistake in the function's name. All intrinsic | |
1352 | functions are defined in librustc_trans/trans/intrinsic.rs and in | |
1353 | libcore/intrinsics.rs in the Rust source code. Example: | |
1354 | ||
1355 | ``` | |
1356 | #![feature(intrinsics)] | |
1357 | ||
1358 | extern "rust-intrinsic" { | |
1359 | fn atomic_fence(); // ok! | |
1360 | } | |
1361 | ||
1362 | fn main() { | |
1363 | unsafe { | |
1364 | atomic_fence(); | |
1365 | } | |
1366 | } | |
1367 | ``` | |
1368 | "##, | |
1369 | ||
1370 | E0094: r##" | |
1371 | You gave an invalid number of type parameters to an intrinsic function. | |
1372 | Erroneous code example: | |
1373 | ||
7453a54e | 1374 | ```compile_fail |
c1a9b12d SL |
1375 | #![feature(intrinsics)] |
1376 | ||
1377 | extern "rust-intrinsic" { | |
1378 | fn size_of<T, U>() -> usize; // error: intrinsic has wrong number | |
1379 | // of type parameters | |
1380 | } | |
1381 | ``` | |
1382 | ||
1383 | Please check that you provided the right number of lifetime parameters | |
1384 | and verify with the function declaration in the Rust source code. | |
1385 | Example: | |
1386 | ||
1387 | ``` | |
1388 | #![feature(intrinsics)] | |
1389 | ||
1390 | extern "rust-intrinsic" { | |
1391 | fn size_of<T>() -> usize; // ok! | |
1392 | } | |
1393 | ``` | |
1394 | "##, | |
1395 | ||
1396 | E0101: r##" | |
b039eaaf SL |
1397 | You hit this error because the compiler lacks the information to |
1398 | determine a type for this expression. Erroneous code example: | |
c1a9b12d | 1399 | |
7453a54e | 1400 | ```compile_fail |
c1a9b12d SL |
1401 | fn main() { |
1402 | let x = |_| {}; // error: cannot determine a type for this expression | |
1403 | } | |
1404 | ``` | |
1405 | ||
1406 | You have two possibilities to solve this situation: | |
1407 | * Give an explicit definition of the expression | |
1408 | * Infer the expression | |
1409 | ||
1410 | Examples: | |
1411 | ||
1412 | ``` | |
1413 | fn main() { | |
1414 | let x = |_ : u32| {}; // ok! | |
1415 | // or: | |
1416 | let x = |_| {}; | |
1417 | x(0u32); | |
1418 | } | |
1419 | ``` | |
1420 | "##, | |
1421 | ||
e9174d1e SL |
1422 | E0102: r##" |
1423 | You hit this error because the compiler lacks information to | |
1424 | determine a type for this variable. Erroneous code example: | |
1425 | ||
7453a54e | 1426 | ```compile_fail |
e9174d1e SL |
1427 | fn demo(devil: fn () -> !) { |
1428 | let x: &_ = devil(); | |
1429 | // error: cannot determine a type for this local variable | |
1430 | } | |
1431 | ||
1432 | fn oh_no() -> ! { panic!("the devil is in the details") } | |
1433 | ||
1434 | fn main() { | |
1435 | demo(oh_no); | |
1436 | } | |
1437 | ``` | |
1438 | ||
1439 | To solve this situation, constrain the type of the variable. | |
1440 | Examples: | |
1441 | ||
7453a54e SL |
1442 | ```no_run |
1443 | #![allow(unused_variables)] | |
1444 | ||
e9174d1e SL |
1445 | fn some_func(x: &u32) { |
1446 | // some code | |
1447 | } | |
1448 | ||
1449 | fn demo(devil: fn () -> !) { | |
1450 | let x: &u32 = devil(); | |
1451 | // Here we defined the type at the variable creation | |
1452 | ||
1453 | let x: &_ = devil(); | |
1454 | some_func(x); | |
1455 | // Here, the type is determined by the function argument type | |
1456 | } | |
1457 | ||
1458 | fn oh_no() -> ! { panic!("the devil is in the details") } | |
1459 | ||
1460 | fn main() { | |
1461 | demo(oh_no); | |
1462 | } | |
1463 | ``` | |
1464 | "##, | |
1465 | ||
d9579d0f AL |
1466 | E0106: r##" |
1467 | This error indicates that a lifetime is missing from a type. If it is an error | |
1468 | inside a function signature, the problem may be with failing to adhere to the | |
1469 | lifetime elision rules (see below). | |
1470 | ||
1471 | Here are some simple examples of where you'll run into this error: | |
1472 | ||
7453a54e | 1473 | ```compile_fail |
d9579d0f AL |
1474 | struct Foo { x: &bool } // error |
1475 | struct Foo<'a> { x: &'a bool } // correct | |
1476 | ||
1477 | enum Bar { A(u8), B(&bool), } // error | |
1478 | enum Bar<'a> { A(u8), B(&'a bool), } // correct | |
1479 | ||
1480 | type MyStr = &str; // error | |
b039eaaf | 1481 | type MyStr<'a> = &'a str; // correct |
d9579d0f AL |
1482 | ``` |
1483 | ||
1484 | Lifetime elision is a special, limited kind of inference for lifetimes in | |
1485 | function signatures which allows you to leave out lifetimes in certain cases. | |
1486 | For more background on lifetime elision see [the book][book-le]. | |
1487 | ||
1488 | The lifetime elision rules require that any function signature with an elided | |
1489 | output lifetime must either have | |
1490 | ||
1491 | - exactly one input lifetime | |
1492 | - or, multiple input lifetimes, but the function must also be a method with a | |
1493 | `&self` or `&mut self` receiver | |
1494 | ||
1495 | In the first case, the output lifetime is inferred to be the same as the unique | |
1496 | input lifetime. In the second case, the lifetime is instead inferred to be the | |
1497 | same as the lifetime on `&self` or `&mut self`. | |
1498 | ||
1499 | Here are some examples of elision errors: | |
1500 | ||
7453a54e | 1501 | ```compile_fail |
d9579d0f | 1502 | // error, no input lifetimes |
7453a54e | 1503 | fn foo() -> &str { } |
d9579d0f AL |
1504 | |
1505 | // error, `x` and `y` have distinct lifetimes inferred | |
7453a54e | 1506 | fn bar(x: &str, y: &str) -> &str { } |
d9579d0f AL |
1507 | |
1508 | // error, `y`'s lifetime is inferred to be distinct from `x`'s | |
7453a54e | 1509 | fn baz<'a>(x: &'a str, y: &str) -> &str { } |
d9579d0f AL |
1510 | ``` |
1511 | ||
e9174d1e | 1512 | [book-le]: https://doc.rust-lang.org/nightly/book/lifetimes.html#lifetime-elision |
d9579d0f AL |
1513 | "##, |
1514 | ||
1515 | E0107: r##" | |
1516 | This error means that an incorrect number of lifetime parameters were provided | |
1517 | for a type (like a struct or enum) or trait. | |
1518 | ||
1519 | Some basic examples include: | |
1520 | ||
7453a54e | 1521 | ```compile_fail |
d9579d0f AL |
1522 | struct Foo<'a>(&'a str); |
1523 | enum Bar { A, B, C } | |
1524 | ||
1525 | struct Baz<'a> { | |
1526 | foo: Foo, // error: expected 1, found 0 | |
1527 | bar: Bar<'a>, // error: expected 0, found 1 | |
1528 | } | |
1529 | ``` | |
1530 | ||
1531 | Here's an example that is currently an error, but may work in a future version | |
1532 | of Rust: | |
1533 | ||
7453a54e | 1534 | ```compile_fail |
d9579d0f AL |
1535 | struct Foo<'a>(&'a str); |
1536 | ||
1537 | trait Quux { } | |
1538 | impl Quux for Foo { } // error: expected 1, found 0 | |
1539 | ``` | |
1540 | ||
1541 | Lifetime elision in implementation headers was part of the lifetime elision | |
1542 | RFC. It is, however, [currently unimplemented][iss15872]. | |
1543 | ||
1544 | [iss15872]: https://github.com/rust-lang/rust/issues/15872 | |
1545 | "##, | |
1546 | ||
62682a34 SL |
1547 | E0116: r##" |
1548 | You can only define an inherent implementation for a type in the same crate | |
1549 | where the type was defined. For example, an `impl` block as below is not allowed | |
1550 | since `Vec` is defined in the standard library: | |
1551 | ||
7453a54e SL |
1552 | ```compile_fail |
1553 | impl Vec<u8> { } // error | |
62682a34 SL |
1554 | ``` |
1555 | ||
1556 | To fix this problem, you can do either of these things: | |
1557 | ||
1558 | - define a trait that has the desired associated functions/types/constants and | |
1559 | implement the trait for the type in question | |
1560 | - define a new type wrapping the type and define an implementation on the new | |
1561 | type | |
1562 | ||
1563 | Note that using the `type` keyword does not work here because `type` only | |
1564 | introduces a type alias: | |
1565 | ||
7453a54e | 1566 | ```compile_fail |
62682a34 SL |
1567 | type Bytes = Vec<u8>; |
1568 | ||
7453a54e | 1569 | impl Bytes { } // error, same as above |
62682a34 SL |
1570 | ``` |
1571 | "##, | |
1572 | ||
c1a9b12d SL |
1573 | E0117: r##" |
1574 | This error indicates a violation of one of Rust's orphan rules for trait | |
1575 | implementations. The rule prohibits any implementation of a foreign trait (a | |
1576 | trait defined in another crate) where | |
62682a34 | 1577 | |
c1a9b12d SL |
1578 | - the type that is implementing the trait is foreign |
1579 | - all of the parameters being passed to the trait (if there are any) are also | |
1580 | foreign. | |
62682a34 | 1581 | |
c1a9b12d | 1582 | Here's one example of this error: |
62682a34 | 1583 | |
7453a54e | 1584 | ```compile_fail |
c1a9b12d SL |
1585 | impl Drop for u32 {} |
1586 | ``` | |
d9579d0f | 1587 | |
c1a9b12d SL |
1588 | To avoid this kind of error, ensure that at least one local type is referenced |
1589 | by the `impl`: | |
d9579d0f | 1590 | |
7453a54e | 1591 | ```ignore |
c1a9b12d SL |
1592 | pub struct Foo; // you define your type in your crate |
1593 | ||
1594 | impl Drop for Foo { // and you can implement the trait on it! | |
1595 | // code of trait implementation here | |
1596 | } | |
1597 | ||
1598 | impl From<Foo> for i32 { // or you use a type from your crate as | |
1599 | // a type parameter | |
1600 | fn from(i: Foo) -> i32 { | |
1601 | 0 | |
1602 | } | |
1603 | } | |
d9579d0f | 1604 | ``` |
d9579d0f | 1605 | |
c1a9b12d | 1606 | Alternatively, define a trait locally and implement that instead: |
d9579d0f AL |
1607 | |
1608 | ``` | |
c1a9b12d SL |
1609 | trait Bar { |
1610 | fn get(&self) -> usize; | |
1611 | } | |
1612 | ||
1613 | impl Bar for u32 { | |
1614 | fn get(&self) -> usize { 0 } | |
1615 | } | |
d9579d0f AL |
1616 | ``` |
1617 | ||
c1a9b12d | 1618 | For information on the design of the orphan rules, see [RFC 1023]. |
d9579d0f | 1619 | |
c1a9b12d SL |
1620 | [RFC 1023]: https://github.com/rust-lang/rfcs/pull/1023 |
1621 | "##, | |
62682a34 | 1622 | |
e9174d1e | 1623 | E0118: r##" |
7453a54e SL |
1624 | You're trying to write an inherent implementation for something which isn't a |
1625 | struct nor an enum. Erroneous code example: | |
1626 | ||
1627 | ```compile_fail | |
1628 | impl (u8, u8) { // error: no base type found for inherent implementation | |
1629 | fn get_state(&self) -> String { | |
1630 | // ... | |
1631 | } | |
1632 | } | |
1633 | ``` | |
1634 | ||
1635 | To fix this error, please implement a trait on the type or wrap it in a struct. | |
1636 | Example: | |
e9174d1e SL |
1637 | |
1638 | ``` | |
7453a54e SL |
1639 | // we create a trait here |
1640 | trait LiveLongAndProsper { | |
1641 | fn get_state(&self) -> String; | |
1642 | } | |
1643 | ||
1644 | // and now you can implement it on (u8, u8) | |
1645 | impl LiveLongAndProsper for (u8, u8) { | |
1646 | fn get_state(&self) -> String { | |
1647 | "He's dead, Jim!".to_owned() | |
1648 | } | |
e9174d1e SL |
1649 | } |
1650 | ``` | |
1651 | ||
7453a54e SL |
1652 | Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct. |
1653 | For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`. | |
1654 | Example: | |
e9174d1e SL |
1655 | |
1656 | ``` | |
7453a54e SL |
1657 | struct TypeWrapper((u8, u8)); |
1658 | ||
1659 | impl TypeWrapper { | |
1660 | fn get_state(&self) -> String { | |
1661 | "Fascinating!".to_owned() | |
1662 | } | |
1663 | } | |
e9174d1e SL |
1664 | ``` |
1665 | "##, | |
1666 | ||
c1a9b12d SL |
1667 | E0119: r##" |
1668 | There are conflicting trait implementations for the same type. | |
1669 | Example of erroneous code: | |
62682a34 | 1670 | |
7453a54e | 1671 | ```compile_fail |
c1a9b12d SL |
1672 | trait MyTrait { |
1673 | fn get(&self) -> usize; | |
62682a34 | 1674 | } |
62682a34 | 1675 | |
c1a9b12d SL |
1676 | impl<T> MyTrait for T { |
1677 | fn get(&self) -> usize { 0 } | |
1678 | } | |
62682a34 | 1679 | |
c1a9b12d SL |
1680 | struct Foo { |
1681 | value: usize | |
1682 | } | |
62682a34 | 1683 | |
9cc50fc6 SL |
1684 | impl MyTrait for Foo { // error: conflicting implementations of trait |
1685 | // `MyTrait` for type `Foo` | |
c1a9b12d SL |
1686 | fn get(&self) -> usize { self.value } |
1687 | } | |
1688 | ``` | |
d9579d0f | 1689 | |
c1a9b12d SL |
1690 | When looking for the implementation for the trait, the compiler finds |
1691 | both the `impl<T> MyTrait for T` where T is all types and the `impl | |
1692 | MyTrait for Foo`. Since a trait cannot be implemented multiple times, | |
1693 | this is an error. So, when you write: | |
d9579d0f | 1694 | |
c1a9b12d | 1695 | ``` |
7453a54e SL |
1696 | trait MyTrait { |
1697 | fn get(&self) -> usize; | |
1698 | } | |
1699 | ||
c1a9b12d SL |
1700 | impl<T> MyTrait for T { |
1701 | fn get(&self) -> usize { 0 } | |
1702 | } | |
1703 | ``` | |
62682a34 | 1704 | |
c1a9b12d SL |
1705 | This makes the trait implemented on all types in the scope. So if you |
1706 | try to implement it on another one after that, the implementations will | |
1707 | conflict. Example: | |
62682a34 SL |
1708 | |
1709 | ``` | |
c1a9b12d SL |
1710 | trait MyTrait { |
1711 | fn get(&self) -> usize; | |
62682a34 SL |
1712 | } |
1713 | ||
c1a9b12d SL |
1714 | impl<T> MyTrait for T { |
1715 | fn get(&self) -> usize { 0 } | |
1716 | } | |
62682a34 | 1717 | |
c1a9b12d SL |
1718 | struct Foo; |
1719 | ||
1720 | fn main() { | |
1721 | let f = Foo; | |
1722 | ||
1723 | f.get(); // the trait is implemented so we can use it | |
62682a34 | 1724 | } |
c1a9b12d | 1725 | ``` |
62682a34 SL |
1726 | "##, |
1727 | ||
c1a9b12d SL |
1728 | E0120: r##" |
1729 | An attempt was made to implement Drop on a trait, which is not allowed: only | |
1730 | structs and enums can implement Drop. An example causing this error: | |
62682a34 | 1731 | |
7453a54e | 1732 | ```compile_fail |
c1a9b12d SL |
1733 | trait MyTrait {} |
1734 | ||
1735 | impl Drop for MyTrait { | |
1736 | fn drop(&mut self) {} | |
1737 | } | |
1738 | ``` | |
1739 | ||
1740 | A workaround for this problem is to wrap the trait up in a struct, and implement | |
1741 | Drop on that. An example is shown below: | |
1742 | ||
1743 | ``` | |
1744 | trait MyTrait {} | |
1745 | struct MyWrapper<T: MyTrait> { foo: T } | |
1746 | ||
1747 | impl <T: MyTrait> Drop for MyWrapper<T> { | |
1748 | fn drop(&mut self) {} | |
1749 | } | |
1750 | ||
1751 | ``` | |
1752 | ||
1753 | Alternatively, wrapping trait objects requires something like the following: | |
1754 | ||
1755 | ``` | |
1756 | trait MyTrait {} | |
1757 | ||
1758 | //or Box<MyTrait>, if you wanted an owned trait object | |
1759 | struct MyWrapper<'a> { foo: &'a MyTrait } | |
1760 | ||
1761 | impl <'a> Drop for MyWrapper<'a> { | |
1762 | fn drop(&mut self) {} | |
1763 | } | |
1764 | ``` | |
1765 | "##, | |
1766 | ||
1767 | E0121: r##" | |
1768 | In order to be consistent with Rust's lack of global type inference, type | |
1769 | placeholders are disallowed by design in item signatures. | |
1770 | ||
1771 | Examples of this error include: | |
1772 | ||
7453a54e | 1773 | ```compile_fail |
c1a9b12d SL |
1774 | fn foo() -> _ { 5 } // error, explicitly write out the return type instead |
1775 | ||
1776 | static BAR: _ = "test"; // error, explicitly write out the type instead | |
1777 | ``` | |
1778 | "##, | |
1779 | ||
e9174d1e SL |
1780 | E0122: r##" |
1781 | An attempt was made to add a generic constraint to a type alias. While Rust will | |
1782 | allow this with a warning, it will not currently enforce the constraint. | |
1783 | Consider the example below: | |
1784 | ||
1785 | ``` | |
1786 | trait Foo{} | |
1787 | ||
1788 | type MyType<R: Foo> = (R, ()); | |
1789 | ||
1790 | fn main() { | |
1791 | let t: MyType<u32>; | |
1792 | } | |
1793 | ``` | |
1794 | ||
1795 | We're able to declare a variable of type `MyType<u32>`, despite the fact that | |
1796 | `u32` does not implement `Foo`. As a result, one should avoid using generic | |
1797 | constraints in concert with type aliases. | |
1798 | "##, | |
1799 | ||
c1a9b12d SL |
1800 | E0124: r##" |
1801 | You declared two fields of a struct with the same name. Erroneous code | |
1802 | example: | |
1803 | ||
7453a54e | 1804 | ```compile_fail |
c1a9b12d SL |
1805 | struct Foo { |
1806 | field1: i32, | |
7453a54e | 1807 | field1: i32, // error: field is already declared |
c1a9b12d SL |
1808 | } |
1809 | ``` | |
1810 | ||
1811 | Please verify that the field names have been correctly spelled. Example: | |
1812 | ||
1813 | ``` | |
1814 | struct Foo { | |
1815 | field1: i32, | |
7453a54e | 1816 | field2: i32, // ok! |
c1a9b12d SL |
1817 | } |
1818 | ``` | |
1819 | "##, | |
1820 | ||
1821 | E0128: r##" | |
1822 | Type parameter defaults can only use parameters that occur before them. | |
1823 | Erroneous code example: | |
1824 | ||
7453a54e SL |
1825 | ```compile_fail |
1826 | struct Foo<T=U, U=()> { | |
c1a9b12d SL |
1827 | field1: T, |
1828 | filed2: U, | |
1829 | } | |
1830 | // error: type parameters with a default cannot use forward declared | |
1831 | // identifiers | |
1832 | ``` | |
1833 | ||
1834 | Since type parameters are evaluated in-order, you may be able to fix this issue | |
1835 | by doing: | |
1836 | ||
1837 | ``` | |
7453a54e | 1838 | struct Foo<U=(), T=U> { |
c1a9b12d SL |
1839 | field1: T, |
1840 | filed2: U, | |
1841 | } | |
1842 | ``` | |
1843 | ||
1844 | Please also verify that this wasn't because of a name-clash and rename the type | |
1845 | parameter if so. | |
1846 | "##, | |
1847 | ||
1848 | E0130: r##" | |
1849 | You declared a pattern as an argument in a foreign function declaration. | |
1850 | Erroneous code example: | |
1851 | ||
7453a54e | 1852 | ```compile_fail |
c1a9b12d SL |
1853 | extern { |
1854 | fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign | |
1855 | // function declarations | |
1856 | } | |
1857 | ``` | |
1858 | ||
1859 | Please replace the pattern argument with a regular one. Example: | |
1860 | ||
1861 | ``` | |
1862 | struct SomeStruct { | |
1863 | a: u32, | |
1864 | b: u32, | |
1865 | } | |
1866 | ||
1867 | extern { | |
1868 | fn foo(s: SomeStruct); // ok! | |
1869 | } | |
7453a54e SL |
1870 | ``` |
1871 | ||
1872 | Or: | |
1873 | ||
1874 | ``` | |
c1a9b12d SL |
1875 | extern { |
1876 | fn foo(a: (u32, u32)); // ok! | |
1877 | } | |
1878 | ``` | |
1879 | "##, | |
1880 | ||
1881 | E0131: r##" | |
1882 | It is not possible to define `main` with type parameters, or even with function | |
1883 | parameters. When `main` is present, it must take no arguments and return `()`. | |
e9174d1e | 1884 | Erroneous code example: |
c1a9b12d | 1885 | |
7453a54e | 1886 | ```compile_fail |
e9174d1e SL |
1887 | fn main<T>() { // error: main function is not allowed to have type parameters |
1888 | } | |
c1a9b12d SL |
1889 | ``` |
1890 | "##, | |
1891 | ||
e9174d1e SL |
1892 | E0132: r##" |
1893 | It is not possible to declare type parameters on a function that has the `start` | |
1894 | attribute. Such a function must have the following type signature: | |
c1a9b12d | 1895 | |
7453a54e | 1896 | ```ignore |
e9174d1e | 1897 | fn(isize, *const *const u8) -> isize; |
c1a9b12d SL |
1898 | ``` |
1899 | "##, | |
1900 | ||
b039eaaf SL |
1901 | E0163: r##" |
1902 | This error means that an attempt was made to match an enum variant as a | |
1903 | struct type when the variant isn't a struct type: | |
1904 | ||
7453a54e | 1905 | ```compile_fail |
b039eaaf SL |
1906 | enum Foo { B(u32) } |
1907 | ||
1908 | fn bar(foo: Foo) -> u32 { | |
1909 | match foo { | |
7453a54e | 1910 | B{i} => i, // error E0163 |
b039eaaf SL |
1911 | } |
1912 | } | |
1913 | ``` | |
1914 | ||
1915 | Try using `()` instead: | |
1916 | ||
1917 | ``` | |
7453a54e SL |
1918 | enum Foo { B(u32) } |
1919 | ||
b039eaaf SL |
1920 | fn bar(foo: Foo) -> u32 { |
1921 | match foo { | |
7453a54e | 1922 | Foo::B(i) => i, |
b039eaaf SL |
1923 | } |
1924 | } | |
1925 | ``` | |
1926 | "##, | |
1927 | ||
1928 | E0164: r##" | |
b039eaaf SL |
1929 | This error means that an attempt was made to match a struct type enum |
1930 | variant as a non-struct type: | |
1931 | ||
7453a54e SL |
1932 | ```compile_fail |
1933 | enum Foo { B { i: u32 } } | |
b039eaaf SL |
1934 | |
1935 | fn bar(foo: Foo) -> u32 { | |
1936 | match foo { | |
7453a54e | 1937 | Foo::B(i) => i, // error E0164 |
b039eaaf SL |
1938 | } |
1939 | } | |
1940 | ``` | |
1941 | ||
1942 | Try using `{}` instead: | |
1943 | ||
1944 | ``` | |
7453a54e SL |
1945 | enum Foo { B { i: u32 } } |
1946 | ||
b039eaaf SL |
1947 | fn bar(foo: Foo) -> u32 { |
1948 | match foo { | |
7453a54e | 1949 | Foo::B{i} => i, |
b039eaaf SL |
1950 | } |
1951 | } | |
1952 | ``` | |
1953 | "##, | |
1954 | ||
c1a9b12d SL |
1955 | E0166: r##" |
1956 | This error means that the compiler found a return expression in a function | |
1957 | marked as diverging. A function diverges if it has `!` in the place of the | |
1958 | return type in its signature. For example: | |
1959 | ||
7453a54e | 1960 | ```compile_fail |
c1a9b12d SL |
1961 | fn foo() -> ! { return; } // error |
1962 | ``` | |
1963 | ||
1964 | For a function that diverges, every control path in the function must never | |
1965 | return, for example with a `loop` that never breaks or a call to another | |
1966 | diverging function (such as `panic!()`). | |
1967 | "##, | |
1968 | ||
1969 | E0172: r##" | |
1970 | This error means that an attempt was made to specify the type of a variable with | |
1971 | a combination of a concrete type and a trait. Consider the following example: | |
1972 | ||
7453a54e | 1973 | ```compile_fail |
c1a9b12d SL |
1974 | fn foo(bar: i32+std::fmt::Display) {} |
1975 | ``` | |
1976 | ||
1977 | The code is trying to specify that we want to receive a signed 32-bit integer | |
1978 | which also implements `Display`. This doesn't make sense: when we pass `i32`, a | |
1979 | concrete type, it implicitly includes all of the traits that it implements. | |
1980 | This includes `Display`, `Debug`, `Clone`, and a host of others. | |
1981 | ||
1982 | If `i32` implements the trait we desire, there's no need to specify the trait | |
1983 | separately. If it does not, then we need to `impl` the trait for `i32` before | |
1984 | passing it into `foo`. Either way, a fixed definition for `foo` will look like | |
1985 | the following: | |
1986 | ||
1987 | ``` | |
1988 | fn foo(bar: i32) {} | |
1989 | ``` | |
1990 | ||
1991 | To learn more about traits, take a look at the Book: | |
1992 | ||
1993 | https://doc.rust-lang.org/book/traits.html | |
1994 | "##, | |
1995 | ||
1996 | E0178: r##" | |
1997 | In types, the `+` type operator has low precedence, so it is often necessary | |
1998 | to use parentheses. | |
1999 | ||
2000 | For example: | |
2001 | ||
7453a54e | 2002 | ```compile_fail |
c1a9b12d SL |
2003 | trait Foo {} |
2004 | ||
2005 | struct Bar<'a> { | |
2006 | w: &'a Foo + Copy, // error, use &'a (Foo + Copy) | |
2007 | x: &'a Foo + 'a, // error, use &'a (Foo + 'a) | |
2008 | y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a) | |
2009 | z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a) | |
2010 | } | |
2011 | ``` | |
2012 | ||
2013 | More details can be found in [RFC 438]. | |
2014 | ||
2015 | [RFC 438]: https://github.com/rust-lang/rfcs/pull/438 | |
2016 | "##, | |
2017 | ||
2018 | E0184: r##" | |
2019 | Explicitly implementing both Drop and Copy for a type is currently disallowed. | |
2020 | This feature can make some sense in theory, but the current implementation is | |
2021 | incorrect and can lead to memory unsafety (see [issue #20126][iss20126]), so | |
2022 | it has been disabled for now. | |
2023 | ||
2024 | [iss20126]: https://github.com/rust-lang/rust/issues/20126 | |
2025 | "##, | |
2026 | ||
2027 | E0185: r##" | |
2028 | An associated function for a trait was defined to be static, but an | |
2029 | implementation of the trait declared the same function to be a method (i.e. to | |
2030 | take a `self` parameter). | |
2031 | ||
2032 | Here's an example of this error: | |
2033 | ||
7453a54e | 2034 | ```compile_fail |
c1a9b12d SL |
2035 | trait Foo { |
2036 | fn foo(); | |
2037 | } | |
2038 | ||
2039 | struct Bar; | |
2040 | ||
2041 | impl Foo for Bar { | |
2042 | // error, method `foo` has a `&self` declaration in the impl, but not in | |
2043 | // the trait | |
2044 | fn foo(&self) {} | |
2045 | } | |
2046 | "##, | |
2047 | ||
2048 | E0186: r##" | |
2049 | An associated function for a trait was defined to be a method (i.e. to take a | |
2050 | `self` parameter), but an implementation of the trait declared the same function | |
2051 | to be static. | |
2052 | ||
2053 | Here's an example of this error: | |
2054 | ||
7453a54e | 2055 | ```compile_fail |
c1a9b12d SL |
2056 | trait Foo { |
2057 | fn foo(&self); | |
62682a34 SL |
2058 | } |
2059 | ||
2060 | struct Bar; | |
2061 | ||
2062 | impl Foo for Bar { | |
2063 | // error, method `foo` has a `&self` declaration in the trait, but not in | |
2064 | // the impl | |
2065 | fn foo() {} | |
2066 | } | |
c1a9b12d SL |
2067 | ``` |
2068 | "##, | |
2069 | ||
2070 | E0191: r##" | |
2071 | Trait objects need to have all associated types specified. Erroneous code | |
2072 | example: | |
2073 | ||
7453a54e | 2074 | ```compile_fail |
c1a9b12d SL |
2075 | trait Trait { |
2076 | type Bar; | |
2077 | } | |
2078 | ||
2079 | type Foo = Trait; // error: the value of the associated type `Bar` (from | |
2080 | // the trait `Trait`) must be specified | |
2081 | ``` | |
2082 | ||
2083 | Please verify you specified all associated types of the trait and that you | |
2084 | used the right trait. Example: | |
2085 | ||
2086 | ``` | |
2087 | trait Trait { | |
2088 | type Bar; | |
2089 | } | |
2090 | ||
2091 | type Foo = Trait<Bar=i32>; // ok! | |
2092 | ``` | |
62682a34 SL |
2093 | "##, |
2094 | ||
2095 | E0192: r##" | |
2096 | Negative impls are only allowed for traits with default impls. For more | |
2097 | information see the [opt-in builtin traits RFC](https://github.com/rust-lang/ | |
2098 | rfcs/blob/master/text/0019-opt-in-builtin-traits.md). | |
2099 | "##, | |
2100 | ||
e9174d1e SL |
2101 | E0193: r##" |
2102 | `where` clauses must use generic type parameters: it does not make sense to use | |
2103 | them otherwise. An example causing this error: | |
2104 | ||
7453a54e | 2105 | ```compile_fail |
e9174d1e SL |
2106 | trait Foo { |
2107 | fn bar(&self); | |
2108 | } | |
2109 | ||
2110 | #[derive(Copy,Clone)] | |
2111 | struct Wrapper<T> { | |
2112 | Wrapped: T | |
2113 | } | |
2114 | ||
2115 | impl Foo for Wrapper<u32> where Wrapper<u32>: Clone { | |
2116 | fn bar(&self) { } | |
2117 | } | |
2118 | ``` | |
2119 | ||
2120 | This use of a `where` clause is strange - a more common usage would look | |
2121 | something like the following: | |
2122 | ||
2123 | ``` | |
7453a54e SL |
2124 | trait Foo { |
2125 | fn bar(&self); | |
2126 | } | |
2127 | ||
2128 | #[derive(Copy,Clone)] | |
2129 | struct Wrapper<T> { | |
2130 | Wrapped: T | |
2131 | } | |
e9174d1e SL |
2132 | impl <T> Foo for Wrapper<T> where Wrapper<T>: Clone { |
2133 | fn bar(&self) { } | |
2134 | } | |
2135 | ``` | |
2136 | ||
2137 | Here, we're saying that the implementation exists on Wrapper only when the | |
2138 | wrapped type `T` implements `Clone`. The `where` clause is important because | |
2139 | some types will not implement `Clone`, and thus will not get this method. | |
2140 | ||
2141 | In our erroneous example, however, we're referencing a single concrete type. | |
b039eaaf SL |
2142 | Since we know for certain that `Wrapper<u32>` implements `Clone`, there's no |
2143 | reason to also specify it in a `where` clause. | |
e9174d1e SL |
2144 | "##, |
2145 | ||
2146 | E0194: r##" | |
2147 | A type parameter was declared which shadows an existing one. An example of this | |
2148 | error: | |
2149 | ||
7453a54e | 2150 | ```compile_fail |
e9174d1e SL |
2151 | trait Foo<T> { |
2152 | fn do_something(&self) -> T; | |
2153 | fn do_something_else<T: Clone>(&self, bar: T); | |
2154 | } | |
2155 | ``` | |
2156 | ||
2157 | In this example, the trait `Foo` and the trait method `do_something_else` both | |
2158 | define a type parameter `T`. This is not allowed: if the method wishes to | |
2159 | define a type parameter, it must use a different name for it. | |
2160 | "##, | |
2161 | ||
c1a9b12d SL |
2162 | E0195: r##" |
2163 | Your method's lifetime parameters do not match the trait declaration. | |
2164 | Erroneous code example: | |
2165 | ||
7453a54e | 2166 | ```compile_fail |
c1a9b12d SL |
2167 | trait Trait { |
2168 | fn bar<'a,'b:'a>(x: &'a str, y: &'b str); | |
2169 | } | |
2170 | ||
2171 | struct Foo; | |
2172 | ||
2173 | impl Trait for Foo { | |
2174 | fn bar<'a,'b>(x: &'a str, y: &'b str) { | |
2175 | // error: lifetime parameters or bounds on method `bar` | |
2176 | // do not match the trait declaration | |
2177 | } | |
2178 | } | |
2179 | ``` | |
2180 | ||
2181 | The lifetime constraint `'b` for bar() implementation does not match the | |
2182 | trait declaration. Ensure lifetime declarations match exactly in both trait | |
2183 | declaration and implementation. Example: | |
2184 | ||
2185 | ``` | |
2186 | trait Trait { | |
2187 | fn t<'a,'b:'a>(x: &'a str, y: &'b str); | |
2188 | } | |
2189 | ||
2190 | struct Foo; | |
2191 | ||
2192 | impl Trait for Foo { | |
2193 | fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok! | |
2194 | } | |
2195 | } | |
2196 | ``` | |
2197 | "##, | |
2198 | ||
d9579d0f AL |
2199 | E0197: r##" |
2200 | Inherent implementations (one that do not implement a trait but provide | |
2201 | methods associated with a type) are always safe because they are not | |
2202 | implementing an unsafe trait. Removing the `unsafe` keyword from the inherent | |
2203 | implementation will resolve this error. | |
2204 | ||
7453a54e | 2205 | ```compile_fail |
d9579d0f AL |
2206 | struct Foo; |
2207 | ||
2208 | // this will cause this error | |
2209 | unsafe impl Foo { } | |
2210 | // converting it to this will fix it | |
2211 | impl Foo { } | |
2212 | ``` | |
d9579d0f AL |
2213 | "##, |
2214 | ||
2215 | E0198: r##" | |
2216 | A negative implementation is one that excludes a type from implementing a | |
2217 | particular trait. Not being able to use a trait is always a safe operation, | |
2218 | so negative implementations are always safe and never need to be marked as | |
2219 | unsafe. | |
2220 | ||
7453a54e SL |
2221 | ```compile_fail |
2222 | #![feature(optin_builtin_traits)] | |
2223 | ||
d9579d0f AL |
2224 | struct Foo; |
2225 | ||
2226 | // unsafe is unnecessary | |
2227 | unsafe impl !Clone for Foo { } | |
d9579d0f | 2228 | ``` |
7453a54e SL |
2229 | |
2230 | This will compile: | |
2231 | ||
2232 | ``` | |
2233 | #![feature(optin_builtin_traits)] | |
2234 | ||
2235 | struct Foo; | |
2236 | ||
2237 | trait Enterprise {} | |
2238 | ||
2239 | impl Enterprise for .. { } | |
2240 | ||
2241 | impl !Enterprise for Foo { } | |
2242 | ``` | |
2243 | ||
2244 | Please note that negative impls are only allowed for traits with default impls. | |
d9579d0f AL |
2245 | "##, |
2246 | ||
2247 | E0199: r##" | |
2248 | Safe traits should not have unsafe implementations, therefore marking an | |
7453a54e SL |
2249 | implementation for a safe trait unsafe will cause a compiler error. Removing |
2250 | the unsafe marker on the trait noted in the error will resolve this problem. | |
d9579d0f | 2251 | |
7453a54e | 2252 | ```compile_fail |
d9579d0f AL |
2253 | struct Foo; |
2254 | ||
2255 | trait Bar { } | |
2256 | ||
2257 | // this won't compile because Bar is safe | |
2258 | unsafe impl Bar for Foo { } | |
2259 | // this will compile | |
2260 | impl Bar for Foo { } | |
2261 | ``` | |
d9579d0f AL |
2262 | "##, |
2263 | ||
2264 | E0200: r##" | |
2265 | Unsafe traits must have unsafe implementations. This error occurs when an | |
2266 | implementation for an unsafe trait isn't marked as unsafe. This may be resolved | |
2267 | by marking the unsafe implementation as unsafe. | |
2268 | ||
7453a54e | 2269 | ```compile_fail |
d9579d0f AL |
2270 | struct Foo; |
2271 | ||
2272 | unsafe trait Bar { } | |
2273 | ||
2274 | // this won't compile because Bar is unsafe and impl isn't unsafe | |
2275 | impl Bar for Foo { } | |
2276 | // this will compile | |
2277 | unsafe impl Bar for Foo { } | |
2278 | ``` | |
d9579d0f AL |
2279 | "##, |
2280 | ||
2281 | E0201: r##" | |
c1a9b12d SL |
2282 | It is an error to define two associated items (like methods, associated types, |
2283 | associated functions, etc.) with the same identifier. | |
d9579d0f | 2284 | |
62682a34 | 2285 | For example: |
d9579d0f | 2286 | |
7453a54e | 2287 | ```compile_fail |
d9579d0f AL |
2288 | struct Foo(u8); |
2289 | ||
2290 | impl Foo { | |
62682a34 | 2291 | fn bar(&self) -> bool { self.0 > 5 } |
c1a9b12d | 2292 | fn bar() {} // error: duplicate associated function |
62682a34 SL |
2293 | } |
2294 | ||
2295 | trait Baz { | |
c1a9b12d | 2296 | type Quux; |
62682a34 SL |
2297 | fn baz(&self) -> bool; |
2298 | } | |
2299 | ||
2300 | impl Baz for Foo { | |
c1a9b12d SL |
2301 | type Quux = u32; |
2302 | ||
62682a34 | 2303 | fn baz(&self) -> bool { true } |
d9579d0f AL |
2304 | |
2305 | // error: duplicate method | |
62682a34 | 2306 | fn baz(&self) -> bool { self.0 > 5 } |
c1a9b12d SL |
2307 | |
2308 | // error: duplicate associated type | |
2309 | type Quux = u32; | |
d9579d0f AL |
2310 | } |
2311 | ``` | |
54a0048b SL |
2312 | |
2313 | Note, however, that items with the same name are allowed for inherent `impl` | |
2314 | blocks that don't overlap: | |
2315 | ||
2316 | ``` | |
2317 | struct Foo<T>(T); | |
2318 | ||
2319 | impl Foo<u8> { | |
2320 | fn bar(&self) -> bool { self.0 > 5 } | |
2321 | } | |
2322 | ||
2323 | impl Foo<bool> { | |
2324 | fn bar(&self) -> bool { self.0 } | |
2325 | } | |
2326 | ``` | |
d9579d0f AL |
2327 | "##, |
2328 | ||
62682a34 SL |
2329 | E0202: r##" |
2330 | Inherent associated types were part of [RFC 195] but are not yet implemented. | |
2331 | See [the tracking issue][iss8995] for the status of this implementation. | |
2332 | ||
2333 | [RFC 195]: https://github.com/rust-lang/rfcs/pull/195 | |
2334 | [iss8995]: https://github.com/rust-lang/rust/issues/8995 | |
2335 | "##, | |
2336 | ||
d9579d0f AL |
2337 | E0204: r##" |
2338 | An attempt to implement the `Copy` trait for a struct failed because one of the | |
2339 | fields does not implement `Copy`. To fix this, you must implement `Copy` for the | |
2340 | mentioned field. Note that this may not be possible, as in the example of | |
2341 | ||
7453a54e | 2342 | ```compile_fail |
d9579d0f AL |
2343 | struct Foo { |
2344 | foo : Vec<u32>, | |
2345 | } | |
2346 | ||
2347 | impl Copy for Foo { } | |
2348 | ``` | |
2349 | ||
2350 | This fails because `Vec<T>` does not implement `Copy` for any `T`. | |
2351 | ||
2352 | Here's another example that will fail: | |
2353 | ||
7453a54e | 2354 | ```compile_fail |
d9579d0f AL |
2355 | #[derive(Copy)] |
2356 | struct Foo<'a> { | |
2357 | ty: &'a mut bool, | |
2358 | } | |
2359 | ``` | |
2360 | ||
2361 | This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this | |
2362 | differs from the behavior for `&T`, which is always `Copy`). | |
2363 | "##, | |
2364 | ||
2365 | E0205: r##" | |
2366 | An attempt to implement the `Copy` trait for an enum failed because one of the | |
2367 | variants does not implement `Copy`. To fix this, you must implement `Copy` for | |
2368 | the mentioned variant. Note that this may not be possible, as in the example of | |
2369 | ||
7453a54e | 2370 | ```compile_fail |
d9579d0f AL |
2371 | enum Foo { |
2372 | Bar(Vec<u32>), | |
2373 | Baz, | |
2374 | } | |
2375 | ||
2376 | impl Copy for Foo { } | |
2377 | ``` | |
2378 | ||
2379 | This fails because `Vec<T>` does not implement `Copy` for any `T`. | |
2380 | ||
2381 | Here's another example that will fail: | |
2382 | ||
7453a54e | 2383 | ```compile_fail |
d9579d0f AL |
2384 | #[derive(Copy)] |
2385 | enum Foo<'a> { | |
2386 | Bar(&'a mut bool), | |
2387 | Baz | |
2388 | } | |
2389 | ``` | |
2390 | ||
2391 | This fails because `&mut T` is not `Copy`, even when `T` is `Copy` (this | |
2392 | differs from the behavior for `&T`, which is always `Copy`). | |
2393 | "##, | |
2394 | ||
2395 | E0206: r##" | |
2396 | You can only implement `Copy` for a struct or enum. Both of the following | |
2397 | examples will fail, because neither `i32` (primitive type) nor `&'static Bar` | |
2398 | (reference to `Bar`) is a struct or enum: | |
2399 | ||
7453a54e | 2400 | ```compile_fail |
d9579d0f AL |
2401 | type Foo = i32; |
2402 | impl Copy for Foo { } // error | |
2403 | ||
2404 | #[derive(Copy, Clone)] | |
2405 | struct Bar; | |
2406 | impl Copy for &'static Bar { } // error | |
2407 | ``` | |
2408 | "##, | |
2409 | ||
c1a9b12d SL |
2410 | E0207: r##" |
2411 | You declared an unused type parameter when implementing a trait on an object. | |
2412 | Erroneous code example: | |
2413 | ||
7453a54e | 2414 | ```compile_fail |
c1a9b12d SL |
2415 | trait MyTrait { |
2416 | fn get(&self) -> usize; | |
2417 | } | |
2418 | ||
2419 | struct Foo; | |
2420 | ||
2421 | impl<T> MyTrait for Foo { | |
2422 | fn get(&self) -> usize { | |
2423 | 0 | |
2424 | } | |
2425 | } | |
2426 | ``` | |
2427 | ||
2428 | Please check your object definition and remove unused type | |
2429 | parameter(s). Example: | |
2430 | ||
2431 | ``` | |
2432 | trait MyTrait { | |
2433 | fn get(&self) -> usize; | |
2434 | } | |
2435 | ||
2436 | struct Foo; | |
2437 | ||
2438 | impl MyTrait for Foo { | |
2439 | fn get(&self) -> usize { | |
2440 | 0 | |
2441 | } | |
2442 | } | |
2443 | ``` | |
2444 | "##, | |
2445 | ||
2446 | E0210: r##" | |
2447 | This error indicates a violation of one of Rust's orphan rules for trait | |
2448 | implementations. The rule concerns the use of type parameters in an | |
2449 | implementation of a foreign trait (a trait defined in another crate), and | |
2450 | states that type parameters must be "covered" by a local type. To understand | |
2451 | what this means, it is perhaps easiest to consider a few examples. | |
2452 | ||
2453 | If `ForeignTrait` is a trait defined in some external crate `foo`, then the | |
2454 | following trait `impl` is an error: | |
2455 | ||
7453a54e | 2456 | ```compile_fail |
c1a9b12d SL |
2457 | extern crate foo; |
2458 | use foo::ForeignTrait; | |
2459 | ||
7453a54e | 2460 | impl<T> ForeignTrait for T { } // error |
c1a9b12d SL |
2461 | ``` |
2462 | ||
2463 | To work around this, it can be covered with a local type, `MyType`: | |
2464 | ||
7453a54e | 2465 | ```ignore |
c1a9b12d | 2466 | struct MyType<T>(T); |
7453a54e | 2467 | impl<T> ForeignTrait for MyType<T> { } // Ok |
c1a9b12d SL |
2468 | ``` |
2469 | ||
7453a54e SL |
2470 | Please note that a type alias is not sufficient. |
2471 | ||
c1a9b12d SL |
2472 | For another example of an error, suppose there's another trait defined in `foo` |
2473 | named `ForeignTrait2` that takes two type parameters. Then this `impl` results | |
2474 | in the same rule violation: | |
2475 | ||
7453a54e | 2476 | ```compile_fail |
c1a9b12d | 2477 | struct MyType2; |
7453a54e | 2478 | impl<T> ForeignTrait2<T, MyType<T>> for MyType2 { } // error |
c1a9b12d SL |
2479 | ``` |
2480 | ||
2481 | The reason for this is that there are two appearances of type parameter `T` in | |
2482 | the `impl` header, both as parameters for `ForeignTrait2`. The first appearance | |
2483 | is uncovered, and so runs afoul of the orphan rule. | |
2484 | ||
2485 | Consider one more example: | |
2486 | ||
7453a54e SL |
2487 | ```ignore |
2488 | impl<T> ForeignTrait2<MyType<T>, T> for MyType2 { } // Ok | |
c1a9b12d SL |
2489 | ``` |
2490 | ||
2491 | This only differs from the previous `impl` in that the parameters `T` and | |
2492 | `MyType<T>` for `ForeignTrait2` have been swapped. This example does *not* | |
2493 | violate the orphan rule; it is permitted. | |
2494 | ||
2495 | To see why that last example was allowed, you need to understand the general | |
2496 | rule. Unfortunately this rule is a bit tricky to state. Consider an `impl`: | |
2497 | ||
7453a54e | 2498 | ```ignore |
c1a9b12d SL |
2499 | impl<P1, ..., Pm> ForeignTrait<T1, ..., Tn> for T0 { ... } |
2500 | ``` | |
2501 | ||
2502 | where `P1, ..., Pm` are the type parameters of the `impl` and `T0, ..., Tn` | |
2503 | are types. One of the types `T0, ..., Tn` must be a local type (this is another | |
2504 | orphan rule, see the explanation for E0117). Let `i` be the smallest integer | |
2505 | such that `Ti` is a local type. Then no type parameter can appear in any of the | |
2506 | `Tj` for `j < i`. | |
2507 | ||
2508 | For information on the design of the orphan rules, see [RFC 1023]. | |
2509 | ||
2510 | [RFC 1023]: https://github.com/rust-lang/rfcs/pull/1023 | |
2511 | "##, | |
2512 | ||
2513 | E0211: r##" | |
b039eaaf SL |
2514 | You used a function or type which doesn't fit the requirements for where it was |
2515 | used. Erroneous code examples: | |
c1a9b12d | 2516 | |
7453a54e | 2517 | ```compile_fail |
c1a9b12d SL |
2518 | #![feature(intrinsics)] |
2519 | ||
2520 | extern "rust-intrinsic" { | |
2521 | fn size_of<T>(); // error: intrinsic has wrong type | |
2522 | } | |
b039eaaf SL |
2523 | |
2524 | // or: | |
2525 | ||
2526 | fn main() -> i32 { 0 } | |
2527 | // error: main function expects type: `fn() {main}`: expected (), found i32 | |
2528 | ||
2529 | // or: | |
2530 | ||
2531 | let x = 1u8; | |
2532 | match x { | |
2533 | 0u8...3i8 => (), | |
2534 | // error: mismatched types in range: expected u8, found i8 | |
2535 | _ => () | |
2536 | } | |
2537 | ||
2538 | // or: | |
2539 | ||
2540 | use std::rc::Rc; | |
2541 | struct Foo; | |
2542 | ||
2543 | impl Foo { | |
2544 | fn x(self: Rc<Foo>) {} | |
2545 | // error: mismatched self type: expected `Foo`: expected struct | |
2546 | // `Foo`, found struct `alloc::rc::Rc` | |
2547 | } | |
c1a9b12d SL |
2548 | ``` |
2549 | ||
b039eaaf | 2550 | For the first code example, please check the function definition. Example: |
c1a9b12d SL |
2551 | |
2552 | ``` | |
2553 | #![feature(intrinsics)] | |
2554 | ||
2555 | extern "rust-intrinsic" { | |
b039eaaf SL |
2556 | fn size_of<T>() -> usize; // ok! |
2557 | } | |
2558 | ``` | |
2559 | ||
2560 | The second case example is a bit particular : the main function must always | |
2561 | have this definition: | |
2562 | ||
7453a54e | 2563 | ```compile_fail |
b039eaaf SL |
2564 | fn main(); |
2565 | ``` | |
2566 | ||
2567 | They never take parameters and never return types. | |
2568 | ||
2569 | For the third example, when you match, all patterns must have the same type | |
2570 | as the type you're matching on. Example: | |
2571 | ||
2572 | ``` | |
2573 | let x = 1u8; | |
7453a54e | 2574 | |
b039eaaf SL |
2575 | match x { |
2576 | 0u8...3u8 => (), // ok! | |
2577 | _ => () | |
2578 | } | |
2579 | ``` | |
2580 | ||
2581 | And finally, for the last example, only `Box<Self>`, `&Self`, `Self`, | |
2582 | or `&mut Self` work as explicit self parameters. Example: | |
2583 | ||
2584 | ``` | |
2585 | struct Foo; | |
2586 | ||
2587 | impl Foo { | |
2588 | fn x(self: Box<Foo>) {} // ok! | |
c1a9b12d SL |
2589 | } |
2590 | ``` | |
2591 | "##, | |
2592 | ||
e9174d1e SL |
2593 | E0214: r##" |
2594 | A generic type was described using parentheses rather than angle brackets. For | |
2595 | example: | |
2596 | ||
7453a54e | 2597 | ```compile_fail |
e9174d1e SL |
2598 | fn main() { |
2599 | let v: Vec(&str) = vec!["foo"]; | |
2600 | } | |
2601 | ``` | |
2602 | ||
2603 | This is not currently supported: `v` should be defined as `Vec<&str>`. | |
2604 | Parentheses are currently only used with generic types when defining parameters | |
2605 | for `Fn`-family traits. | |
2606 | "##, | |
2607 | ||
c1a9b12d SL |
2608 | E0220: r##" |
2609 | You used an associated type which isn't defined in the trait. | |
2610 | Erroneous code example: | |
2611 | ||
7453a54e | 2612 | ```compile_fail |
c1a9b12d SL |
2613 | trait Trait { |
2614 | type Bar; | |
2615 | } | |
2616 | ||
2617 | type Foo = Trait<F=i32>; // error: associated type `F` not found for | |
2618 | // `Trait` | |
2619 | ``` | |
2620 | ||
2621 | Please verify you used the right trait or you didn't misspell the | |
2622 | associated type name. Example: | |
2623 | ||
2624 | ``` | |
2625 | trait Trait { | |
2626 | type Bar; | |
2627 | } | |
2628 | ||
2629 | type Foo = Trait<Bar=i32>; // ok! | |
2630 | ``` | |
2631 | "##, | |
2632 | ||
e9174d1e SL |
2633 | E0221: r##" |
2634 | An attempt was made to retrieve an associated type, but the type was ambiguous. | |
2635 | For example: | |
2636 | ||
7453a54e | 2637 | ```compile_fail |
e9174d1e SL |
2638 | trait T1 {} |
2639 | trait T2 {} | |
2640 | ||
2641 | trait Foo { | |
2642 | type A: T1; | |
2643 | } | |
2644 | ||
2645 | trait Bar : Foo { | |
2646 | type A: T2; | |
2647 | fn do_something() { | |
2648 | let _: Self::A; | |
2649 | } | |
2650 | } | |
2651 | ``` | |
2652 | ||
2653 | In this example, `Foo` defines an associated type `A`. `Bar` inherits that type | |
2654 | from `Foo`, and defines another associated type of the same name. As a result, | |
2655 | when we attempt to use `Self::A`, it's ambiguous whether we mean the `A` defined | |
2656 | by `Foo` or the one defined by `Bar`. | |
2657 | ||
2658 | There are two options to work around this issue. The first is simply to rename | |
2659 | one of the types. Alternatively, one can specify the intended type using the | |
2660 | following syntax: | |
2661 | ||
2662 | ``` | |
7453a54e SL |
2663 | trait T1 {} |
2664 | trait T2 {} | |
2665 | ||
2666 | trait Foo { | |
2667 | type A: T1; | |
2668 | } | |
2669 | ||
2670 | trait Bar : Foo { | |
2671 | type A: T2; | |
2672 | fn do_something() { | |
2673 | let _: <Self as Bar>::A; | |
2674 | } | |
e9174d1e SL |
2675 | } |
2676 | ``` | |
2677 | "##, | |
2678 | ||
c1a9b12d SL |
2679 | E0223: r##" |
2680 | An attempt was made to retrieve an associated type, but the type was ambiguous. | |
2681 | For example: | |
2682 | ||
7453a54e | 2683 | ```compile_fail |
c1a9b12d SL |
2684 | trait MyTrait {type X; } |
2685 | ||
2686 | fn main() { | |
2687 | let foo: MyTrait::X; | |
2688 | } | |
2689 | ``` | |
2690 | ||
2691 | The problem here is that we're attempting to take the type of X from MyTrait. | |
2692 | Unfortunately, the type of X is not defined, because it's only made concrete in | |
2693 | implementations of the trait. A working version of this code might look like: | |
2694 | ||
2695 | ``` | |
2696 | trait MyTrait {type X; } | |
2697 | struct MyStruct; | |
2698 | ||
2699 | impl MyTrait for MyStruct { | |
2700 | type X = u32; | |
2701 | } | |
2702 | ||
2703 | fn main() { | |
2704 | let foo: <MyStruct as MyTrait>::X; | |
2705 | } | |
2706 | ``` | |
2707 | ||
2708 | This syntax specifies that we want the X type from MyTrait, as made concrete in | |
2709 | MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct | |
2710 | might implement two different traits with identically-named associated types. | |
2711 | This syntax allows disambiguation between the two. | |
2712 | "##, | |
2713 | ||
2714 | E0225: r##" | |
2715 | You attempted to use multiple types as bounds for a closure or trait object. | |
2716 | Rust does not currently support this. A simple example that causes this error: | |
2717 | ||
7453a54e | 2718 | ```compile_fail |
c1a9b12d SL |
2719 | fn main() { |
2720 | let _: Box<std::io::Read+std::io::Write>; | |
2721 | } | |
2722 | ``` | |
2723 | ||
2724 | Builtin traits are an exception to this rule: it's possible to have bounds of | |
2725 | one non-builtin type, plus any number of builtin types. For example, the | |
2726 | following compiles correctly: | |
2727 | ||
2728 | ``` | |
2729 | fn main() { | |
2730 | let _: Box<std::io::Read+Copy+Sync>; | |
2731 | } | |
2732 | ``` | |
2733 | "##, | |
2734 | ||
2735 | E0232: r##" | |
2736 | The attribute must have a value. Erroneous code example: | |
2737 | ||
7453a54e SL |
2738 | ```compile_fail |
2739 | #![feature(on_unimplemented)] | |
2740 | ||
c1a9b12d SL |
2741 | #[rustc_on_unimplemented] // error: this attribute must have a value |
2742 | trait Bar {} | |
2743 | ``` | |
2744 | ||
2745 | Please supply the missing value of the attribute. Example: | |
2746 | ||
2747 | ``` | |
7453a54e SL |
2748 | #![feature(on_unimplemented)] |
2749 | ||
c1a9b12d SL |
2750 | #[rustc_on_unimplemented = "foo"] // ok! |
2751 | trait Bar {} | |
2752 | ``` | |
2753 | "##, | |
2754 | ||
d9579d0f AL |
2755 | E0243: r##" |
2756 | This error indicates that not enough type parameters were found in a type or | |
2757 | trait. | |
2758 | ||
2759 | For example, the `Foo` struct below is defined to be generic in `T`, but the | |
2760 | type parameter is missing in the definition of `Bar`: | |
2761 | ||
7453a54e | 2762 | ```compile_fail |
d9579d0f AL |
2763 | struct Foo<T> { x: T } |
2764 | ||
2765 | struct Bar { x: Foo } | |
2766 | ``` | |
2767 | "##, | |
2768 | ||
2769 | E0244: r##" | |
2770 | This error indicates that too many type parameters were found in a type or | |
2771 | trait. | |
2772 | ||
2773 | For example, the `Foo` struct below has no type parameters, but is supplied | |
2774 | with two in the definition of `Bar`: | |
2775 | ||
7453a54e | 2776 | ```compile_fail |
d9579d0f AL |
2777 | struct Foo { x: bool } |
2778 | ||
2779 | struct Bar<S, T> { x: Foo<S, T> } | |
2780 | ``` | |
2781 | "##, | |
2782 | ||
e9174d1e SL |
2783 | E0248: r##" |
2784 | This error indicates an attempt to use a value where a type is expected. For | |
2785 | example: | |
d9579d0f | 2786 | |
7453a54e | 2787 | ```compile_fail |
e9174d1e SL |
2788 | enum Foo { |
2789 | Bar(u32) | |
2790 | } | |
2791 | ||
2792 | fn do_something(x: Foo::Bar) { } | |
2793 | ``` | |
2794 | ||
2795 | In this example, we're attempting to take a type of `Foo::Bar` in the | |
2796 | do_something function. This is not legal: `Foo::Bar` is a value of type `Foo`, | |
2797 | not a distinct static type. Likewise, it's not legal to attempt to | |
2798 | `impl Foo::Bar`: instead, you must `impl Foo` and then pattern match to specify | |
b039eaaf | 2799 | behavior for specific enum variants. |
e9174d1e SL |
2800 | "##, |
2801 | ||
2802 | E0249: r##" | |
2803 | This error indicates a constant expression for the array length was found, but | |
2804 | it was not an integer (signed or unsigned) expression. | |
2805 | ||
2806 | Some examples of code that produces this error are: | |
2807 | ||
7453a54e | 2808 | ```compile_fail |
e9174d1e SL |
2809 | const A: [u32; "hello"] = []; // error |
2810 | const B: [u32; true] = []; // error | |
2811 | const C: [u32; 0.0] = []; // error | |
2812 | "##, | |
2813 | ||
2814 | E0250: r##" | |
2815 | There was an error while evaluating the expression for the length of a fixed- | |
2816 | size array type. | |
2817 | ||
2818 | Some examples of this error are: | |
2819 | ||
7453a54e | 2820 | ```compile_fail |
e9174d1e | 2821 | // divide by zero in the length expression |
d9579d0f AL |
2822 | const A: [u32; 1/0] = []; |
2823 | ||
2824 | // Rust currently will not evaluate the function `foo` at compile time | |
2825 | fn foo() -> usize { 12 } | |
2826 | const B: [u32; foo()] = []; | |
2827 | ||
2828 | // it is an error to try to add `u8` and `f64` | |
2829 | use std::{f64, u8}; | |
2830 | const C: [u32; u8::MAX + f64::EPSILON] = []; | |
2831 | ``` | |
2832 | "##, | |
2833 | ||
62682a34 SL |
2834 | E0318: r##" |
2835 | Default impls for a trait must be located in the same crate where the trait was | |
2836 | defined. For more information see the [opt-in builtin traits RFC](https://github | |
2837 | .com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md). | |
2838 | "##, | |
2839 | ||
92a42be0 SL |
2840 | E0321: r##" |
2841 | A cross-crate opt-out trait was implemented on something which wasn't a struct | |
2842 | or enum type. Erroneous code example: | |
2843 | ||
7453a54e | 2844 | ```compile_fail |
92a42be0 SL |
2845 | #![feature(optin_builtin_traits)] |
2846 | ||
2847 | struct Foo; | |
2848 | ||
2849 | impl !Sync for Foo {} | |
2850 | ||
2851 | unsafe impl Send for &'static Foo { | |
2852 | // error: cross-crate traits with a default impl, like `core::marker::Send`, | |
2853 | // can only be implemented for a struct/enum type, not | |
2854 | // `&'static Foo` | |
2855 | ``` | |
2856 | ||
2857 | Only structs and enums are permitted to impl Send, Sync, and other opt-out | |
2858 | trait, and the struct or enum must be local to the current crate. So, for | |
2859 | example, `unsafe impl Send for Rc<Foo>` is not allowed. | |
2860 | "##, | |
2861 | ||
d9579d0f AL |
2862 | E0322: r##" |
2863 | The `Sized` trait is a special trait built-in to the compiler for types with a | |
2864 | constant size known at compile-time. This trait is automatically implemented | |
2865 | for types as needed by the compiler, and it is currently disallowed to | |
2866 | explicitly implement it for a type. | |
2867 | "##, | |
2868 | ||
e9174d1e SL |
2869 | E0323: r##" |
2870 | An associated const was implemented when another trait item was expected. | |
2871 | Erroneous code example: | |
2872 | ||
7453a54e SL |
2873 | ```compile_fail |
2874 | #![feature(associated_consts)] | |
2875 | ||
e9174d1e SL |
2876 | trait Foo { |
2877 | type N; | |
2878 | } | |
2879 | ||
2880 | struct Bar; | |
2881 | ||
2882 | impl Foo for Bar { | |
2883 | const N : u32 = 0; | |
2884 | // error: item `N` is an associated const, which doesn't match its | |
2885 | // trait `<Bar as Foo>` | |
2886 | } | |
2887 | ``` | |
2888 | ||
2889 | Please verify that the associated const wasn't misspelled and the correct trait | |
2890 | was implemented. Example: | |
2891 | ||
2892 | ``` | |
2893 | struct Bar; | |
2894 | ||
2895 | trait Foo { | |
2896 | type N; | |
2897 | } | |
2898 | ||
2899 | impl Foo for Bar { | |
2900 | type N = u32; // ok! | |
2901 | } | |
7453a54e SL |
2902 | ``` |
2903 | ||
2904 | Or: | |
2905 | ||
2906 | ``` | |
2907 | #![feature(associated_consts)] | |
2908 | ||
2909 | struct Bar; | |
e9174d1e | 2910 | |
e9174d1e SL |
2911 | trait Foo { |
2912 | const N : u32; | |
2913 | } | |
2914 | ||
2915 | impl Foo for Bar { | |
2916 | const N : u32 = 0; // ok! | |
2917 | } | |
2918 | ``` | |
2919 | "##, | |
2920 | ||
2921 | E0324: r##" | |
2922 | A method was implemented when another trait item was expected. Erroneous | |
2923 | code example: | |
2924 | ||
7453a54e | 2925 | ```compile_fail |
e9174d1e SL |
2926 | struct Bar; |
2927 | ||
2928 | trait Foo { | |
2929 | const N : u32; | |
2930 | ||
2931 | fn M(); | |
2932 | } | |
2933 | ||
2934 | impl Foo for Bar { | |
2935 | fn N() {} | |
2936 | // error: item `N` is an associated method, which doesn't match its | |
2937 | // trait `<Bar as Foo>` | |
2938 | } | |
2939 | ``` | |
2940 | ||
2941 | To fix this error, please verify that the method name wasn't misspelled and | |
2942 | verify that you are indeed implementing the correct trait items. Example: | |
2943 | ||
2944 | ``` | |
7453a54e SL |
2945 | #![feature(associated_consts)] |
2946 | ||
e9174d1e SL |
2947 | struct Bar; |
2948 | ||
2949 | trait Foo { | |
2950 | const N : u32; | |
2951 | ||
2952 | fn M(); | |
2953 | } | |
2954 | ||
2955 | impl Foo for Bar { | |
2956 | const N : u32 = 0; | |
2957 | ||
2958 | fn M() {} // ok! | |
2959 | } | |
2960 | ``` | |
2961 | "##, | |
2962 | ||
2963 | E0325: r##" | |
2964 | An associated type was implemented when another trait item was expected. | |
2965 | Erroneous code example: | |
2966 | ||
7453a54e | 2967 | ```compile_fail |
e9174d1e SL |
2968 | struct Bar; |
2969 | ||
2970 | trait Foo { | |
2971 | const N : u32; | |
2972 | } | |
2973 | ||
2974 | impl Foo for Bar { | |
2975 | type N = u32; | |
2976 | // error: item `N` is an associated type, which doesn't match its | |
2977 | // trait `<Bar as Foo>` | |
2978 | } | |
2979 | ``` | |
2980 | ||
2981 | Please verify that the associated type name wasn't misspelled and your | |
2982 | implementation corresponds to the trait definition. Example: | |
2983 | ||
2984 | ``` | |
2985 | struct Bar; | |
2986 | ||
2987 | trait Foo { | |
2988 | type N; | |
2989 | } | |
2990 | ||
2991 | impl Foo for Bar { | |
2992 | type N = u32; // ok! | |
2993 | } | |
7453a54e SL |
2994 | ``` |
2995 | ||
2996 | Or: | |
2997 | ||
2998 | ``` | |
2999 | #![feature(associated_consts)] | |
3000 | ||
3001 | struct Bar; | |
e9174d1e | 3002 | |
e9174d1e SL |
3003 | trait Foo { |
3004 | const N : u32; | |
3005 | } | |
3006 | ||
3007 | impl Foo for Bar { | |
3008 | const N : u32 = 0; // ok! | |
3009 | } | |
3010 | ``` | |
3011 | "##, | |
3012 | ||
62682a34 SL |
3013 | E0326: r##" |
3014 | The types of any associated constants in a trait implementation must match the | |
3015 | types in the trait definition. This error indicates that there was a mismatch. | |
3016 | ||
3017 | Here's an example of this error: | |
3018 | ||
7453a54e | 3019 | ```compile_fail |
62682a34 SL |
3020 | trait Foo { |
3021 | const BAR: bool; | |
3022 | } | |
3023 | ||
3024 | struct Bar; | |
3025 | ||
3026 | impl Foo for Bar { | |
3027 | const BAR: u32 = 5; // error, expected bool, found u32 | |
3028 | } | |
3029 | ``` | |
3030 | "##, | |
3031 | ||
c1a9b12d SL |
3032 | E0327: r##" |
3033 | You cannot use associated items other than constant items as patterns. This | |
3034 | includes method items. Example of erroneous code: | |
3035 | ||
7453a54e | 3036 | ```compile_fail |
c1a9b12d SL |
3037 | enum B {} |
3038 | ||
3039 | impl B { | |
3040 | fn bb() -> i32 { 0 } | |
3041 | } | |
3042 | ||
3043 | fn main() { | |
3044 | match 0 { | |
3045 | B::bb => {} // error: associated items in match patterns must | |
3046 | // be constants | |
3047 | } | |
3048 | } | |
3049 | ``` | |
3050 | ||
3051 | Please check that you're not using a method as a pattern. Example: | |
3052 | ||
3053 | ``` | |
3054 | enum B { | |
3055 | ba, | |
3056 | bb | |
3057 | } | |
3058 | ||
3059 | fn main() { | |
3060 | match B::ba { | |
3061 | B::bb => {} // ok! | |
3062 | _ => {} | |
3063 | } | |
3064 | } | |
3065 | ``` | |
3066 | "##, | |
3067 | ||
e9174d1e SL |
3068 | E0329: r##" |
3069 | An attempt was made to access an associated constant through either a generic | |
3070 | type parameter or `Self`. This is not supported yet. An example causing this | |
3071 | error is shown below: | |
3072 | ||
7453a54e SL |
3073 | ```compile_fail |
3074 | #![feature(associated_consts)] | |
3075 | ||
e9174d1e SL |
3076 | trait Foo { |
3077 | const BAR: f64; | |
3078 | } | |
3079 | ||
3080 | struct MyStruct; | |
3081 | ||
3082 | impl Foo for MyStruct { | |
3083 | const BAR: f64 = 0f64; | |
3084 | } | |
3085 | ||
3086 | fn get_bar_bad<F: Foo>(t: F) -> f64 { | |
3087 | F::BAR | |
3088 | } | |
3089 | ``` | |
3090 | ||
7453a54e SL |
3091 | Currently, the value of `BAR` for a particular type can only be accessed |
3092 | through a concrete type, as shown below: | |
3093 | ||
3094 | ```ignore | |
3095 | #![feature(associated_consts)] | |
3096 | ||
3097 | trait Foo { | |
3098 | const BAR: f64; | |
3099 | } | |
3100 | ||
3101 | struct MyStruct; | |
e9174d1e | 3102 | |
e9174d1e SL |
3103 | fn get_bar_good() -> f64 { |
3104 | <MyStruct as Foo>::BAR | |
3105 | } | |
3106 | ``` | |
3107 | "##, | |
3108 | ||
3109 | E0366: r##" | |
3110 | An attempt was made to implement `Drop` on a concrete specialization of a | |
3111 | generic type. An example is shown below: | |
3112 | ||
7453a54e | 3113 | ```compile_fail |
e9174d1e SL |
3114 | struct Foo<T> { |
3115 | t: T | |
3116 | } | |
3117 | ||
3118 | impl Drop for Foo<u32> { | |
3119 | fn drop(&mut self) {} | |
3120 | } | |
3121 | ``` | |
3122 | ||
3123 | This code is not legal: it is not possible to specialize `Drop` to a subset of | |
3124 | implementations of a generic type. One workaround for this is to wrap the | |
3125 | generic type, as shown below: | |
3126 | ||
3127 | ``` | |
3128 | struct Foo<T> { | |
3129 | t: T | |
3130 | } | |
3131 | ||
3132 | struct Bar { | |
3133 | t: Foo<u32> | |
3134 | } | |
3135 | ||
3136 | impl Drop for Bar { | |
3137 | fn drop(&mut self) {} | |
3138 | } | |
3139 | ``` | |
3140 | "##, | |
3141 | ||
3142 | E0367: r##" | |
3143 | An attempt was made to implement `Drop` on a specialization of a generic type. | |
3144 | An example is shown below: | |
3145 | ||
7453a54e | 3146 | ```compile_fail |
e9174d1e SL |
3147 | trait Foo{} |
3148 | ||
3149 | struct MyStruct<T> { | |
3150 | t: T | |
3151 | } | |
3152 | ||
3153 | impl<T: Foo> Drop for MyStruct<T> { | |
3154 | fn drop(&mut self) {} | |
3155 | } | |
3156 | ``` | |
3157 | ||
3158 | This code is not legal: it is not possible to specialize `Drop` to a subset of | |
3159 | implementations of a generic type. In order for this code to work, `MyStruct` | |
3160 | must also require that `T` implements `Foo`. Alternatively, another option is | |
3161 | to wrap the generic type in another that specializes appropriately: | |
3162 | ||
3163 | ``` | |
3164 | trait Foo{} | |
3165 | ||
3166 | struct MyStruct<T> { | |
3167 | t: T | |
3168 | } | |
3169 | ||
3170 | struct MyStructWrapper<T: Foo> { | |
3171 | t: MyStruct<T> | |
3172 | } | |
3173 | ||
3174 | impl <T: Foo> Drop for MyStructWrapper<T> { | |
3175 | fn drop(&mut self) {} | |
3176 | } | |
3177 | ``` | |
3178 | "##, | |
3179 | ||
d9579d0f AL |
3180 | E0368: r##" |
3181 | This error indicates that a binary assignment operator like `+=` or `^=` was | |
b039eaaf SL |
3182 | applied to a type that doesn't support it. For example: |
3183 | ||
7453a54e | 3184 | ```compile_fail |
b039eaaf | 3185 | let mut x = 12f32; // error: binary operation `<<` cannot be applied to |
7453a54e | 3186 | // type `f32` |
d9579d0f | 3187 | |
b039eaaf | 3188 | x <<= 2; |
d9579d0f | 3189 | ``` |
b039eaaf SL |
3190 | |
3191 | To fix this error, please check that this type implements this binary | |
3192 | operation. Example: | |
3193 | ||
54a0048b SL |
3194 | ``` |
3195 | let mut x = 12u32; // the `u32` type does implement the `ShlAssign` trait | |
b039eaaf SL |
3196 | |
3197 | x <<= 2; // ok! | |
d9579d0f AL |
3198 | ``` |
3199 | ||
b039eaaf SL |
3200 | It is also possible to overload most operators for your own type by |
3201 | implementing the `[OP]Assign` traits from `std::ops`. | |
3202 | ||
d9579d0f AL |
3203 | Another problem you might be facing is this: suppose you've overloaded the `+` |
3204 | operator for some type `Foo` by implementing the `std::ops::Add` trait for | |
3205 | `Foo`, but you find that using `+=` does not work, as in this example: | |
3206 | ||
7453a54e | 3207 | ```compile_fail |
d9579d0f AL |
3208 | use std::ops::Add; |
3209 | ||
3210 | struct Foo(u32); | |
3211 | ||
3212 | impl Add for Foo { | |
3213 | type Output = Foo; | |
3214 | ||
3215 | fn add(self, rhs: Foo) -> Foo { | |
3216 | Foo(self.0 + rhs.0) | |
3217 | } | |
3218 | } | |
3219 | ||
3220 | fn main() { | |
3221 | let mut x: Foo = Foo(5); | |
b039eaaf | 3222 | x += Foo(7); // error, `+= cannot be applied to the type `Foo` |
d9579d0f AL |
3223 | } |
3224 | ``` | |
3225 | ||
b039eaaf SL |
3226 | This is because `AddAssign` is not automatically implemented, so you need to |
3227 | manually implement it for your type. | |
62682a34 SL |
3228 | "##, |
3229 | ||
e9174d1e SL |
3230 | E0369: r##" |
3231 | A binary operation was attempted on a type which doesn't support it. | |
3232 | Erroneous code example: | |
3233 | ||
7453a54e | 3234 | ```compile_fail |
e9174d1e SL |
3235 | let x = 12f32; // error: binary operation `<<` cannot be applied to |
3236 | // type `f32` | |
3237 | ||
3238 | x << 2; | |
3239 | ``` | |
3240 | ||
3241 | To fix this error, please check that this type implements this binary | |
3242 | operation. Example: | |
3243 | ||
3244 | ``` | |
3245 | let x = 12u32; // the `u32` type does implement it: | |
3246 | // https://doc.rust-lang.org/stable/std/ops/trait.Shl.html | |
3247 | ||
3248 | x << 2; // ok! | |
3249 | ``` | |
3250 | ||
3251 | It is also possible to overload most operators for your own type by | |
3252 | implementing traits from `std::ops`. | |
3253 | "##, | |
3254 | ||
3255 | E0370: r##" | |
3256 | The maximum value of an enum was reached, so it cannot be automatically | |
3257 | set in the next enum value. Erroneous code example: | |
3258 | ||
7453a54e | 3259 | ```compile_fail |
e9174d1e SL |
3260 | enum Foo { |
3261 | X = 0x7fffffffffffffff, | |
7453a54e SL |
3262 | Y, // error: enum discriminant overflowed on value after |
3263 | // 9223372036854775807: i64; set explicitly via | |
3264 | // Y = -9223372036854775808 if that is desired outcome | |
e9174d1e SL |
3265 | } |
3266 | ``` | |
3267 | ||
3268 | To fix this, please set manually the next enum value or put the enum variant | |
3269 | with the maximum value at the end of the enum. Examples: | |
3270 | ||
3271 | ``` | |
3272 | enum Foo { | |
3273 | X = 0x7fffffffffffffff, | |
3274 | Y = 0, // ok! | |
3275 | } | |
7453a54e | 3276 | ``` |
e9174d1e | 3277 | |
7453a54e SL |
3278 | Or: |
3279 | ||
3280 | ``` | |
e9174d1e SL |
3281 | enum Foo { |
3282 | Y = 0, // ok! | |
3283 | X = 0x7fffffffffffffff, | |
3284 | } | |
3285 | ``` | |
3286 | "##, | |
3287 | ||
62682a34 SL |
3288 | E0371: r##" |
3289 | When `Trait2` is a subtrait of `Trait1` (for example, when `Trait2` has a | |
3290 | definition like `trait Trait2: Trait1 { ... }`), it is not allowed to implement | |
3291 | `Trait1` for `Trait2`. This is because `Trait2` already implements `Trait1` by | |
3292 | definition, so it is not useful to do this. | |
3293 | ||
3294 | Example: | |
3295 | ||
7453a54e | 3296 | ```compile_fail |
62682a34 SL |
3297 | trait Foo { fn foo(&self) { } } |
3298 | trait Bar: Foo { } | |
3299 | trait Baz: Bar { } | |
3300 | ||
3301 | impl Bar for Baz { } // error, `Baz` implements `Bar` by definition | |
3302 | impl Foo for Baz { } // error, `Baz` implements `Bar` which implements `Foo` | |
3303 | impl Baz for Baz { } // error, `Baz` (trivially) implements `Baz` | |
3304 | impl Baz for Bar { } // Note: This is OK | |
3305 | ``` | |
3306 | "##, | |
3307 | ||
62682a34 SL |
3308 | E0379: r##" |
3309 | Trait methods cannot be declared `const` by design. For more information, see | |
3310 | [RFC 911]. | |
3311 | ||
3312 | [RFC 911]: https://github.com/rust-lang/rfcs/pull/911 | |
3313 | "##, | |
3314 | ||
3315 | E0380: r##" | |
3316 | Default impls are only allowed for traits with no methods or associated items. | |
3317 | For more information see the [opt-in builtin traits RFC](https://github.com/rust | |
3318 | -lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md). | |
c1a9b12d SL |
3319 | "##, |
3320 | ||
e9174d1e SL |
3321 | E0390: r##" |
3322 | You tried to implement methods for a primitive type. Erroneous code example: | |
3323 | ||
7453a54e | 3324 | ```compile_fail |
e9174d1e SL |
3325 | struct Foo { |
3326 | x: i32 | |
3327 | } | |
3328 | ||
3329 | impl *mut Foo {} | |
3330 | // error: only a single inherent implementation marked with | |
3331 | // `#[lang = "mut_ptr"]` is allowed for the `*mut T` primitive | |
3332 | ``` | |
3333 | ||
3334 | This isn't allowed, but using a trait to implement a method is a good solution. | |
3335 | Example: | |
3336 | ||
3337 | ``` | |
3338 | struct Foo { | |
3339 | x: i32 | |
3340 | } | |
3341 | ||
3342 | trait Bar { | |
3343 | fn bar(); | |
3344 | } | |
3345 | ||
3346 | impl Bar for *mut Foo { | |
3347 | fn bar() {} // ok! | |
3348 | } | |
3349 | ``` | |
3350 | "##, | |
3351 | ||
c1a9b12d SL |
3352 | E0391: r##" |
3353 | This error indicates that some types or traits depend on each other | |
3354 | and therefore cannot be constructed. | |
3355 | ||
3356 | The following example contains a circular dependency between two traits: | |
3357 | ||
7453a54e | 3358 | ```compile_fail |
c1a9b12d SL |
3359 | trait FirstTrait : SecondTrait { |
3360 | ||
3361 | } | |
3362 | ||
3363 | trait SecondTrait : FirstTrait { | |
3364 | ||
3365 | } | |
3366 | ``` | |
3367 | "##, | |
3368 | ||
3369 | E0392: r##" | |
3370 | This error indicates that a type or lifetime parameter has been declared | |
7453a54e | 3371 | but not actually used. Here is an example that demonstrates the error: |
c1a9b12d | 3372 | |
7453a54e | 3373 | ```compile_fail |
c1a9b12d SL |
3374 | enum Foo<T> { |
3375 | Bar | |
3376 | } | |
3377 | ``` | |
3378 | ||
3379 | If the type parameter was included by mistake, this error can be fixed | |
3380 | by simply removing the type parameter, as shown below: | |
3381 | ||
3382 | ``` | |
3383 | enum Foo { | |
3384 | Bar | |
3385 | } | |
3386 | ``` | |
3387 | ||
3388 | Alternatively, if the type parameter was intentionally inserted, it must be | |
3389 | used. A simple fix is shown below: | |
3390 | ||
3391 | ``` | |
3392 | enum Foo<T> { | |
3393 | Bar(T) | |
3394 | } | |
3395 | ``` | |
3396 | ||
3397 | This error may also commonly be found when working with unsafe code. For | |
3398 | example, when using raw pointers one may wish to specify the lifetime for | |
3399 | which the pointed-at data is valid. An initial attempt (below) causes this | |
3400 | error: | |
3401 | ||
7453a54e | 3402 | ```compile_fail |
c1a9b12d SL |
3403 | struct Foo<'a, T> { |
3404 | x: *const T | |
3405 | } | |
3406 | ``` | |
3407 | ||
3408 | We want to express the constraint that Foo should not outlive `'a`, because | |
3409 | the data pointed to by `T` is only valid for that lifetime. The problem is | |
3410 | that there are no actual uses of `'a`. It's possible to work around this | |
3411 | by adding a PhantomData type to the struct, using it to tell the compiler | |
3412 | to act as if the struct contained a borrowed reference `&'a T`: | |
3413 | ||
3414 | ``` | |
3415 | use std::marker::PhantomData; | |
3416 | ||
3417 | struct Foo<'a, T: 'a> { | |
3418 | x: *const T, | |
3419 | phantom: PhantomData<&'a T> | |
3420 | } | |
3421 | ``` | |
3422 | ||
3423 | PhantomData can also be used to express information about unused type | |
3424 | parameters. You can read more about it in the API documentation: | |
3425 | ||
3426 | https://doc.rust-lang.org/std/marker/struct.PhantomData.html | |
e9174d1e SL |
3427 | "##, |
3428 | ||
3429 | E0439: r##" | |
3430 | The length of the platform-intrinsic function `simd_shuffle` | |
3431 | wasn't specified. Erroneous code example: | |
3432 | ||
7453a54e SL |
3433 | ```compile_fail |
3434 | #![feature(platform_intrinsics)] | |
3435 | ||
e9174d1e SL |
3436 | extern "platform-intrinsic" { |
3437 | fn simd_shuffle<A,B>(a: A, b: A, c: [u32; 8]) -> B; | |
3438 | // error: invalid `simd_shuffle`, needs length: `simd_shuffle` | |
3439 | } | |
3440 | ``` | |
3441 | ||
3442 | The `simd_shuffle` function needs the length of the array passed as | |
3443 | last parameter in its name. Example: | |
3444 | ||
3445 | ``` | |
7453a54e SL |
3446 | #![feature(platform_intrinsics)] |
3447 | ||
e9174d1e SL |
3448 | extern "platform-intrinsic" { |
3449 | fn simd_shuffle8<A,B>(a: A, b: A, c: [u32; 8]) -> B; | |
3450 | } | |
3451 | ``` | |
3452 | "##, | |
3453 | ||
3454 | E0440: r##" | |
3455 | A platform-specific intrinsic function has the wrong number of type | |
3456 | parameters. Erroneous code example: | |
3457 | ||
7453a54e SL |
3458 | ```compile_fail |
3459 | #![feature(repr_simd)] | |
3460 | #![feature(platform_intrinsics)] | |
3461 | ||
e9174d1e SL |
3462 | #[repr(simd)] |
3463 | struct f64x2(f64, f64); | |
3464 | ||
3465 | extern "platform-intrinsic" { | |
3466 | fn x86_mm_movemask_pd<T>(x: f64x2) -> i32; | |
3467 | // error: platform-specific intrinsic has wrong number of type | |
3468 | // parameters | |
3469 | } | |
3470 | ``` | |
3471 | ||
3472 | Please refer to the function declaration to see if it corresponds | |
3473 | with yours. Example: | |
3474 | ||
3475 | ``` | |
7453a54e SL |
3476 | #![feature(repr_simd)] |
3477 | #![feature(platform_intrinsics)] | |
3478 | ||
e9174d1e SL |
3479 | #[repr(simd)] |
3480 | struct f64x2(f64, f64); | |
3481 | ||
3482 | extern "platform-intrinsic" { | |
3483 | fn x86_mm_movemask_pd(x: f64x2) -> i32; | |
3484 | } | |
3485 | ``` | |
3486 | "##, | |
3487 | ||
3488 | E0441: r##" | |
3489 | An unknown platform-specific intrinsic function was used. Erroneous | |
3490 | code example: | |
3491 | ||
7453a54e SL |
3492 | ```compile_fail |
3493 | #![feature(repr_simd)] | |
3494 | #![feature(platform_intrinsics)] | |
3495 | ||
e9174d1e SL |
3496 | #[repr(simd)] |
3497 | struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16); | |
3498 | ||
3499 | extern "platform-intrinsic" { | |
3500 | fn x86_mm_adds_ep16(x: i16x8, y: i16x8) -> i16x8; | |
3501 | // error: unrecognized platform-specific intrinsic function | |
3502 | } | |
3503 | ``` | |
3504 | ||
3505 | Please verify that the function name wasn't misspelled, and ensure | |
3506 | that it is declared in the rust source code (in the file | |
3507 | src/librustc_platform_intrinsics/x86.rs). Example: | |
3508 | ||
3509 | ``` | |
7453a54e SL |
3510 | #![feature(repr_simd)] |
3511 | #![feature(platform_intrinsics)] | |
3512 | ||
e9174d1e SL |
3513 | #[repr(simd)] |
3514 | struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16); | |
3515 | ||
3516 | extern "platform-intrinsic" { | |
3517 | fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8; // ok! | |
3518 | } | |
3519 | ``` | |
3520 | "##, | |
3521 | ||
3522 | E0442: r##" | |
3523 | Intrinsic argument(s) and/or return value have the wrong type. | |
3524 | Erroneous code example: | |
3525 | ||
7453a54e SL |
3526 | ```compile_fail |
3527 | #![feature(repr_simd)] | |
3528 | #![feature(platform_intrinsics)] | |
3529 | ||
e9174d1e SL |
3530 | #[repr(simd)] |
3531 | struct i8x16(i8, i8, i8, i8, i8, i8, i8, i8, | |
3532 | i8, i8, i8, i8, i8, i8, i8, i8); | |
3533 | #[repr(simd)] | |
3534 | struct i32x4(i32, i32, i32, i32); | |
3535 | #[repr(simd)] | |
3536 | struct i64x2(i64, i64); | |
3537 | ||
3538 | extern "platform-intrinsic" { | |
3539 | fn x86_mm_adds_epi16(x: i8x16, y: i32x4) -> i64x2; | |
3540 | // error: intrinsic arguments/return value have wrong type | |
3541 | } | |
3542 | ``` | |
3543 | ||
3544 | To fix this error, please refer to the function declaration to give | |
3545 | it the awaited types. Example: | |
3546 | ||
3547 | ``` | |
7453a54e SL |
3548 | #![feature(repr_simd)] |
3549 | #![feature(platform_intrinsics)] | |
3550 | ||
e9174d1e SL |
3551 | #[repr(simd)] |
3552 | struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16); | |
3553 | ||
3554 | extern "platform-intrinsic" { | |
3555 | fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8; // ok! | |
3556 | } | |
3557 | ``` | |
3558 | "##, | |
3559 | ||
3560 | E0443: r##" | |
3561 | Intrinsic argument(s) and/or return value have the wrong type. | |
3562 | Erroneous code example: | |
3563 | ||
7453a54e SL |
3564 | ```compile_fail |
3565 | #![feature(repr_simd)] | |
3566 | #![feature(platform_intrinsics)] | |
3567 | ||
e9174d1e SL |
3568 | #[repr(simd)] |
3569 | struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16); | |
3570 | #[repr(simd)] | |
3571 | struct i64x8(i64, i64, i64, i64, i64, i64, i64, i64); | |
3572 | ||
3573 | extern "platform-intrinsic" { | |
3574 | fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i64x8; | |
3575 | // error: intrinsic argument/return value has wrong type | |
3576 | } | |
3577 | ``` | |
3578 | ||
3579 | To fix this error, please refer to the function declaration to give | |
3580 | it the awaited types. Example: | |
3581 | ||
3582 | ``` | |
7453a54e SL |
3583 | #![feature(repr_simd)] |
3584 | #![feature(platform_intrinsics)] | |
3585 | ||
e9174d1e SL |
3586 | #[repr(simd)] |
3587 | struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16); | |
3588 | ||
3589 | extern "platform-intrinsic" { | |
3590 | fn x86_mm_adds_epi16(x: i16x8, y: i16x8) -> i16x8; // ok! | |
3591 | } | |
3592 | ``` | |
3593 | "##, | |
3594 | ||
3595 | E0444: r##" | |
3596 | A platform-specific intrinsic function has wrong number of arguments. | |
3597 | Erroneous code example: | |
3598 | ||
7453a54e SL |
3599 | ```compile_fail |
3600 | #![feature(repr_simd)] | |
3601 | #![feature(platform_intrinsics)] | |
3602 | ||
e9174d1e SL |
3603 | #[repr(simd)] |
3604 | struct f64x2(f64, f64); | |
3605 | ||
3606 | extern "platform-intrinsic" { | |
3607 | fn x86_mm_movemask_pd(x: f64x2, y: f64x2, z: f64x2) -> i32; | |
3608 | // error: platform-specific intrinsic has invalid number of arguments | |
3609 | } | |
3610 | ``` | |
3611 | ||
3612 | Please refer to the function declaration to see if it corresponds | |
3613 | with yours. Example: | |
3614 | ||
3615 | ``` | |
7453a54e SL |
3616 | #![feature(repr_simd)] |
3617 | #![feature(platform_intrinsics)] | |
3618 | ||
e9174d1e SL |
3619 | #[repr(simd)] |
3620 | struct f64x2(f64, f64); | |
3621 | ||
3622 | extern "platform-intrinsic" { | |
3623 | fn x86_mm_movemask_pd(x: f64x2) -> i32; // ok! | |
3624 | } | |
3625 | ``` | |
3626 | "##, | |
d9579d0f | 3627 | |
b039eaaf SL |
3628 | E0516: r##" |
3629 | The `typeof` keyword is currently reserved but unimplemented. | |
3630 | Erroneous code example: | |
3631 | ||
7453a54e | 3632 | ```compile_fail |
b039eaaf SL |
3633 | fn main() { |
3634 | let x: typeof(92) = 92; | |
3635 | } | |
3636 | ``` | |
3637 | ||
3638 | Try using type inference instead. Example: | |
3639 | ||
3640 | ``` | |
3641 | fn main() { | |
3642 | let x = 92; | |
3643 | } | |
3644 | ``` | |
3645 | "##, | |
3646 | ||
54a0048b SL |
3647 | E0520: r##" |
3648 | A non-default implementation was already made on this type so it cannot be | |
3649 | specialized further. Erroneous code example: | |
3650 | ||
3651 | ```compile_fail | |
3652 | #![feature(specialization)] | |
3653 | ||
3654 | trait SpaceLlama { | |
3655 | fn fly(&self); | |
3656 | } | |
3657 | ||
3658 | // applies to all T | |
3659 | impl<T> SpaceLlama for T { | |
3660 | default fn fly(&self) {} | |
3661 | } | |
3662 | ||
3663 | // non-default impl | |
3664 | // applies to all `Clone` T and overrides the previous impl | |
3665 | impl<T: Clone> SpaceLlama for T { | |
3666 | fn fly(&self) {} | |
3667 | } | |
3668 | ||
3669 | // since `i32` is clone, this conflicts with the previous implementation | |
3670 | impl SpaceLlama for i32 { | |
3671 | default fn fly(&self) {} | |
3672 | // error: item `fly` is provided by an `impl` that specializes | |
3673 | // another, but the item in the parent `impl` is not marked | |
3674 | // `default` and so it cannot be specialized. | |
3675 | } | |
3676 | ``` | |
3677 | ||
3678 | Specialization only allows you to override `default` functions in | |
3679 | implementations. | |
3680 | ||
3681 | To fix this error, you need to mark all the parent implementations as default. | |
3682 | Example: | |
3683 | ||
3684 | ``` | |
3685 | #![feature(specialization)] | |
3686 | ||
3687 | trait SpaceLlama { | |
3688 | fn fly(&self); | |
3689 | } | |
3690 | ||
3691 | // applies to all T | |
3692 | impl<T> SpaceLlama for T { | |
3693 | default fn fly(&self) {} // This is a parent implementation. | |
3694 | } | |
3695 | ||
3696 | // applies to all `Clone` T; overrides the previous impl | |
3697 | impl<T: Clone> SpaceLlama for T { | |
3698 | default fn fly(&self) {} // This is a parent implementation but was | |
3699 | // previously not a default one, causing the error | |
3700 | } | |
3701 | ||
3702 | // applies to i32, overrides the previous two impls | |
3703 | impl SpaceLlama for i32 { | |
3704 | fn fly(&self) {} // And now that's ok! | |
3705 | } | |
3706 | ``` | |
3707 | "##, | |
3708 | ||
d9579d0f AL |
3709 | } |
3710 | ||
1a4d82fc | 3711 | register_diagnostics! { |
e9174d1e SL |
3712 | // E0068, |
3713 | // E0085, | |
3714 | // E0086, | |
1a4d82fc | 3715 | E0090, |
e9174d1e | 3716 | E0103, // @GuillaumeGomez: I was unable to get this error, try your best! |
1a4d82fc | 3717 | E0104, |
e9174d1e SL |
3718 | // E0123, |
3719 | // E0127, | |
3720 | // E0129, | |
3721 | // E0141, | |
3722 | // E0159, // use of trait `{}` as struct constructor | |
1a4d82fc | 3723 | E0167, |
e9174d1e SL |
3724 | // E0168, |
3725 | // E0173, // manual implementations of unboxed closure traits are experimental | |
1a4d82fc | 3726 | E0174, // explicit use of unboxed closure methods are experimental |
1a4d82fc JJ |
3727 | E0182, |
3728 | E0183, | |
e9174d1e | 3729 | // E0187, // can't infer the kind of the closure |
b039eaaf | 3730 | // E0188, // can not cast an immutable reference to a mutable pointer |
e9174d1e SL |
3731 | // E0189, // deprecated: can only cast a boxed pointer to a boxed object |
3732 | // E0190, // deprecated: can only cast a &-pointer to an &-object | |
85aaf69f | 3733 | E0196, // cannot determine a type for this closure |
85aaf69f SL |
3734 | E0203, // type parameter has more than one relaxed default bound, |
3735 | // and only one is supported | |
85aaf69f | 3736 | E0208, |
e9174d1e | 3737 | // E0209, // builtin traits can only be implemented on structs or enums |
85aaf69f | 3738 | E0212, // cannot extract an associated type from a higher-ranked trait bound |
e9174d1e | 3739 | // E0213, // associated types are not accepted in this context |
c1a9b12d SL |
3740 | // E0215, // angle-bracket notation is not stable with `Fn` |
3741 | // E0216, // parenthetical notation is only stable with `Fn` | |
e9174d1e SL |
3742 | // E0217, // ambiguous associated type, defined in multiple supertraits |
3743 | // E0218, // no associated type defined | |
3744 | // E0219, // associated type defined in higher-ranked supertrait | |
c1a9b12d SL |
3745 | // E0222, // Error code E0045 (variadic function must have C calling |
3746 | // convention) duplicate | |
85aaf69f | 3747 | E0224, // at least one non-builtin train is required for an object type |
85aaf69f SL |
3748 | E0226, // only a single explicit lifetime bound is permitted |
3749 | E0227, // ambiguous lifetime bound, explicit lifetime bound required | |
3750 | E0228, // explicit lifetime bound required | |
85aaf69f SL |
3751 | E0230, // there is no type parameter on trait |
3752 | E0231, // only named substitution parameters are allowed | |
e9174d1e SL |
3753 | // E0233, |
3754 | // E0234, | |
3755 | // E0235, // structure constructor specifies a structure of type but | |
54a0048b SL |
3756 | // E0236, // no lang item for range syntax |
3757 | // E0237, // no lang item for range syntax | |
85aaf69f | 3758 | E0238, // parenthesized parameters may only be used with a trait |
e9174d1e SL |
3759 | // E0239, // `next` method of `Iterator` trait has unexpected type |
3760 | // E0240, | |
3761 | // E0241, | |
85aaf69f | 3762 | E0242, // internal error looking up a definition |
85aaf69f | 3763 | E0245, // not a trait |
e9174d1e | 3764 | // E0246, // invalid recursive type |
7453a54e | 3765 | // E0247, |
e9174d1e | 3766 | // E0319, // trait impls for defaulted traits allowed just for structs/enums |
c34b1796 | 3767 | E0320, // recursive overflow during dropck |
d9579d0f | 3768 | E0328, // cannot implement Unsize explicitly |
9cc50fc6 | 3769 | // E0372, // coherence not object safe |
d9579d0f AL |
3770 | E0374, // the trait `CoerceUnsized` may only be implemented for a coercion |
3771 | // between structures with one field being coerced, none found | |
3772 | E0375, // the trait `CoerceUnsized` may only be implemented for a coercion | |
3773 | // between structures with one field being coerced, but multiple | |
3774 | // fields need coercions | |
3775 | E0376, // the trait `CoerceUnsized` may only be implemented for a coercion | |
3776 | // between structures | |
62682a34 | 3777 | E0377, // the trait `CoerceUnsized` may only be implemented for a coercion |
d9579d0f | 3778 | // between structures with the same definition |
c1a9b12d | 3779 | E0393, // the type parameter `{}` must be explicitly specified in an object |
62682a34 | 3780 | // type because its default value `{}` references the type `Self`" |
c1a9b12d SL |
3781 | E0399, // trait items need to be implemented because the associated |
3782 | // type `{}` was overridden | |
b039eaaf | 3783 | E0436, // functional record update requires a struct |
54a0048b SL |
3784 | E0513, // no type for local variable .. |
3785 | E0521 // redundant default implementations of trait | |
1a4d82fc | 3786 | } |