Skip to content

Fix pretty-printing of empty impl items #9061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from Sep 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,13 @@ pub fn print_item(s: @ps, item: &ast::item) {
};

print_type(s, ty);
space(s.s);

if methods.len() == 0 {
word(s.s, ";");
end(s); // end the head-ibox
end(s); // end the outer cbox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm personally very unfamiliar with this code, but looking at it, could you explain why there's two calls to end here? it looks like one of them is the complement of the above head call, and I was just wondering what the "outer cbox" was.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton My understanding of this is very limited too but I think head() opens two blocks (as can be seen in https://github.com/jakub-/rust/blob/7173b9d1b8475bf2b44e50b78501f45f98c76bc0/src/libsyntax/print/pprust.rs#L246).

impl Trait for T {
    fn foo() -> uint { 42 }
}

One spanning "impl Trait for T" (presumably so you can indent properly when you're wrapping a header that's too long?), and other one spanning the whole thing up to }.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, thanks for the explanation!

} else {
space(s.s);
bopen(s);
for meth in methods.iter() {
print_method(s, *meth);
Expand Down
5 changes: 5 additions & 0 deletions src/test/pretty/empty-impl.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait X { }
impl X for uint;

trait Y { }
impl Y for uint;
5 changes: 5 additions & 0 deletions src/test/pretty/empty-impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait X { }
impl X for uint;

trait Y { }
impl Y for uint;