diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-07 12:27:17 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-07 12:27:17 +0000 |
commit | 7967ce85cfc5fc2b1996425b44f2a45d0841c8ff (patch) | |
tree | 4495b9de7ea6c8e9dd9fd347d42517e9dee511fa /crates/assists/src/handlers/introduce_named_lifetime.rs | |
parent | c3e9fb183bc287d83b97b776edc87c54d18d1a73 (diff) | |
parent | 72b9a4fbd3c12f3250b9157a1d44230e04ec8b22 (diff) |
Merge #7184
7184: Changes Cursor Marker To $0 r=matklad a=kevaundray
Co-authored-by: Kevaundray Wedderburn <[email protected]>
Diffstat (limited to 'crates/assists/src/handlers/introduce_named_lifetime.rs')
-rw-r--r-- | crates/assists/src/handlers/introduce_named_lifetime.rs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/crates/assists/src/handlers/introduce_named_lifetime.rs b/crates/assists/src/handlers/introduce_named_lifetime.rs index ab8fe3ea9..3f5f44d69 100644 --- a/crates/assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/assists/src/handlers/introduce_named_lifetime.rs | |||
@@ -14,7 +14,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime"; | |||
14 | // Change an anonymous lifetime to a named lifetime. | 14 | // Change an anonymous lifetime to a named lifetime. |
15 | // | 15 | // |
16 | // ``` | 16 | // ``` |
17 | // impl Cursor<'_<|>> { | 17 | // impl Cursor<'_$0> { |
18 | // fn node(self) -> &SyntaxNode { | 18 | // fn node(self) -> &SyntaxNode { |
19 | // match self { | 19 | // match self { |
20 | // Cursor::Replace(node) | Cursor::Before(node) => node, | 20 | // Cursor::Replace(node) | Cursor::Before(node) => node, |
@@ -33,7 +33,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime"; | |||
33 | // } | 33 | // } |
34 | // ``` | 34 | // ``` |
35 | // FIXME: How can we handle renaming any one of multiple anonymous lifetimes? | 35 | // FIXME: How can we handle renaming any one of multiple anonymous lifetimes? |
36 | // FIXME: should also add support for the case fun(f: &Foo) -> &<|>Foo | 36 | // FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo |
37 | pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { | 37 | pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { |
38 | let lifetime = | 38 | let lifetime = |
39 | ctx.find_node_at_offset::<ast::Lifetime>().filter(|lifetime| lifetime.text() == "'_")?; | 39 | ctx.find_node_at_offset::<ast::Lifetime>().filter(|lifetime| lifetime.text() == "'_")?; |
@@ -150,7 +150,7 @@ mod tests { | |||
150 | fn test_example_case() { | 150 | fn test_example_case() { |
151 | check_assist( | 151 | check_assist( |
152 | introduce_named_lifetime, | 152 | introduce_named_lifetime, |
153 | r#"impl Cursor<'_<|>> { | 153 | r#"impl Cursor<'_$0> { |
154 | fn node(self) -> &SyntaxNode { | 154 | fn node(self) -> &SyntaxNode { |
155 | match self { | 155 | match self { |
156 | Cursor::Replace(node) | Cursor::Before(node) => node, | 156 | Cursor::Replace(node) | Cursor::Before(node) => node, |
@@ -171,7 +171,7 @@ mod tests { | |||
171 | fn test_example_case_simplified() { | 171 | fn test_example_case_simplified() { |
172 | check_assist( | 172 | check_assist( |
173 | introduce_named_lifetime, | 173 | introduce_named_lifetime, |
174 | r#"impl Cursor<'_<|>> {"#, | 174 | r#"impl Cursor<'_$0> {"#, |
175 | r#"impl<'a> Cursor<'a> {"#, | 175 | r#"impl<'a> Cursor<'a> {"#, |
176 | ); | 176 | ); |
177 | } | 177 | } |
@@ -180,7 +180,7 @@ mod tests { | |||
180 | fn test_example_case_cursor_after_tick() { | 180 | fn test_example_case_cursor_after_tick() { |
181 | check_assist( | 181 | check_assist( |
182 | introduce_named_lifetime, | 182 | introduce_named_lifetime, |
183 | r#"impl Cursor<'<|>_> {"#, | 183 | r#"impl Cursor<'$0_> {"#, |
184 | r#"impl<'a> Cursor<'a> {"#, | 184 | r#"impl<'a> Cursor<'a> {"#, |
185 | ); | 185 | ); |
186 | } | 186 | } |
@@ -189,7 +189,7 @@ mod tests { | |||
189 | fn test_impl_with_other_type_param() { | 189 | fn test_impl_with_other_type_param() { |
190 | check_assist( | 190 | check_assist( |
191 | introduce_named_lifetime, | 191 | introduce_named_lifetime, |
192 | "impl<I> fmt::Display for SepByBuilder<'_<|>, I> | 192 | "impl<I> fmt::Display for SepByBuilder<'_$0, I> |
193 | where | 193 | where |
194 | I: Iterator, | 194 | I: Iterator, |
195 | I::Item: fmt::Display, | 195 | I::Item: fmt::Display, |
@@ -206,28 +206,28 @@ mod tests { | |||
206 | fn test_example_case_cursor_before_tick() { | 206 | fn test_example_case_cursor_before_tick() { |
207 | check_assist( | 207 | check_assist( |
208 | introduce_named_lifetime, | 208 | introduce_named_lifetime, |
209 | r#"impl Cursor<<|>'_> {"#, | 209 | r#"impl Cursor<$0'_> {"#, |
210 | r#"impl<'a> Cursor<'a> {"#, | 210 | r#"impl<'a> Cursor<'a> {"#, |
211 | ); | 211 | ); |
212 | } | 212 | } |
213 | 213 | ||
214 | #[test] | 214 | #[test] |
215 | fn test_not_applicable_cursor_position() { | 215 | fn test_not_applicable_cursor_position() { |
216 | check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_><|> {"#); | 216 | check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_>$0 {"#); |
217 | check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<|><'_> {"#); | 217 | check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor$0<'_> {"#); |
218 | } | 218 | } |
219 | 219 | ||
220 | #[test] | 220 | #[test] |
221 | fn test_not_applicable_lifetime_already_name() { | 221 | fn test_not_applicable_lifetime_already_name() { |
222 | check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a<|>> {"#); | 222 | check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a$0> {"#); |
223 | check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a<|>>"#); | 223 | check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a$0>"#); |
224 | } | 224 | } |
225 | 225 | ||
226 | #[test] | 226 | #[test] |
227 | fn test_with_type_parameter() { | 227 | fn test_with_type_parameter() { |
228 | check_assist( | 228 | check_assist( |
229 | introduce_named_lifetime, | 229 | introduce_named_lifetime, |
230 | r#"impl<T> Cursor<T, '_<|>>"#, | 230 | r#"impl<T> Cursor<T, '_$0>"#, |
231 | r#"impl<T, 'a> Cursor<T, 'a>"#, | 231 | r#"impl<T, 'a> Cursor<T, 'a>"#, |
232 | ); | 232 | ); |
233 | } | 233 | } |
@@ -236,7 +236,7 @@ mod tests { | |||
236 | fn test_with_existing_lifetime_name_conflict() { | 236 | fn test_with_existing_lifetime_name_conflict() { |
237 | check_assist( | 237 | check_assist( |
238 | introduce_named_lifetime, | 238 | introduce_named_lifetime, |
239 | r#"impl<'a, 'b> Cursor<'a, 'b, '_<|>>"#, | 239 | r#"impl<'a, 'b> Cursor<'a, 'b, '_$0>"#, |
240 | r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#, | 240 | r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#, |
241 | ); | 241 | ); |
242 | } | 242 | } |
@@ -245,7 +245,7 @@ mod tests { | |||
245 | fn test_function_return_value_anon_lifetime_param() { | 245 | fn test_function_return_value_anon_lifetime_param() { |
246 | check_assist( | 246 | check_assist( |
247 | introduce_named_lifetime, | 247 | introduce_named_lifetime, |
248 | r#"fn my_fun() -> X<'_<|>>"#, | 248 | r#"fn my_fun() -> X<'_$0>"#, |
249 | r#"fn my_fun<'a>() -> X<'a>"#, | 249 | r#"fn my_fun<'a>() -> X<'a>"#, |
250 | ); | 250 | ); |
251 | } | 251 | } |
@@ -254,7 +254,7 @@ mod tests { | |||
254 | fn test_function_return_value_anon_reference_lifetime() { | 254 | fn test_function_return_value_anon_reference_lifetime() { |
255 | check_assist( | 255 | check_assist( |
256 | introduce_named_lifetime, | 256 | introduce_named_lifetime, |
257 | r#"fn my_fun() -> &'_<|> X"#, | 257 | r#"fn my_fun() -> &'_$0 X"#, |
258 | r#"fn my_fun<'a>() -> &'a X"#, | 258 | r#"fn my_fun<'a>() -> &'a X"#, |
259 | ); | 259 | ); |
260 | } | 260 | } |
@@ -263,7 +263,7 @@ mod tests { | |||
263 | fn test_function_param_anon_lifetime() { | 263 | fn test_function_param_anon_lifetime() { |
264 | check_assist( | 264 | check_assist( |
265 | introduce_named_lifetime, | 265 | introduce_named_lifetime, |
266 | r#"fn my_fun(x: X<'_<|>>)"#, | 266 | r#"fn my_fun(x: X<'_$0>)"#, |
267 | r#"fn my_fun<'a>(x: X<'a>)"#, | 267 | r#"fn my_fun<'a>(x: X<'a>)"#, |
268 | ); | 268 | ); |
269 | } | 269 | } |
@@ -272,7 +272,7 @@ mod tests { | |||
272 | fn test_function_add_lifetime_to_params() { | 272 | fn test_function_add_lifetime_to_params() { |
273 | check_assist( | 273 | check_assist( |
274 | introduce_named_lifetime, | 274 | introduce_named_lifetime, |
275 | r#"fn my_fun(f: &Foo) -> X<'_<|>>"#, | 275 | r#"fn my_fun(f: &Foo) -> X<'_$0>"#, |
276 | r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#, | 276 | r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#, |
277 | ); | 277 | ); |
278 | } | 278 | } |
@@ -281,7 +281,7 @@ mod tests { | |||
281 | fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() { | 281 | fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() { |
282 | check_assist( | 282 | check_assist( |
283 | introduce_named_lifetime, | 283 | introduce_named_lifetime, |
284 | r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_<|>>"#, | 284 | r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_$0>"#, |
285 | r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#, | 285 | r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#, |
286 | ); | 286 | ); |
287 | } | 287 | } |
@@ -291,7 +291,7 @@ mod tests { | |||
291 | // this is not permitted under lifetime elision rules | 291 | // this is not permitted under lifetime elision rules |
292 | check_assist_not_applicable( | 292 | check_assist_not_applicable( |
293 | introduce_named_lifetime, | 293 | introduce_named_lifetime, |
294 | r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_<|>>"#, | 294 | r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_$0>"#, |
295 | ); | 295 | ); |
296 | } | 296 | } |
297 | 297 | ||
@@ -299,7 +299,7 @@ mod tests { | |||
299 | fn test_function_add_lifetime_to_self_ref_param() { | 299 | fn test_function_add_lifetime_to_self_ref_param() { |
300 | check_assist( | 300 | check_assist( |
301 | introduce_named_lifetime, | 301 | introduce_named_lifetime, |
302 | r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#, | 302 | r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_$0>"#, |
303 | r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#, | 303 | r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#, |
304 | ); | 304 | ); |
305 | } | 305 | } |
@@ -308,7 +308,7 @@ mod tests { | |||
308 | fn test_function_add_lifetime_to_param_with_non_ref_self() { | 308 | fn test_function_add_lifetime_to_param_with_non_ref_self() { |
309 | check_assist( | 309 | check_assist( |
310 | introduce_named_lifetime, | 310 | introduce_named_lifetime, |
311 | r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#, | 311 | r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_$0>"#, |
312 | r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#, | 312 | r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#, |
313 | ); | 313 | ); |
314 | } | 314 | } |