Skip to content

Commit 6600962

Browse files
committed
---
yaml --- r: 216815 b: refs/heads/stable c: f23867a h: refs/heads/master i: 216813: 3f4f903 216811: 006357d 216807: 45bb81e 216799: c54a02a v: v3
1 parent 58894e2 commit 6600962

File tree

4 files changed

+156
-6
lines changed

4 files changed

+156
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 757809c8d380886e5fa38d307ceeba3a3c74449e
32+
refs/heads/stable: f23867aa66d61393183313f1828e6383d8365e47
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/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/stable/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/stable/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,

0 commit comments

Comments
 (0)