Skip to content

Commit ed544f4

Browse files
committed
---
yaml --- r: 210514 b: refs/heads/try c: fd099b2 h: refs/heads/master v: v3
1 parent 820087c commit ed544f4

15 files changed

+156
-237
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 978dc9f36a7ebd5c16100ab6cf6ee5f528ccf14a
5+
refs/heads/try: fd099b2d50e38a3ccd3f43e4457e5f73f089f075
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/doc/trpl/error-handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ we can use the `unwrap()` method:
214214
io::stdin().read_line(&mut buffer).unwrap();
215215
```
216216

217-
`unwrap()` will `panic!` if the `Option` is `None`. This basically says "Give
217+
`unwrap()` will `panic!` if the `Result` is `Err`. This basically says "Give
218218
me the value, and if something goes wrong, just crash." This is less reliable
219219
than matching the error and attempting to recover, but is also significantly
220220
shorter. Sometimes, just crashing is appropriate.

branches/try/src/librustc/diagnostics.rs

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ fn main() {
271271
See also http://doc.rust-lang.org/book/unsafe.html
272272
"##,
273273

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+
274280
E0152: r##"
275281
Lang items are already implemented in the standard library. Unless you are
276282
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
419425
be taken.
420426
"##,
421427

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+
422564
E0282: r##"
423565
This error indicates that type inference did not result in one unique possible
424566
type, and extra information is required. In most cases this can be provided
@@ -664,7 +806,6 @@ register_diagnostics! {
664806
E0134,
665807
E0135,
666808
E0136,
667-
E0137,
668809
E0138,
669810
E0139,
670811
E0261, // use of undeclared lifetime name
@@ -674,7 +815,6 @@ register_diagnostics! {
674815
E0266, // expected item
675816
E0269, // not all control paths return a value
676817
E0270, // computation may converge in a function marked as diverging
677-
E0271, // type mismatch resolving
678818
E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter
679819
E0273, // rustc_on_unimplemented must have named format arguments
680820
E0274, // rustc_on_unimplemented must have a value

branches/try/src/librustc_typeck/diagnostics.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ let x_is_nonzero = x as bool;
3434
```
3535
"##,
3636

37+
E0062: r##"
38+
This error indicates that during an attempt to build a struct or struct-like
39+
enum variant, one of the fields was specified more than once. Each field should
40+
be specified exactly one time.
41+
"##,
42+
43+
E0063: r##"
44+
This error indicates that during an attempt to build a struct or struct-like
45+
enum variant, one of the fields was not provided. Each field should be specified
46+
exactly once.
47+
"##,
48+
3749
E0081: r##"
3850
Enum discriminants are used to differentiate enum variants stored in memory.
3951
This error indicates that the same value was used for two or more variants,
@@ -136,8 +148,6 @@ register_diagnostics! {
136148
E0059,
137149
E0060,
138150
E0061,
139-
E0062,
140-
E0063,
141151
E0066,
142152
E0067,
143153
E0068,

branches/try/src/test/auxiliary/crateresolve3-1.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve3-2.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve5-1.rs

Lines changed: 0 additions & 34 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve5-2.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve7x.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve8-1.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve_calories-1.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

branches/try/src/test/auxiliary/crateresolve_calories-2.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)