diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide/src/inlay_hints.rs | 6 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs | 78 | ||||
-rw-r--r-- | crates/test_utils/src/minicore.rs | 11 |
3 files changed, 36 insertions, 59 deletions
diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index a6ba3d734..335d57a0d 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs | |||
@@ -818,7 +818,7 @@ fn main() { | |||
818 | fn shorten_iterators_in_associated_params() { | 818 | fn shorten_iterators_in_associated_params() { |
819 | check_types( | 819 | check_types( |
820 | r#" | 820 | r#" |
821 | //- minicore: iterator | 821 | //- minicore: iterators |
822 | use core::iter; | 822 | use core::iter; |
823 | 823 | ||
824 | pub struct SomeIter<T> {} | 824 | pub struct SomeIter<T> {} |
@@ -1126,7 +1126,7 @@ fn main() { | |||
1126 | fn shorten_iterator_hints() { | 1126 | fn shorten_iterator_hints() { |
1127 | check_types( | 1127 | check_types( |
1128 | r#" | 1128 | r#" |
1129 | //- minicore: iterator | 1129 | //- minicore: iterators |
1130 | use core::iter; | 1130 | use core::iter; |
1131 | 1131 | ||
1132 | struct MyIter; | 1132 | struct MyIter; |
@@ -1357,7 +1357,7 @@ fn main() { | |||
1357 | max_length: None, | 1357 | max_length: None, |
1358 | }, | 1358 | }, |
1359 | r#" | 1359 | r#" |
1360 | //- minicore: iterator | 1360 | //- minicore: iterators |
1361 | use core::iter; | 1361 | use core::iter; |
1362 | 1362 | ||
1363 | struct MyIter; | 1363 | struct MyIter; |
diff --git a/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs index 8e571723d..5f2aa016f 100644 --- a/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs +++ b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs | |||
@@ -186,18 +186,14 @@ fn main() { | |||
186 | fn test_for_borrowed() { | 186 | fn test_for_borrowed() { |
187 | check_assist( | 187 | check_assist( |
188 | replace_for_loop_with_for_each, | 188 | replace_for_loop_with_for_each, |
189 | r" | 189 | r#" |
190 | //- minicore: iterator | 190 | //- minicore: iterators |
191 | struct Iter; | 191 | use core::iter::{Repeat, repeat}; |
192 | impl Iterator for Iter { | ||
193 | type Item = usize; | ||
194 | fn next(&mut self) -> Option<Self::Item> { None } | ||
195 | } | ||
196 | 192 | ||
197 | struct S; | 193 | struct S; |
198 | impl S { | 194 | impl S { |
199 | fn iter(&self) -> Iter { Iter } | 195 | fn iter(&self) -> Repeat<i32> { repeat(92) } |
200 | fn iter_mut(&mut self) -> Iter { Iter } | 196 | fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) } |
201 | } | 197 | } |
202 | 198 | ||
203 | fn main() { | 199 | fn main() { |
@@ -206,18 +202,14 @@ fn main() { | |||
206 | let a = v * 2; | 202 | let a = v * 2; |
207 | } | 203 | } |
208 | } | 204 | } |
209 | ", | 205 | "#, |
210 | r" | 206 | r#" |
211 | struct Iter; | 207 | use core::iter::{Repeat, repeat}; |
212 | impl Iterator for Iter { | ||
213 | type Item = usize; | ||
214 | fn next(&mut self) -> Option<Self::Item> { None } | ||
215 | } | ||
216 | 208 | ||
217 | struct S; | 209 | struct S; |
218 | impl S { | 210 | impl S { |
219 | fn iter(&self) -> Iter { Iter } | 211 | fn iter(&self) -> Repeat<i32> { repeat(92) } |
220 | fn iter_mut(&mut self) -> Iter { Iter } | 212 | fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) } |
221 | } | 213 | } |
222 | 214 | ||
223 | fn main() { | 215 | fn main() { |
@@ -226,7 +218,7 @@ fn main() { | |||
226 | let a = v * 2; | 218 | let a = v * 2; |
227 | }); | 219 | }); |
228 | } | 220 | } |
229 | ", | 221 | "#, |
230 | ) | 222 | ) |
231 | } | 223 | } |
232 | 224 | ||
@@ -259,18 +251,14 @@ fn main() { | |||
259 | fn test_for_borrowed_mut() { | 251 | fn test_for_borrowed_mut() { |
260 | check_assist( | 252 | check_assist( |
261 | replace_for_loop_with_for_each, | 253 | replace_for_loop_with_for_each, |
262 | r" | 254 | r#" |
263 | //- minicore: iterator | 255 | //- minicore: iterators |
264 | struct Iter; | 256 | use core::iter::{Repeat, repeat}; |
265 | impl Iterator for Iter { | ||
266 | type Item = usize; | ||
267 | fn next(&mut self) -> Option<Self::Item> { None } | ||
268 | } | ||
269 | 257 | ||
270 | struct S; | 258 | struct S; |
271 | impl S { | 259 | impl S { |
272 | fn iter(&self) -> Iter { Iter } | 260 | fn iter(&self) -> Repeat<i32> { repeat(92) } |
273 | fn iter_mut(&mut self) -> Iter { Iter } | 261 | fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) } |
274 | } | 262 | } |
275 | 263 | ||
276 | fn main() { | 264 | fn main() { |
@@ -279,18 +267,14 @@ fn main() { | |||
279 | let a = v * 2; | 267 | let a = v * 2; |
280 | } | 268 | } |
281 | } | 269 | } |
282 | ", | 270 | "#, |
283 | r" | 271 | r#" |
284 | struct Iter; | 272 | use core::iter::{Repeat, repeat}; |
285 | impl Iterator for Iter { | ||
286 | type Item = usize; | ||
287 | fn next(&mut self) -> Option<Self::Item> { None } | ||
288 | } | ||
289 | 273 | ||
290 | struct S; | 274 | struct S; |
291 | impl S { | 275 | impl S { |
292 | fn iter(&self) -> Iter { Iter } | 276 | fn iter(&self) -> Repeat<i32> { repeat(92) } |
293 | fn iter_mut(&mut self) -> Iter { Iter } | 277 | fn iter_mut(&mut self) -> Repeat<i32> { repeat(92) } |
294 | } | 278 | } |
295 | 279 | ||
296 | fn main() { | 280 | fn main() { |
@@ -299,7 +283,7 @@ fn main() { | |||
299 | let a = v * 2; | 283 | let a = v * 2; |
300 | }); | 284 | }); |
301 | } | 285 | } |
302 | ", | 286 | "#, |
303 | ) | 287 | ) |
304 | } | 288 | } |
305 | 289 | ||
@@ -332,28 +316,16 @@ fn main() { | |||
332 | check_assist( | 316 | check_assist( |
333 | replace_for_loop_with_for_each, | 317 | replace_for_loop_with_for_each, |
334 | r#" | 318 | r#" |
335 | //- minicore: iterator | 319 | //- minicore: iterators |
336 | struct Iter; | ||
337 | impl Iterator for Iter { | ||
338 | type Item = usize; | ||
339 | fn next(&mut self) -> Option<Self::Item> { None } | ||
340 | } | ||
341 | |||
342 | fn main() { | 320 | fn main() { |
343 | for$0 a in Iter.take(1) { | 321 | for$0 a in core::iter::repeat(92).take(1) { |
344 | println!("{}", a); | 322 | println!("{}", a); |
345 | } | 323 | } |
346 | } | 324 | } |
347 | "#, | 325 | "#, |
348 | r#" | 326 | r#" |
349 | struct Iter; | ||
350 | impl Iterator for Iter { | ||
351 | type Item = usize; | ||
352 | fn next(&mut self) -> Option<Self::Item> { None } | ||
353 | } | ||
354 | |||
355 | fn main() { | 327 | fn main() { |
356 | Iter.take(1).for_each(|a| { | 328 | core::iter::repeat(92).take(1).for_each(|a| { |
357 | println!("{}", a); | 329 | println!("{}", a); |
358 | }); | 330 | }); |
359 | } | 331 | } |
diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index 1a0573d7a..e6d2301c7 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs | |||
@@ -21,6 +21,7 @@ | |||
21 | //! option: | 21 | //! option: |
22 | //! result: | 22 | //! result: |
23 | //! iterator: option | 23 | //! iterator: option |
24 | //! iterators: iterator | ||
24 | 25 | ||
25 | pub mod marker { | 26 | pub mod marker { |
26 | // region:sized | 27 | // region:sized |
@@ -209,6 +210,7 @@ pub mod task { | |||
209 | 210 | ||
210 | // region:iterator | 211 | // region:iterator |
211 | pub mod iter { | 212 | pub mod iter { |
213 | // region:iterators | ||
212 | mod adapters { | 214 | mod adapters { |
213 | pub struct Take<I> { | 215 | pub struct Take<I> { |
214 | iter: I, | 216 | iter: I, |
@@ -249,6 +251,7 @@ pub mod iter { | |||
249 | pub use self::repeat::{repeat, Repeat}; | 251 | pub use self::repeat::{repeat, Repeat}; |
250 | } | 252 | } |
251 | pub use self::sources::{repeat, Repeat}; | 253 | pub use self::sources::{repeat, Repeat}; |
254 | // endregion:iterators | ||
252 | 255 | ||
253 | mod traits { | 256 | mod traits { |
254 | mod iterator { | 257 | mod iterator { |
@@ -261,15 +264,17 @@ pub mod iter { | |||
261 | fn nth(&mut self, n: usize) -> Option<Self::Item> { | 264 | fn nth(&mut self, n: usize) -> Option<Self::Item> { |
262 | loop {} | 265 | loop {} |
263 | } | 266 | } |
264 | fn take(self, n: usize) -> crate::iter::Take<Self> { | ||
265 | loop {} | ||
266 | } | ||
267 | fn by_ref(&mut self) -> &mut Self | 267 | fn by_ref(&mut self) -> &mut Self |
268 | where | 268 | where |
269 | Self: Sized, | 269 | Self: Sized, |
270 | { | 270 | { |
271 | self | 271 | self |
272 | } | 272 | } |
273 | // region:iterators | ||
274 | fn take(self, n: usize) -> crate::iter::Take<Self> { | ||
275 | loop {} | ||
276 | } | ||
277 | // endregion:iterators | ||
273 | } | 278 | } |
274 | impl<I: Iterator + ?Sized> Iterator for &mut I { | 279 | impl<I: Iterator + ?Sized> Iterator for &mut I { |
275 | type Item = I::Item; | 280 | type Item = I::Item; |