Skip to content

Commit 9735fc2

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

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

Diff for: src/librustc/diagnostics.rs

+51
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,57 @@ 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+
```
338+
// example 1:
339+
let vs = vec![1, 2, 3, 4];
340+
341+
for v in &vs {
342+
match v {
343+
1 => {}
344+
_ => {}
345+
}
346+
}
347+
348+
//example 2:
349+
trait Trait { type AssociatedType; }
350+
impl Trait for i8 { type AssociatedType = &'static str; }
351+
fn foo<T>(t: T) where T: Trait<AssociatedType=u32> {
352+
println!("in foo");
353+
}
354+
355+
foo(3i8);
356+
```
357+
358+
To avoid those issues, you have to make the types match correctly. So we can
359+
fix the previous examples like this:
360+
361+
```
362+
// example 1:
363+
let vs = vec![1, 2, 3, 4];
364+
365+
for v in &vs {
366+
match v {
367+
&1 => {}
368+
_ => {}
369+
}
370+
}
371+
372+
//example 2:
373+
trait Trait { type AssociatedType; }
374+
impl Trait for i8 { type AssociatedType = &'static str; }
375+
fn foo<T>(t: T) where T: Trait<AssociatedType = &'static str> {
376+
println!("in foo");
377+
}
378+
379+
foo(3i8);
380+
```
381+
"##,
382+
332383
E0296: r##"
333384
This error indicates that the given recursion limit could not be parsed. Ensure
334385
that the value provided is a positive integer between quotes, like so:

0 commit comments

Comments
 (0)