Skip to content

Commit da9019d

Browse files
Add long error explanation for E0271
1 parent 65f8899 commit da9019d

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Diff for: src/librustc/diagnostics.rs

+42-1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,48 @@ loop. Without a loop to break out of or continue in, no sensible action can be
329329
taken.
330330
"##,
331331

332+
E0271: r##"
333+
This is because of a type mismatch, that happens to involve a constraint that
334+
forces the associated type of some particular trait to be equivalent to some
335+
other type. Examples:
336+
```
337+
// example 1:
338+
let vs = vec![1, 2, 3, 4];
339+
for v in &vs {
340+
match v {
341+
1 => {}
342+
_ => {}
343+
}
344+
}
345+
//example 2:
346+
trait Trait { type AssociatedType; }
347+
impl Trait for i8 { type AssociatedType = &'static str; }
348+
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
349+
println!("in foo");
350+
}
351+
foo(3i8);
352+
```
353+
To avoid those issues, you have to make the types match correctly. So we can
354+
fix the previous examples like this:
355+
```
356+
// example 1:
357+
let vs = vec![1, 2, 3, 4];
358+
for v in &vs {
359+
match v {
360+
&1 => {}
361+
_ => {}
362+
}
363+
}
364+
//example 2:
365+
trait Trait { type AssociatedType; }
366+
impl Trait for i8 { type AssociatedType = &'static str; }
367+
fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
368+
println!("in foo");
369+
}
370+
foo(3i8);
371+
```
372+
"##,
373+
332374
E0296: r##"
333375
This error indicates that the given recursion limit could not be parsed. Ensure
334376
that the value provided is a positive integer between quotes, like so:
@@ -456,7 +498,6 @@ register_diagnostics! {
456498
E0266, // expected item
457499
E0269, // not all control paths return a value
458500
E0270, // computation may converge in a function marked as diverging
459-
E0271, // type mismatch resolving
460501
E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter
461502
E0273, // rustc_on_unimplemented must have named format arguments
462503
E0274, // rustc_on_unimplemented must have a value

0 commit comments

Comments
 (0)