File tree 2 files changed +71
-2
lines changed
compiler/rustc_infer/src/infer/outlives
src/test/ui/impl-trait/issues
2 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -155,14 +155,17 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
155
155
bug ! ( )
156
156
}
157
157
158
+ #[ instrument( level = "trace" , skip( self ) ) ]
158
159
fn relate_with_variance < T : Relate < ' tcx > > (
159
160
& mut self ,
160
- _ : ty:: Variance ,
161
+ variance : ty:: Variance ,
161
162
_: ty:: VarianceDiagInfo < ' tcx > ,
162
163
a : T ,
163
164
b : T ,
164
165
) -> RelateResult < ' tcx , T > {
165
- self . relate ( a, b)
166
+ // Opaque types substs have lifetime parameters.
167
+ // We must not check them to be equal, as we never insert anything to make them so.
168
+ if variance != ty:: Bivariant { self . relate ( a, b) } else { Ok ( a) }
166
169
}
167
170
168
171
#[ instrument( skip( self ) , level = "debug" ) ]
Original file line number Diff line number Diff line change
1
+ // check-pass
2
+
3
+ struct It ;
4
+
5
+ struct Data {
6
+ items : Vec < It > ,
7
+ }
8
+
9
+ impl Data {
10
+ fn new ( ) -> Self {
11
+ Self {
12
+ items : vec ! [ It , It ] ,
13
+ }
14
+ }
15
+
16
+ fn content ( & self ) -> impl Iterator < Item = & It > {
17
+ self . items . iter ( )
18
+ }
19
+ }
20
+
21
+ struct Container < ' a > {
22
+ name : String ,
23
+ resolver : Box < dyn Resolver + ' a > ,
24
+ }
25
+
26
+ impl < ' a > Container < ' a > {
27
+ fn new < R : Resolver + ' a > ( name : & str , resolver : R ) -> Self {
28
+ Self {
29
+ name : name. to_owned ( ) ,
30
+ resolver : Box :: new ( resolver) ,
31
+ }
32
+ }
33
+ }
34
+
35
+ trait Resolver { }
36
+
37
+ impl < R : Resolver > Resolver for & R { }
38
+
39
+ impl Resolver for It { }
40
+
41
+ fn get < ' a > ( mut items : impl Iterator < Item = & ' a It > ) -> impl Resolver + ' a {
42
+ items. next ( ) . unwrap ( )
43
+ }
44
+
45
+ fn get2 < ' a , ' b : ' b > ( mut items : impl Iterator < Item = & ' a It > ) -> impl Resolver + ' a {
46
+ items. next ( ) . unwrap ( )
47
+ }
48
+
49
+ fn main ( ) {
50
+ let data = Data :: new ( ) ;
51
+ let resolver = get ( data. content ( ) ) ;
52
+
53
+ let _ = [ "a" , "b" ]
54
+ . iter ( )
55
+ . map ( |& n| Container :: new ( n, & resolver) )
56
+ . map ( |c| c. name )
57
+ . collect :: < Vec < _ > > ( ) ;
58
+
59
+ let resolver = get2 ( data. content ( ) ) ;
60
+
61
+ let _ = [ "a" , "b" ]
62
+ . iter ( )
63
+ . map ( |& n| Container :: new ( n, & resolver) )
64
+ . map ( |c| c. name )
65
+ . collect :: < Vec < _ > > ( ) ;
66
+ }
You can’t perform that action at this time.
0 commit comments