Skip to content

Commit 592d271

Browse files
committed
Rollup merge of rust-lang#24576 - cactorium:errorcodes, r=pnkfelix
For rust-lang#24407
2 parents 9560754 + 4174aa4 commit 592d271

File tree

1 file changed

+55
-3
lines changed

1 file changed

+55
-3
lines changed

src/librustc/diagnostics.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,10 +524,65 @@ number cannot be negative.
524524
E0307: r##"
525525
The length of an array is part of its type. For this reason, this length must be
526526
a compile-time constant.
527+
"##,
528+
529+
E0308: r##"
530+
This error occurs when the compiler was unable to infer the concrete type of a
531+
variable. This error can occur for several cases, the most common of which is a
532+
mismatch in the expected type that the compiler inferred for a variable's
533+
initializing expression, and the actual type explicitly assigned to the
534+
variable.
535+
536+
For example:
537+
538+
let x: i32 = "I am not a number!";
539+
// ~~~ ~~~~~~~~~~~~~~~~~~~~
540+
// | |
541+
// | initializing expression;
542+
// | compiler infers type `&str`
543+
// |
544+
// type `i32` assigned to variable `x`
545+
"##,
546+
547+
E0309: r##"
548+
Types in type definitions have lifetimes associated with them that represent
549+
how long the data stored within them is guaranteed to be live. This lifetime
550+
must be as long as the data needs to be alive, and missing the constraint that
551+
denotes this will cause this error.
552+
553+
// This won't compile because T is not constrained, meaning the data
554+
// stored in it is not guaranteed to last as long as the reference
555+
struct Foo<'a, T> {
556+
foo: &'a T
557+
}
558+
559+
// This will compile, because it has the constraint on the type parameter
560+
struct Foo<'a, T: 'a> {
561+
foo: &'a T
562+
}
563+
"##,
564+
565+
E0310: r##"
566+
Types in type definitions have lifetimes associated with them that represent
567+
how long the data stored within them is guaranteed to be live. This lifetime
568+
must be as long as the data needs to be alive, and missing the constraint that
569+
denotes this will cause this error.
570+
571+
// This won't compile because T is not constrained to the static lifetime
572+
// the reference needs
573+
struct Foo<T> {
574+
foo: &'static T
575+
}
576+
577+
// This will compile, because it has the constraint on the type parameter
578+
struct Foo<T: 'static> {
579+
foo: &'static T
580+
}
527581
"##
528582

529583
}
530584

585+
531586
register_diagnostics! {
532587
E0011,
533588
E0012,
@@ -571,9 +626,6 @@ register_diagnostics! {
571626
E0300, // unexpanded macro
572627
E0304, // expected signed integer constant
573628
E0305, // expected constant
574-
E0308,
575-
E0309, // thing may not live long enough
576-
E0310, // thing may not live long enough
577629
E0311, // thing may not live long enough
578630
E0312, // lifetime of reference outlives lifetime of borrowed content
579631
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable

0 commit comments

Comments
 (0)