]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-23485.rs
Rollup merge of #96539 - tmandry:relnotes-1.61, r=Mark-Simulacrum
[rust.git] / src / test / ui / issues / issue-23485.rs
1 // run-pass
2 #![allow(unused_imports)]
3 // Test for an ICE that occurred when a default method implementation
4 // was applied to a type that did not meet the prerequisites. The
5 // problem occurred specifically because normalizing
6 // `Self::Item::Target` was impossible in this case.
7
8 use std::boxed::Box;
9 use std::marker::Sized;
10 use std::clone::Clone;
11 use std::ops::Deref;
12 use std::option::Option;
13 use std::option::Option::{Some,None};
14
15 trait Iterator {
16     type Item;
17
18     fn next(&mut self) -> Option<Self::Item>;
19
20     fn clone_first(mut self) -> Option<<Self::Item as Deref>::Target> where
21         Self: Sized,
22         Self::Item: Deref,
23         <Self::Item as Deref>::Target: Clone,
24     {
25         self.next().map(|x| x.clone())
26     }
27 }
28
29 struct Counter {
30     value: i32
31 }
32
33 struct Token {
34     value: i32
35 }
36
37 impl Iterator for Counter {
38     type Item = Token;
39
40     fn next(&mut self) -> Option<Token> {
41         let x = self.value;
42         self.value += 1;
43         Some(Token { value: x })
44     }
45 }
46
47 fn main() {
48     let mut x: Box<dyn Iterator<Item=Token>> = Box::new(Counter { value: 22 });
49     assert_eq!(x.next().unwrap().value, 22);
50 }