-
Notifications
You must be signed in to change notification settings - Fork 547
Document ErrorGuaranteed #1316
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
Document ErrorGuaranteed #1316
Changes from 2 commits
Commits
Show all changes
3 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# `ErrorGuaranteed` | ||
|
||
The previous sections have been about the error message that a user of the | ||
compiler sees. But emitting an error can also have a second important side | ||
effect within the compiler source code: it generates an | ||
[`ErrorGuaranteed`][errorguar]. | ||
|
||
`ErrorGuaranteed` is a zero-sized type that is unconstructable outside of the | ||
[`rustc_errors`][rerrors] crate. It is generated whenever an error is reported | ||
to the user, so that if your compiler code ever encounters a value of type | ||
`ErrorGuaranteed`, the compilation is _statically guaranteed to fail_. This is | ||
useful for avoiding unsoundness bugs because you can statically check that an | ||
error code path leads to a failure. | ||
|
||
There are some important considerations about the usage of `ErrorGuaranteed`: | ||
|
||
* It does _not_ convey information about the _kind_ of error. For example, the | ||
error may be due (indirectly) to an ICE. Thus, you should not rely on | ||
`ErrorGuaranteed` when deciding whether to emit an error, or what kind of error | ||
to emit. | ||
|
||
* `ErrorGuaranteed` should not be used to indicate that a compilation _will | ||
emit_ an error in the future. It should be used to indicate that an error | ||
_has already been_ emitted -- that is, the [`emit()`][emit] function has | ||
already been called. For example, if we detect that a future part of the | ||
compiler will error, we _cannot_ use `ErrorGuaranteed` unless we first emit | ||
an error ourselves. | ||
|
||
Thankfully, in most cases, it should be statically impossible to abuse | ||
`ErrorGuaranteed`. | ||
|
||
|
||
[errorguar]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.ErrorGuaranteed.html | ||
[rerrors]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/index.html | ||
[dsp]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/struct.Handler.html#method.delay_span_bug | ||
[emit]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_errors/diagnostic_builder/struct.DiagnosticBuilder.html#method.emit |
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.
Uh oh!
There was an error while loading. Please reload this page.