diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-10-27 09:23:55 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-10-27 09:23:55 +0000 |
commit | 5a3d2332f8d5e382fc06210c260ff6db857ac716 (patch) | |
tree | 0e12aa5d4bcdfb609faa76e01e49854ac95ccadd /docs/user/features.md | |
parent | a455635b48b9b43904488bb33454c67e513bccf7 (diff) | |
parent | da5528824a836a4f36f44f90adc9fadcc98ca75b (diff) |
Merge #2086
2086: document almost all assists r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'docs/user/features.md')
-rw-r--r-- | docs/user/features.md | 174 |
1 files changed, 0 insertions, 174 deletions
diff --git a/docs/user/features.md b/docs/user/features.md index 2e213e34c..7ae2ca7b6 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -118,180 +118,6 @@ impl Debug<|> for Foo { | |||
118 | } | 118 | } |
119 | ``` | 119 | ``` |
120 | 120 | ||
121 | - Fill struct fields | ||
122 | |||
123 | ```rust | ||
124 | // before: | ||
125 | struct S<'a, D> { | ||
126 | a: u32, | ||
127 | b: String, | ||
128 | c: (i32, i32), | ||
129 | d: D, | ||
130 | r: &'a str, | ||
131 | } | ||
132 | |||
133 | fn main() { | ||
134 | let s = S<|> {} | ||
135 | } | ||
136 | |||
137 | // after: | ||
138 | struct S<'a, D> { | ||
139 | a: u32, | ||
140 | b: String, | ||
141 | c: (i32, i32), | ||
142 | d: D, | ||
143 | r: &'a str, | ||
144 | } | ||
145 | |||
146 | fn main() { | ||
147 | let s = <|>S { | ||
148 | a: (), | ||
149 | b: (), | ||
150 | c: (), | ||
151 | d: (), | ||
152 | r: (), | ||
153 | } | ||
154 | } | ||
155 | ``` | ||
156 | |||
157 | - Remove `dbg!` | ||
158 | |||
159 | ```rust | ||
160 | // before: | ||
161 | fn foo(n: usize) { | ||
162 | if let Some(_) = dbg!(n.<|>checked_sub(4)) { | ||
163 | // ... | ||
164 | } | ||
165 | } | ||
166 | |||
167 | // after: | ||
168 | fn foo(n: usize) { | ||
169 | if let Some(_) = n.<|>checked_sub(4) { | ||
170 | // ... | ||
171 | } | ||
172 | } | ||
173 | ``` | ||
174 | |||
175 | - Replace if-let with match: | ||
176 | |||
177 | ```rust | ||
178 | // before: | ||
179 | impl VariantData { | ||
180 | pub fn is_struct(&self) -> bool { | ||
181 | if <|>let VariantData::Struct(..) = *self { | ||
182 | true | ||
183 | } else { | ||
184 | false | ||
185 | } | ||
186 | } | ||
187 | } | ||
188 | |||
189 | // after: | ||
190 | impl VariantData { | ||
191 | pub fn is_struct(&self) -> bool { | ||
192 | <|>match *self { | ||
193 | VariantData::Struct(..) => true, | ||
194 | _ => false, | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | ``` | ||
199 | |||
200 | - Split import | ||
201 | |||
202 | ```rust | ||
203 | // before: | ||
204 | use crate:<|>:db::{RootDatabase, FileSymbol}; | ||
205 | // after: | ||
206 | use crate::{<|>db::{RootDatabase, FileSymbol}}; | ||
207 | ``` | ||
208 | |||
209 | - Move if condition to match arm guard | ||
210 | ```rust | ||
211 | // before: | ||
212 | fn f() { | ||
213 | let mut t = 'a'; | ||
214 | let chars = "abcd"; | ||
215 | match t { | ||
216 | '\r' => if chars.clone().next().is_some() { | ||
217 | t = 'e';<|> | ||
218 | false | ||
219 | }, | ||
220 | _ => true | ||
221 | } | ||
222 | } | ||
223 | |||
224 | // after: | ||
225 | fn f() { | ||
226 | let mut t = 'a'; | ||
227 | let chars = "abcd"; | ||
228 | match t { | ||
229 | '\r' <|>if chars.clone().next().is_some() => { | ||
230 | t = 'e'; | ||
231 | false | ||
232 | }, | ||
233 | _ => true | ||
234 | } | ||
235 | } | ||
236 | ``` | ||
237 | |||
238 | - Make raw string unescaped | ||
239 | |||
240 | ```rust | ||
241 | // before: | ||
242 | fn f() { | ||
243 | let s = <|>"ab\ncd"; | ||
244 | } | ||
245 | |||
246 | // after: | ||
247 | fn f() { | ||
248 | let s = <|>r#"ab | ||
249 | cd"#; | ||
250 | } | ||
251 | ``` | ||
252 | |||
253 | - Make usual string | ||
254 | |||
255 | ```rust | ||
256 | // before: | ||
257 | fn f() { | ||
258 | let s = <|>r#"abcd"#; | ||
259 | } | ||
260 | |||
261 | // after: | ||
262 | fn f() { | ||
263 | let s = <|>"abcd"; | ||
264 | } | ||
265 | ``` | ||
266 | |||
267 | - Add hash | ||
268 | |||
269 | ```rust | ||
270 | // before: | ||
271 | fn f() { | ||
272 | let s = <|>r"abcd"; | ||
273 | } | ||
274 | |||
275 | // after: | ||
276 | fn f() { | ||
277 | let s = <|>r#"abcd"#; | ||
278 | } | ||
279 | ``` | ||
280 | |||
281 | - Remove hash | ||
282 | |||
283 | ```rust | ||
284 | // before: | ||
285 | fn f() { | ||
286 | let s = <|>r#"abcd"#; | ||
287 | } | ||
288 | |||
289 | // after: | ||
290 | fn f() { | ||
291 | let s = <|>r"abcd"; | ||
292 | } | ||
293 | ``` | ||
294 | |||
295 | ### Magic Completions | 121 | ### Magic Completions |
296 | 122 | ||
297 | In addition to usual reference completion, rust-analyzer provides some ✨magic✨ | 123 | In addition to usual reference completion, rust-analyzer provides some ✨magic✨ |