rust/src/test/pretty
kennytm 0d53ecd0c7
Rollup merge of #45784 - harpocrates:fix/print-parens-cast-lt, r=kennytm
Pretty print parens around casts on the LHS of `<`/`<<`

When pretty printing a cast expression occuring on the LHS of a `<` or `<<` expression, we should add parens around the cast. Otherwise, the `<`/`<<` gets interpreted as the beginning of the generics for the type on the RHS of the cast.

Consider:

    $ cat parens_cast.rs
    macro_rules! negative {
        ($e:expr) => { $e < 0 }
    }

    fn main() {
        negative!(1 as i32);
    }

Before this PR, the output of the following is not valid Rust:

    $ rustc -Z unstable-options --pretty=expanded parens_cast.rs
    #![feature(prelude_import)]
    #![no_std]
    #[prelude_import]
    use std::prelude::v1::*;
    #[macro_use]
    extern crate std as std;
    macro_rules! negative(( $ e : expr ) => { $ e < 0 });

    fn main() { 1 as i32 < 0; }

After this PR, the output of the following is valid Rust:

    $ rustc -Z unstable-options --pretty=expanded parens_cast.rs
    #![feature(prelude_import)]
    #![no_std]
    #[prelude_import]
    use std::prelude::v1::*;
    #[macro_use]
    extern crate std as std;
    macro_rules! negative(( $ e : expr ) => { $ e < 0 });

    fn main() { (1 as i32) < 0; }

I've gone through several README/wiki style documents but I'm still not sure where to test this though. I'm not even sure if this sort of thing is tested...
2017-11-07 22:40:20 +08:00
..
auxiliary
asm-clobbers.rs
asm-options.rs
attr-derive.rs
attr-fn-inner.rs
attr-literals.rs
auto-trait.rs Fix unsafe auto trait pretty print. 2017-11-03 16:13:23 -02:00
blank-lines.rs
block-comment-multiple-asterisks.rs
block-comment-trailing-whitespace2.rs
block-comment-trailing-whitespace.rs
block-comment-wchar.pp
block-comment-wchar.rs
block-disambig.rs
cast-lt.pp Update comments in cast-lt.pp 2017-11-06 22:18:14 -08:00
cast-lt.rs Fix comments 2017-11-05 20:53:46 -08:00
closure-reform-pretty.rs
disamb-stmt-expr.rs
do1.rs
doc-comments.rs
empty-impl.rs
empty-lines.rs
example1.rs
example2.pp
example2.rs
fn-return.rs
fn-types.rs
for-comment.rs
import-renames.rs
issue-4264.pp
issue-4264.rs
issue-19077.rs
issue-25031.rs
issue-30731.rs
issue-31073.pp
issue-31073.rs
let.rs
lifetime.rs
match-block-expr.rs
match-naked-expr-medium.rs
match-naked-expr.rs
path-type-bounds.rs
raw-str-nonexpr.rs
stmt_expr_attributes.rs
struct-pattern.rs
struct-tuple.rs
tag-blank-lines.rs
top-level-doc-comments.rs
trait-polarity.rs
trait-safety.rs
unary-op-disambig.rs
vec-comments.pp
vec-comments.rs
where-clauses.rs