Skip to content

Commit 6bde429

Browse files
committed
Minimized (and then greatly expanded) test of failure cases from #52934.
1 parent 4efc0a7 commit 6bde429

4 files changed

+692
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
error[E0503]: cannot use `self.cx` because it was mutably borrowed
2+
--> $DIR/two-phase-surprise-no-conflict.rs:40:13
3+
|
4+
LL | let _mut_borrow = &mut *self;
5+
| ----- borrow of `*self` occurs here
6+
LL | let _access = self.cx;
7+
| ^^^^^^^ use of borrowed `*self`
8+
9+
error[E0502]: cannot borrow `*self.cx_mut` as immutable because `*self` is also borrowed as mutable
10+
--> $DIR/two-phase-surprise-no-conflict.rs:79:33
11+
|
12+
LL | self.hash_expr(&self.cx_mut.body(eid).value);
13+
| ---- ^^^^^^^^^^^ - mutable borrow ends here
14+
| | |
15+
| | immutable borrow occurs here
16+
| mutable borrow occurs here
17+
18+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
19+
--> $DIR/two-phase-surprise-no-conflict.rs:131:52
20+
|
21+
LL | reg.register_static(Box::new(TrivialPass::new(&reg.sess_mut)));
22+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
23+
| | |
24+
| mutable borrow occurs here immutable borrow occurs here
25+
26+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
27+
--> $DIR/two-phase-surprise-no-conflict.rs:135:51
28+
|
29+
LL | reg.register_bound(Box::new(TrivialPass::new(&reg.sess_mut)));
30+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
31+
| | |
32+
| mutable borrow occurs here immutable borrow occurs here
33+
34+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
35+
--> $DIR/two-phase-surprise-no-conflict.rs:139:50
36+
|
37+
LL | reg.register_univ(Box::new(TrivialPass::new(&reg.sess_mut)));
38+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
39+
| | |
40+
| mutable borrow occurs here immutable borrow occurs here
41+
42+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
43+
--> $DIR/two-phase-surprise-no-conflict.rs:143:41
44+
|
45+
LL | reg.register_ref(&TrivialPass::new(&reg.sess_mut));
46+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
47+
| | |
48+
| mutable borrow occurs here immutable borrow occurs here
49+
50+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
51+
--> $DIR/two-phase-surprise-no-conflict.rs:151:56
52+
|
53+
LL | reg.register_static(Box::new(TrivialPass::new(&mut reg.sess_mut)));
54+
| --- ^^^^^^^^^^^^ - first borrow ends here
55+
| | |
56+
| first mutable borrow occurs here second mutable borrow occurs here
57+
58+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
59+
--> $DIR/two-phase-surprise-no-conflict.rs:156:59
60+
|
61+
LL | reg.register_bound(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
62+
| --- ^^^^^^^^^^^^ - first borrow ends here
63+
| | |
64+
| first mutable borrow occurs here second mutable borrow occurs here
65+
66+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
67+
--> $DIR/two-phase-surprise-no-conflict.rs:161:58
68+
|
69+
LL | reg.register_univ(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
70+
| --- ^^^^^^^^^^^^ - first borrow ends here
71+
| | |
72+
| first mutable borrow occurs here second mutable borrow occurs here
73+
74+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
75+
--> $DIR/two-phase-surprise-no-conflict.rs:166:49
76+
|
77+
LL | reg.register_ref(&TrivialPass::new_mut(&mut reg.sess_mut));
78+
| --- ^^^^^^^^^^^^ - first borrow ends here
79+
| | |
80+
| first mutable borrow occurs here second mutable borrow occurs here
81+
82+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
83+
--> $DIR/two-phase-surprise-no-conflict.rs:178:51
84+
|
85+
LL | reg.register_bound(Box::new(CapturePass::new(&reg.sess_mut)));
86+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
87+
| | |
88+
| mutable borrow occurs here immutable borrow occurs here
89+
90+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
91+
--> $DIR/two-phase-surprise-no-conflict.rs:183:50
92+
|
93+
LL | reg.register_univ(Box::new(CapturePass::new(&reg.sess_mut)));
94+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
95+
| | |
96+
| mutable borrow occurs here immutable borrow occurs here
97+
98+
error[E0502]: cannot borrow `reg.sess_mut` as immutable because `*reg` is also borrowed as mutable
99+
--> $DIR/two-phase-surprise-no-conflict.rs:188:41
100+
|
101+
LL | reg.register_ref(&CapturePass::new(&reg.sess_mut));
102+
| --- ^^^^^^^^^^^^ - mutable borrow ends here
103+
| | |
104+
| mutable borrow occurs here immutable borrow occurs here
105+
106+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
107+
--> $DIR/two-phase-surprise-no-conflict.rs:200:59
108+
|
109+
LL | reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
110+
| --- ^^^^^^^^^^^^ - first borrow ends here
111+
| | |
112+
| first mutable borrow occurs here second mutable borrow occurs here
113+
114+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
115+
--> $DIR/two-phase-surprise-no-conflict.rs:206:58
116+
|
117+
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
118+
| --- ^^^^^^^^^^^^ - first borrow ends here
119+
| | |
120+
| first mutable borrow occurs here second mutable borrow occurs here
121+
122+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
123+
--> $DIR/two-phase-surprise-no-conflict.rs:212:49
124+
|
125+
LL | reg.register_ref(&CapturePass::new_mut(&mut reg.sess_mut));
126+
| --- ^^^^^^^^^^^^ - first borrow ends here
127+
| | |
128+
| first mutable borrow occurs here second mutable borrow occurs here
129+
130+
error: aborting due to 16 previous errors
131+
132+
Some errors occurred: E0499, E0502, E0503.
133+
For more information about an error, try `rustc --explain E0499`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
error[E0503]: cannot use `self.cx` because it was mutably borrowed
2+
--> $DIR/two-phase-surprise-no-conflict.rs:40:23
3+
|
4+
LL | let _mut_borrow = &mut *self;
5+
| ---------- borrow of `*self` occurs here
6+
LL | let _access = self.cx;
7+
| ^^^^^^^ use of borrowed `*self`
8+
...
9+
LL | _mut_borrow;
10+
| ----------- borrow later used here
11+
12+
error[E0502]: cannot borrow `*self` as mutable because it is also borrowed as immutable
13+
--> $DIR/two-phase-surprise-no-conflict.rs:79:17
14+
|
15+
LL | self.hash_expr(&self.cx_mut.body(eid).value);
16+
| ^^^^^^^^^^^^^^^^-----------^^^^^^^^^^^^^^^^^
17+
| | |
18+
| | immutable borrow occurs here
19+
| mutable borrow occurs here
20+
| borrow later used here
21+
22+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
23+
--> $DIR/two-phase-surprise-no-conflict.rs:151:51
24+
|
25+
LL | reg.register_static(Box::new(TrivialPass::new(&mut reg.sess_mut)));
26+
| ----------------------------------------------^^^^^^^^^^^^^^^^^---
27+
| | |
28+
| | second mutable borrow occurs here
29+
| first mutable borrow occurs here
30+
| borrow later used here
31+
32+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
33+
--> $DIR/two-phase-surprise-no-conflict.rs:156:54
34+
|
35+
LL | reg.register_bound(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
36+
| -------------------------------------------------^^^^^^^^^^^^^^^^^---
37+
| | |
38+
| | second mutable borrow occurs here
39+
| first mutable borrow occurs here
40+
| borrow later used here
41+
42+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
43+
--> $DIR/two-phase-surprise-no-conflict.rs:161:53
44+
|
45+
LL | reg.register_univ(Box::new(TrivialPass::new_mut(&mut reg.sess_mut)));
46+
| ------------------------------------------------^^^^^^^^^^^^^^^^^---
47+
| | |
48+
| | second mutable borrow occurs here
49+
| first mutable borrow occurs here
50+
| borrow later used here
51+
52+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
53+
--> $DIR/two-phase-surprise-no-conflict.rs:166:44
54+
|
55+
LL | reg.register_ref(&TrivialPass::new_mut(&mut reg.sess_mut));
56+
| ---------------------------------------^^^^^^^^^^^^^^^^^--
57+
| | |
58+
| | second mutable borrow occurs here
59+
| first mutable borrow occurs here
60+
| borrow later used here
61+
62+
error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
63+
--> $DIR/two-phase-surprise-no-conflict.rs:178:5
64+
|
65+
LL | reg.register_bound(Box::new(CapturePass::new(&reg.sess_mut)));
66+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^
67+
| | |
68+
| | immutable borrow occurs here
69+
| mutable borrow occurs here
70+
| borrow later used here
71+
72+
error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
73+
--> $DIR/two-phase-surprise-no-conflict.rs:183:5
74+
|
75+
LL | reg.register_univ(Box::new(CapturePass::new(&reg.sess_mut)));
76+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^
77+
| | |
78+
| | immutable borrow occurs here
79+
| mutable borrow occurs here
80+
|
81+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 122:21...
82+
--> $DIR/two-phase-surprise-no-conflict.rs:122:21
83+
|
84+
LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
85+
| ^^
86+
87+
error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
88+
--> $DIR/two-phase-surprise-no-conflict.rs:188:5
89+
|
90+
LL | reg.register_ref(&CapturePass::new(&reg.sess_mut));
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^
92+
| | |
93+
| | immutable borrow occurs here
94+
| mutable borrow occurs here
95+
| borrow later used here
96+
97+
error[E0499]: cannot borrow `*reg` as mutable more than once at a time
98+
--> $DIR/two-phase-surprise-no-conflict.rs:200:5
99+
|
100+
LL | reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
101+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^^
102+
| | |
103+
| | first mutable borrow occurs here
104+
| second mutable borrow occurs here
105+
| borrow later used here
106+
107+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
108+
--> $DIR/two-phase-surprise-no-conflict.rs:200:54
109+
|
110+
LL | reg.register_bound(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
111+
| -------------------------------------------------^^^^^^^^^^^^^^^^^---
112+
| | |
113+
| | second mutable borrow occurs here
114+
| first mutable borrow occurs here
115+
| borrow later used here
116+
117+
error[E0499]: cannot borrow `*reg` as mutable more than once at a time
118+
--> $DIR/two-phase-surprise-no-conflict.rs:206:5
119+
|
120+
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
121+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^^
122+
| | |
123+
| | first mutable borrow occurs here
124+
| second mutable borrow occurs here
125+
|
126+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 122:21...
127+
--> $DIR/two-phase-surprise-no-conflict.rs:122:21
128+
|
129+
LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
130+
| ^^
131+
132+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
133+
--> $DIR/two-phase-surprise-no-conflict.rs:206:53
134+
|
135+
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
136+
| ------------------------------------------------^^^^^^^^^^^^^^^^^---
137+
| | |
138+
| | second mutable borrow occurs here
139+
| first mutable borrow occurs here
140+
| borrow later used here
141+
142+
error[E0499]: cannot borrow `*reg` as mutable more than once at a time
143+
--> $DIR/two-phase-surprise-no-conflict.rs:212:5
144+
|
145+
LL | reg.register_ref(&CapturePass::new_mut(&mut reg.sess_mut));
146+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^
147+
| | |
148+
| | first mutable borrow occurs here
149+
| second mutable borrow occurs here
150+
| borrow later used here
151+
152+
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
153+
--> $DIR/two-phase-surprise-no-conflict.rs:212:44
154+
|
155+
LL | reg.register_ref(&CapturePass::new_mut(&mut reg.sess_mut));
156+
| ---------------------------------------^^^^^^^^^^^^^^^^^--
157+
| | |
158+
| | second mutable borrow occurs here
159+
| first mutable borrow occurs here
160+
| borrow later used here
161+
162+
error: aborting due to 15 previous errors
163+
164+
Some errors occurred: E0499, E0502, E0503.
165+
For more information about an error, try `rustc --explain E0499`.

0 commit comments

Comments
 (0)