diff options
Diffstat (limited to 'src/docs/try_err.txt')
| -rw-r--r-- | src/docs/try_err.txt | 28 |
1 files changed, 0 insertions, 28 deletions
diff --git a/src/docs/try_err.txt b/src/docs/try_err.txt deleted file mode 100644 index e3d4ef3a09d..00000000000 --- a/src/docs/try_err.txt +++ /dev/null @@ -1,28 +0,0 @@ -### What it does -Checks for usages of `Err(x)?`. - -### Why is this bad? -The `?` operator is designed to allow calls that -can fail to be easily chained. For example, `foo()?.bar()` or -`foo(bar()?)`. Because `Err(x)?` can't be used that way (it will -always return), it is more clear to write `return Err(x)`. - -### Example -``` -fn foo(fail: bool) -> Result<i32, String> { - if fail { - Err("failed")?; - } - Ok(0) -} -``` -Could be written: - -``` -fn foo(fail: bool) -> Result<i32, String> { - if fail { - return Err("failed".into()); - } - Ok(0) -} -``` \ No newline at end of file |
