Skip to content
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

pp omits parens needed to disambiguate call-with-block sugar #1458

Closed
jruderman opened this issue Jan 8, 2012 · 3 comments
Closed

pp omits parens needed to disambiguate call-with-block sugar #1458

jruderman opened this issue Jan 8, 2012 · 3 comments
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.

Comments

@jruderman
Copy link
Contributor

This is a passing Rust program:

fn plus_one(f: block() -> int) -> int {
  ret f() + 1;
}

fn ret_plus_one() -> fn(block() -> int) -> int {
  ret plus_one;
}

fn main() {
  let z = (ret_plus_one()) {|| 2};
  assert z == 3;
}

The pretty-printer omits the parens around the call in main, so the result of pretty-printing does not compile.

@graydon
Copy link
Contributor

graydon commented Feb 15, 2012

Goodness!

I wonder if it might make sense to just hold on to any parens in the input, as AST nodes. expr_paren(@expr) is likely a harmless no-op at almost every level of the compiler pipeline and it would relieve the pretty printer from having to work out the (sometimes quite complicated) rules regarding the "proper" amount of parenthesization required to reproduce the input unambiguously.

@brson
Copy link
Contributor

brson commented Jul 31, 2012

Still a problem with do

fn plus_one(f: fn() -> int) -> int {
  ret f() + 1;
}

fn ret_plus_one() -> fn(fn() -> int) -> int {
  ret plus_one;
}

fn main() {
    let z = do (ret_plus_one()) || { 2 };
    assert z == 3;
}

@catamorphism
Copy link
Contributor

@brson 's example doesn't parse at all now. I filed #3861

catamorphism added a commit that referenced this issue Oct 30, 2012
for better pretty-printing, as per #1458
bjorn3 added a commit to bjorn3/rust that referenced this issue Mar 8, 2024
Fix download hash check on big-endian systems
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

4 participants