diff options
| author | Ifeanyi Orizu <iorizu1811@gmail.com> | 2025-08-01 00:33:01 -0500 |
|---|---|---|
| committer | Ifeanyi Orizu <iorizu1811@gmail.com> | 2025-08-01 10:48:54 -0500 |
| commit | 7d167260ca00ab7778d3198d9b34fbb3fd95d1e4 (patch) | |
| tree | edebe864148c1a1f7abb6e81f6e8eba9b00f16f8 /src | |
| parent | 053f68151b8e6fb079b6a9254699d5a46220e52f (diff) | |
| download | rust-7d167260ca00ab7778d3198d9b34fbb3fd95d1e4.tar.gz rust-7d167260ca00ab7778d3198d9b34fbb3fd95d1e4.zip | |
Fix more docs
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/rust-analyzer/docs/book/src/contributing/style.md | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/tools/rust-analyzer/docs/book/src/contributing/style.md b/src/tools/rust-analyzer/docs/book/src/contributing/style.md index 5654e37753a..746f3eb1321 100644 --- a/src/tools/rust-analyzer/docs/book/src/contributing/style.md +++ b/src/tools/rust-analyzer/docs/book/src/contributing/style.md @@ -49,8 +49,8 @@ In this case, we'll probably ask you to split API changes into a separate PR. Changes of the third group should be pretty rare, so we don't specify any specific process for them. That said, adding an innocent-looking `pub use` is a very simple way to break encapsulation, keep an eye on it! -Note: if you enjoyed this abstract hand-waving about boundaries, you might appreciate -https://www.tedinski.com/2018/02/06/system-boundaries.html +Note: if you enjoyed this abstract hand-waving about boundaries, you might appreciate [this post](https://www.tedinski.com/2018/02/06/system-boundaries.html). + ## Crates.io Dependencies @@ -231,7 +231,7 @@ fn is_string_literal(s: &str) -> bool { } ``` -In the "Not as good" version, the precondition that `1` is a valid char boundary is checked in `is_string_literal` and used in `foo`. +In the "Bad" version, the precondition that `1` and `s.len() - 1` are valid string literal boundaries is checked in `is_string_literal` but used in `main`. In the "Good" version, the precondition check and usage are checked in the same block, and then encoded in the types. **Rationale:** non-local code properties degrade under change. @@ -271,6 +271,8 @@ fn f() { } ``` +See also [this post](https://matklad.github.io/2023/11/15/push-ifs-up-and-fors-down.html) + ## Assertions Assert liberally. @@ -608,7 +610,7 @@ Avoid making a lot of code type parametric, *especially* on the boundaries betwe ```rust // GOOD -fn frobnicate(f: impl FnMut()) { +fn frobnicate(mut f: impl FnMut()) { frobnicate_impl(&mut f) } fn frobnicate_impl(f: &mut dyn FnMut()) { @@ -616,7 +618,7 @@ fn frobnicate_impl(f: &mut dyn FnMut()) { } // BAD -fn frobnicate(f: impl FnMut()) { +fn frobnicate(mut f: impl FnMut()) { // lots of code } ``` @@ -975,7 +977,7 @@ Don't use the `ref` keyword. **Rationale:** consistency & simplicity. `ref` was required before [match ergonomics](https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md). Today, it is redundant. -Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword). +Between `ref` and match ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword). ## Empty Match Arms |
