aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ide/src/inlay_hints.rs6
-rw-r--r--crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs78
-rw-r--r--crates/test_utils/src/minicore.rs11
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
822use core::iter; 822use core::iter;
823 823
824pub struct SomeIter<T> {} 824pub 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
1130use core::iter; 1130use core::iter;
1131 1131
1132struct MyIter; 1132struct 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
1361use core::iter; 1361use core::iter;
1362 1362
1363struct MyIter; 1363struct 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
191struct Iter; 191use core::iter::{Repeat, repeat};
192impl Iterator for Iter {
193 type Item = usize;
194 fn next(&mut self) -> Option<Self::Item> { None }
195}
196 192
197struct S; 193struct S;
198impl S { 194impl 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
203fn main() { 199fn 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#"
211struct Iter; 207use core::iter::{Repeat, repeat};
212impl Iterator for Iter {
213 type Item = usize;
214 fn next(&mut self) -> Option<Self::Item> { None }
215}
216 208
217struct S; 209struct S;
218impl S { 210impl 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
223fn main() { 215fn 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
264struct Iter; 256use core::iter::{Repeat, repeat};
265impl Iterator for Iter {
266 type Item = usize;
267 fn next(&mut self) -> Option<Self::Item> { None }
268}
269 257
270struct S; 258struct S;
271impl S { 259impl 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
276fn main() { 264fn 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#"
284struct Iter; 272use core::iter::{Repeat, repeat};
285impl Iterator for Iter {
286 type Item = usize;
287 fn next(&mut self) -> Option<Self::Item> { None }
288}
289 273
290struct S; 274struct S;
291impl S { 275impl 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
296fn main() { 280fn 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
336struct Iter;
337impl Iterator for Iter {
338 type Item = usize;
339 fn next(&mut self) -> Option<Self::Item> { None }
340}
341
342fn main() { 320fn 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#"
349struct Iter;
350impl Iterator for Iter {
351 type Item = usize;
352 fn next(&mut self) -> Option<Self::Item> { None }
353}
354
355fn main() { 327fn 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
25pub mod marker { 26pub mod marker {
26 // region:sized 27 // region:sized
@@ -209,6 +210,7 @@ pub mod task {
209 210
210// region:iterator 211// region:iterator
211pub mod iter { 212pub 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;