Skip to content

Commit d6227dc

Browse files
committed
Added error explanations for E0308, E0309, and E0310
1 parent ba11928 commit d6227dc

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

src/librustc/diagnostics.rs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,63 @@ number cannot be negative.
303303
E0307: r##"
304304
The length of an array is part of its type. For this reason, this length must be
305305
a compile-time constant.
306+
"##,
307+
308+
E0308: r##"
309+
This error occurs when the compiler was unable to infer the concrete type of a
310+
variable. This error can occur for several cases, the most common of which is
311+
that there is a mismatch in the expected type that the compiler inferred, and
312+
the actual type that the user defined a variable as.
313+
314+
let a: char = 7; // An integral type can't contained in a character, so
315+
// there is a mismatch.
316+
317+
let b: u32 = 7; // Either use the right type...
318+
let c = 7; // ...or let the compiler infer it.
319+
320+
let d: char = c; // This also causes a mismatch because c is some sort
321+
// of number whereas d is definitely a character.
322+
"##,
323+
324+
E0309: r##"
325+
Types in type definitions have lifetimes associated with them that represent
326+
how long the data stored within them is guaranteed to be live. This lifetime
327+
must be as long as the data needs to be alive, and missing the constraint that
328+
denotes this will cause this error.
329+
330+
// This won't compile because T is not constrained, meaning the data
331+
// stored in it is not guaranteed to last as long as the reference
332+
struct Foo<'a, T> {
333+
foo: &'a T
334+
}
335+
336+
// This will compile, because it has the constraint on the type parameter
337+
struct Foo<'a, T: 'a> {
338+
foo: &'a T
339+
}
340+
"##,
341+
342+
E0310: r##"
343+
Types in type definitions have lifetimes associated with them that represent
344+
how long the data stored within them is guaranteed to be live. This lifetime
345+
must be as long as the data needs to be alive, and missing the constraint that
346+
denotes this will cause this error.
347+
348+
// This won't compile because T is not constrained to the static lifetime
349+
// the reference needs
350+
struct Foo<T> {
351+
foo: &'static T
352+
}
353+
354+
// This will compile, because it has the constraint on the type parameter
355+
struct Foo<T: 'static> {
356+
foo: &'static T
357+
}
306358
"##
307359

308360
}
309361

362+
310363
register_diagnostics! {
311364
E0009,
312365
E0010,
@@ -363,9 +416,6 @@ register_diagnostics! {
363416
E0300, // unexpanded macro
364417
E0304, // expected signed integer constant
365418
E0305, // expected constant
366-
E0308,
367-
E0309, // thing may not live long enough
368-
E0310, // thing may not live long enough
369419
E0311, // thing may not live long enough
370420
E0312, // lifetime of reference outlives lifetime of borrowed content
371421
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable

0 commit comments

Comments
 (0)