You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rust-lang/rfcs#221
The current terminology of "task failure" often causes problems when
writing or speaking about code. You often want to talk about the
possibility of an operation that returns a Result "failing", but cannot
because of the ambiguity with task failure. Instead, you have to speak
of "the failing case" or "when the operation does not succeed" or other
circumlocutions.
Likewise, we use a "Failure" header in rustdoc to describe when
operations may fail the task, but it would often be helpful to separate
out a section describing the "Err-producing" case.
We have been steadily moving away from task failure and toward Result as
an error-handling mechanism, so we should optimize our terminology
accordingly: Result-producing functions should be easy to describe.
To update your code, rename any call to `fail!` to `panic!` instead.
Assuming you have not created your own macro named `panic!`, this
will work on UNIX based systems:
grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g'
You can of course also do this by hand.
[breaking-change]
Copy file name to clipboardExpand all lines: src/doc/complement-lang-faq.md
+3-2
Original file line number
Diff line number
Diff line change
@@ -65,14 +65,15 @@ Data values in the language can only be constructed through a fixed set of initi
65
65
* There is no global inter-crate namespace; all name management occurs within a crate.
66
66
* Using another crate binds the root of _its_ namespace into the user's namespace.
67
67
68
-
## Why is failure unwinding non-recoverable within a task? Why not try to "catch exceptions"?
68
+
## Why is panic unwinding non-recoverable within a task? Why not try to "catch exceptions"?
69
69
70
70
In short, because too few guarantees could be made about the dynamic environment of the catch block, as well as invariants holding in the unwound heap, to be able to safely resume; we believe that other methods of signalling and logging errors are more appropriate, with tasks playing the role of a "hard" isolation boundary between separate heaps.
71
71
72
72
Rust provides, instead, three predictable and well-defined options for handling any combination of the three main categories of "catch" logic:
73
73
74
74
* Failure _logging_ is done by the integrated logging subsystem.
75
-
*_Recovery_ after a failure is done by trapping a task failure from _outside_ the task, where other tasks are known to be unaffected.
75
+
*_Recovery_ after a panic is done by trapping a task panic from _outside_
76
+
the task, where other tasks are known to be unaffected.
76
77
*_Cleanup_ of resources is done by RAII-style objects with destructors.
77
78
78
79
Cleanup through RAII-style destructors is more likely to work than in catch blocks anyways, since it will be better tested (part of the non-error control paths, so executed all the time).
0 commit comments