@@ -271,6 +271,12 @@ fn main() {
271
271
See also http://doc.rust-lang.org/book/unsafe.html
272
272
"## ,
273
273
274
+ E0137 : r##"
275
+ This error indicates that the compiler found multiple functions with the
276
+ #[main] attribute. This is an error because there must be a unique entry point
277
+ into a Rust program.
278
+ "## ,
279
+
274
280
E0152 : r##"
275
281
Lang items are already implemented in the standard library. Unless you are
276
282
writing a free-standing application (e.g. a kernel), you do not need to provide
@@ -419,6 +425,142 @@ of a loop. Without a loop to break out of or continue in, no sensible action can
419
425
be taken.
420
426
"## ,
421
427
428
+ E0271 : r##"
429
+ This is because of a type mismatch between the associated type of some
430
+ trait (e.g. T::Bar, where T implements trait Quux { type Bar; })
431
+ and another type U that is required to be equal to T::Bar, but is not.
432
+ Examples follow.
433
+
434
+ Here is a basic example:
435
+
436
+ ```
437
+ trait Trait { type AssociatedType; }
438
+ fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
439
+ println!("in foo");
440
+ }
441
+ impl Trait for i8 { type AssociatedType = &'static str; }
442
+ foo(3_i8);
443
+ ```
444
+
445
+ Here is that same example again, with some explanatory comments:
446
+
447
+ ```
448
+ trait Trait { type AssociatedType; }
449
+
450
+ fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
451
+ // ~~~~~~~~ ~~~~~~~~~~~~~~~~~~
452
+ // | |
453
+ // This says `foo` can |
454
+ // only be used with |
455
+ // some type that |
456
+ // implements `Trait`. |
457
+ // |
458
+ // This says not only must
459
+ // `T` be an impl of `Trait`
460
+ // but also that the impl
461
+ // must assign the type `u32`
462
+ // to the associated type.
463
+ println!("in foo");
464
+ }
465
+
466
+ impl Trait for i8 { type AssociatedType = &'static str; }
467
+ ~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
468
+ // | |
469
+ // `i8` does have |
470
+ // implementation |
471
+ // of `Trait`... |
472
+ // ... but it is an implementation
473
+ // that assigns `&'static str` to
474
+ // the associated type.
475
+
476
+ foo(3_i8);
477
+ // Here, we invoke `foo` with an `i8`, which does not satisfy
478
+ // the constraint `<i8 as Trait>::AssociatedType=32`, and
479
+ // therefore the type-checker complains with this error code.
480
+ ```
481
+
482
+ Here is a more subtle instance of the same problem, that can
483
+ arise with for-loops in Rust:
484
+
485
+ ```
486
+ let vs: Vec<i32> = vec![1, 2, 3, 4];
487
+ for v in &vs {
488
+ match v {
489
+ 1 => {}
490
+ _ => {}
491
+ }
492
+ }
493
+ ```
494
+
495
+ The above fails because of an analogous type mismatch,
496
+ though may be harder to see. Again, here are some
497
+ explanatory comments for the same example:
498
+
499
+ ```
500
+ {
501
+ let vs = vec![1, 2, 3, 4];
502
+
503
+ // `for`-loops use a protocol based on the `Iterator`
504
+ // trait. Each item yielded in a `for` loop has the
505
+ // type `Iterator::Item` -- that is,I `Item` is the
506
+ // associated type of the concrete iterator impl.
507
+ for v in &vs {
508
+ // ~ ~~~
509
+ // | |
510
+ // | We borrow `vs`, iterating over a sequence of
511
+ // | *references* of type `&Elem` (where `Elem` is
512
+ // | vector's element type). Thus, the associated
513
+ // | type `Item` must be a reference `&`-type ...
514
+ // |
515
+ // ... and `v` has the type `Iterator::Item`, as dictated by
516
+ // the `for`-loop protocol ...
517
+
518
+ match v {
519
+ 1 => {}
520
+ // ~
521
+ // |
522
+ // ... but *here*, `v` is forced to have some integral type;
523
+ // only types like `u8`,`i8`,`u16`,`i16`, et cetera can
524
+ // match the pattern `1` ...
525
+
526
+ _ => {}
527
+ }
528
+
529
+ // ... therefore, the compiler complains, because it sees
530
+ // an attempt to solve the equations
531
+ // `some integral-type` = type-of-`v`
532
+ // = `Iterator::Item`
533
+ // = `&Elem` (i.e. `some reference type`)
534
+ //
535
+ // which cannot possibly all be true.
536
+
537
+ }
538
+ }
539
+ ```
540
+
541
+ To avoid those issues, you have to make the types match correctly.
542
+ So we can fix the previous examples like this:
543
+
544
+ ```
545
+ // Basic Example:
546
+ trait Trait { type AssociatedType; }
547
+ fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
548
+ println!("in foo");
549
+ }
550
+ impl Trait for i8 { type AssociatedType = &'static str; }
551
+ foo(3_i8);
552
+
553
+ // For-Loop Example:
554
+ let vs = vec![1, 2, 3, 4];
555
+ for v in &vs {
556
+ match v {
557
+ &1 => {}
558
+ _ => {}
559
+ }
560
+ }
561
+ ```
562
+ "## ,
563
+
422
564
E0282 : r##"
423
565
This error indicates that type inference did not result in one unique possible
424
566
type, and extra information is required. In most cases this can be provided
@@ -664,7 +806,6 @@ register_diagnostics! {
664
806
E0134 ,
665
807
E0135 ,
666
808
E0136 ,
667
- E0137 ,
668
809
E0138 ,
669
810
E0139 ,
670
811
E0261 , // use of undeclared lifetime name
@@ -674,7 +815,6 @@ register_diagnostics! {
674
815
E0266 , // expected item
675
816
E0269 , // not all control paths return a value
676
817
E0270 , // computation may converge in a function marked as diverging
677
- E0271 , // type mismatch resolving
678
818
E0272 , // rustc_on_unimplemented attribute refers to non-existent type parameter
679
819
E0273 , // rustc_on_unimplemented must have named format arguments
680
820
E0274 , // rustc_on_unimplemented must have a value
0 commit comments