-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Added error explanations for E0308, E0309, and E0310 #24576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,10 +303,63 @@ number cannot be negative. | |
| E0307: r##" | ||
| The length of an array is part of its type. For this reason, this length must be | ||
| a compile-time constant. | ||
| "##, | ||
|
|
||
| E0308: r##" | ||
| This error occurs when the compiler was unable to infer the concrete type of a | ||
| variable. This error can occur for several cases, the most common of which is | ||
| that there is a mismatch in the expected type that the compiler inferred, and | ||
| the actual type that the user defined a variable as. | ||
|
|
||
| let a: char = 7; // An integral type can't contained in a character, so | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be "can't be contained".
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, sorry, fixed |
||
| // there is a mismatch. | ||
|
|
||
| let b: u32 = 7; // Either use the right type... | ||
| let c = 7; // ...or let the compiler infer it. | ||
|
|
||
| let d: char = c; // This also causes a mismatch because c is some sort | ||
| // of number whereas d is definitely a character. | ||
| "##, | ||
|
|
||
| E0309: r##" | ||
| Types in type definitions have lifetimes associated with them that represent | ||
| how long the data stored within them is guaranteed to be live. This lifetime | ||
| must be as long as the data needs to be alive, and missing the constraint that | ||
| denotes this will cause this error. | ||
|
|
||
| // This won't compile because T is not constrained, meaning the data | ||
| // stored in it is not guaranteed to last as long as the reference | ||
| struct Foo<'a, T> { | ||
| foo: &'a T | ||
| } | ||
|
|
||
| // This will compile, because it has the constraint on the type parameter | ||
| struct Foo<'a, T: 'a> { | ||
| foo: &'a T | ||
| } | ||
| "##, | ||
|
|
||
| E0310: r##" | ||
| Types in type definitions have lifetimes associated with them that represent | ||
| how long the data stored within them is guaranteed to be live. This lifetime | ||
| must be as long as the data needs to be alive, and missing the constraint that | ||
| denotes this will cause this error. | ||
|
|
||
| // This won't compile because T is not constrained to the static lifetime | ||
| // the reference needs | ||
| struct Foo<T> { | ||
| foo: &'static T | ||
| } | ||
|
|
||
| // This will compile, because it has the constraint on the type parameter | ||
| struct Foo<T: 'static> { | ||
| foo: &'static T | ||
| } | ||
| "## | ||
|
|
||
| } | ||
|
|
||
|
|
||
| register_diagnostics! { | ||
| E0009, | ||
| E0010, | ||
|
|
@@ -363,9 +416,6 @@ register_diagnostics! { | |
| E0300, // unexpanded macro | ||
| E0304, // expected signed integer constant | ||
| E0305, // expected constant | ||
| E0308, | ||
| E0309, // thing may not live long enough | ||
| E0310, // thing may not live long enough | ||
| E0311, // thing may not live long enough | ||
| E0312, // lifetime of reference outlives lifetime of borrowed content | ||
| E0313, // lifetime of borrowed pointer outlives lifetime of captured variable | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean "…variable has." (forgot a 'h')
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @cactorium that original is grammatically correct but also difficult to read.
I suggest perhaps:
(Or drop the example if you're not into that. :) )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's way better worded :)! Thanks!