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

Pretty printer improvements #14106

Closed
wants to merge 18 commits into from

Conversation

alexcrichton
Copy link
Member

Rebasing of #13596, plus some extra fixes.

These commands now execute without error:

rustc --pretty expanded src/libcore/lib.rs > core.rs
rustc core.rs

@huonw
Copy link
Member

huonw commented May 11, 2014

Is the binary from core.rs and libcore/lib.rs the same?

@alexcrichton
Copy link
Member Author

Sadly no, I think that because there's any slight difference at all in the AST that the binary output is quite different. I imagine that they are very similar in functionality, however.

@sanxiyn
Copy link
Member

sanxiyn commented May 11, 2014

Does rustc --test core.rs; ./core pass then?

@alexcrichton
Copy link
Member Author

Not quite, sadly. By using --pretty expanded all configuration is done, so all of the cfg(test) portions go away and aren't present for --test. That would require --pretty normal to actually work, but it currently butchers macro invocations to the point where the resulting source doesn't even parse.

@alexcrichton
Copy link
Member Author

Should have all the tests passing now.

@huonw
Copy link
Member

huonw commented May 11, 2014

Hm, I wonder if

rustc src/libcore/lib.rs --test --pretty expanded > coretest.rs
rustc coretest.rs
./coretest

works.

Some(ast_map::NodeItem(item)) => item,
_ => return,
};
if !cx.checked_raw_pointers.insert(item.id) { return }
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 a little confused about why this would ever be hit? Surely the visitor visits each item once?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, of course: The automatically_derived attribute applies to impls, and so one can have multiple impls corresponding to a single struct/enum.

@alexcrichton
Copy link
Member Author

Running --test over --pretty expanded sadly doesn't work very well because --pretty expanded prints post-expansion meaning that all of the cfg(test) directives are lost (in addition to all #[test])

@huonw
Copy link
Member

huonw commented May 13, 2014

Travis has relevant failures.

klutzy and others added 18 commits May 13, 2014 09:04
Inject `extern crate {std, native}` before `use` statements.
Add `#![feature(glob)]` since `use std::prelude::*` is used.

(Unfortunately `rustc --pretty expanded` does not converge,
since `extern crate` and `use std::prelude::*` is injected at every
iteration.)
Some `Expr` needs parentheses when printed. For example, without
parentheses, `ExprUnary(UnNeg, ExprBinary(BiAdd, ..))` becomes
`-lhs + rhs` which is wrong.

Those cases don't appear in ordinary code (since parentheses are
explicitly added) but they can appear in manually crafted ast by
extensions.
The tests use managed boxes, but are not perfectly feature-gated because
they use `@` inside macros. (It causes issue after `--pretty expanded`.)
After testing `--pretty normal`, it tries to run `--pretty expanded` and
typecheck output.
Here we don't check convergence since it really diverges: for every
iteration, some extra lines (e.g.`extern crate std`) are inserted.

Some tests are `ignore-pretty`-ed since they cause various issues
with `--pretty expanded`.
* Added `// no-pretty-expanded` to pretty-print a test, but not run it through
  the `expanded` variant.
* Removed #[deriving] and other expanded attributes after they are expanded
* Removed hacks around &str and &&str and friends (from both the parser and the
  pretty printer).
* Un-ignored a bunch of tests
Integers are always parsed as a u64 in libsyntax, but they're stored as i64. The
parser and pretty printer both printed an i64 instead of u64, sometimes
introducing an extra negative sign.
This uses the trick of replacing the << token with a < token to parse closure
types correctly.

Closes rust-lang#13324
The pretty printer handles inlines comments quite badly
When expanding, an extra unsafe block is generated which is currently not
handled well.
Previously, literals "1i" were printed as "1". This fixes the
numeric-method-autoexport test for pretty printing.
Now that the #[deriving] attribute is removed, the raw_pointers_deriving lint
was broken. This commit restores the lint by preserving lint attributes
across #[deriving] to the implementations and using #[automatically_derived] as
the trigger for activating the lint.
When printing doc comments, always put a newline after them in a macro
invocation to ensure that a line-doc-comment doesn't consume remaining tokens on
the line.
bors added a commit that referenced this pull request May 14, 2014
Closes #14184 (std: Move the owned module from core to std)
Closes #14183 (Allow blocks in const expressions)
Closes #14176 (Add tests for from_bits.)
Closes #14175 (Replaced ~T by Box<T> in manual)
Closes #14173 (Implements Default trait for BigInt and BigUint)
Closes #14171 (Fix #8391)
Closes #14159 (Clean up unicode code in libstd)
Closes #14126 (docs: Add a not found page)
Closes #14123 (add a line to the example to clarify semantics)
Closes #14106 (Pretty printer improvements)
Closes #14083 (rustllvm: Add LLVMRustArrayType)
Closes #13957 (io: Implement process wait timeouts)
@bors bors closed this in #14187 May 14, 2014
@alexcrichton alexcrichton deleted the pretty-updates branch May 14, 2014 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants