Skip to content

Commit 0327dc0

Browse files
committed
Insert missing maybe_print_comment call for class destructors
While it wasn't the original issue, the first program from #2487 failed the pretty-printing test because of this, so it's still a good test case :-) It also turns out that the second program from #2487 now triggers a kind error, so I figured I might as well add it as a test case.
1 parent de4f0b9 commit 0327dc0

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ fn print_item(s: ps, &&item: @ast::item) {
539539
print_block(s, ctor.node.body);
540540
option::iter(m_dtor) {|dtor|
541541
hardbreak_if_not_bol(s);
542+
maybe_print_comment(s, dtor.span.lo);
542543
head(s, "drop");
543544
print_block(s, dtor.node.body);
544545
}

src/test/compile-fail/issue-2487-b.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class socket {
2+
let sock: int;
3+
4+
new() { self.sock = 1; }
5+
6+
drop { }
7+
8+
fn set_identity() {
9+
closure { ||
10+
setsockopt_bytes(self.sock) //! ERROR copying a noncopyable value
11+
}
12+
}
13+
}
14+
15+
fn closure(f: fn@()) { f() }
16+
17+
fn setsockopt_bytes(+_sock: int) { }
18+
19+
fn main() {}

src/test/run-pass/issue-2487-a.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class socket {
2+
let sock: int;
3+
4+
new() { self.sock = 1; }
5+
6+
drop { }
7+
8+
fn set_identity() {
9+
closure { ||
10+
setsockopt_bytes(copy self.sock)
11+
}
12+
}
13+
}
14+
15+
fn closure(f: fn()) { f() }
16+
17+
fn setsockopt_bytes(_sock: int) { }
18+
19+
fn main() {}

0 commit comments

Comments
 (0)