Skip to content

Commit 9f62afa

Browse files
committed
Add regression test
1 parent 1105b7f commit 9f62afa

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Regression test for #133941: Don't suggest adding a semicolon during borrowck
2+
// errors when one already exists.
3+
4+
use std::marker::PhantomData;
5+
6+
struct Bar<'a>(PhantomData<&'a mut i32>);
7+
8+
impl<'a> Drop for Bar<'a> {
9+
fn drop(&mut self) {}
10+
}
11+
12+
struct Foo();
13+
14+
impl Foo {
15+
fn f(&mut self) -> Option<Bar<'_>> {
16+
None
17+
}
18+
19+
fn g(&mut self) {}
20+
}
21+
22+
fn main() {
23+
let mut foo = Foo();
24+
while let Some(_) = foo.f() {
25+
//~^ NOTE first mutable borrow occurs here
26+
//~| a temporary with access to the first borrow is created here ...
27+
foo.g(); //~ ERROR cannot borrow `foo` as mutable more than once at a time
28+
//~^ second mutable borrow occurs here
29+
};
30+
//~^ ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0499]: cannot borrow `foo` as mutable more than once at a time
2+
--> $DIR/do-not-suggest-duplicate-semicolons-issue-133941.rs:27:9
3+
|
4+
LL | while let Some(_) = foo.f() {
5+
| -------
6+
| |
7+
| first mutable borrow occurs here
8+
| a temporary with access to the first borrow is created here ...
9+
...
10+
LL | foo.g();
11+
| ^^^ second mutable borrow occurs here
12+
LL |
13+
LL | };
14+
| - ... and the first borrow might be used here, when that temporary is dropped and runs the destructor for type `Option<Bar<'_>>`
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0499`.

0 commit comments

Comments
 (0)