Commit Graph

271 Commits

Author SHA1 Message Date
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
Alec Theriault
aa38a1ee50 Update comments in cast-lt.pp 2017-11-06 22:18:14 -08:00
Alec Theriault
3761c0d246 Fix comments 2017-11-05 20:53:46 -08:00
Alec Theriault
005d14d5c8 Added tests 2017-11-05 12:27:46 -08:00
leonardo.yvens
5190abb941 Fix unsafe auto trait pretty print.
It was being printed wrong as auto unsafe trait
2017-11-03 16:13:23 -02:00
leonardo.yvens
ca26f01dd1 Update pretty test for auto trait syntax. 2017-11-03 16:13:22 -02:00
Wonwoo Choi
84cb90f8ee Fix tests 2017-10-08 23:52:15 +09:00
Eduard-Mihai Burtescu
10f66bd6e4 Use rvalue promotion to 'static instead of static items. 2017-09-10 11:20:27 +03:00
Josh Driver
a201348775 Update pretty test for derive attributes
Remove attr-variant-data.rs since it relies on quirks
in legacy custom derive resolution (undefined derives
only print a warning).

Add a new test which uses a defined proc macro derive,
and tests pretty printing of proc macro derive
attributes.
2017-02-05 12:22:29 +10:30
Vadim Petrochenkov
2efe865d22 AST/HIR: Merge ObjectSum and PolyTraitRef 2017-01-17 01:52:47 +03:00
Jeffrey Seyfried
8a1acb2c69 Pretty-print $crate::foo::bar as ::foo::bar. 2016-12-22 06:14:36 +00:00
Eduard Burtescu
16b5c2cfef rustc: desugar UFCS as much as possible during HIR lowering. 2016-11-28 04:18:10 +02:00
Eduard Burtescu
8e9106c531 tests: fix fallout in pretty-printing output exact-match tests. 2016-11-10 01:44:53 +02:00
iirelu
e593c3b893 Changed most vec! invocations to use square braces
Most of the Rust community agrees that the vec! macro is clearer when
called using square brackets [] instead of regular brackets (). Most of
these ocurrences are from before macros allowed using different types of
brackets.

There is one left unchanged in a pretty-print test, as the pretty
printer still wants it to have regular brackets.
2016-10-31 22:51:40 +00:00
Jeffrey Seyfried
8b0c292a72 Improve $crate. 2016-10-19 10:03:06 +00:00
Vadim Petrochenkov
4a91a80b26 Fix some pretty printing tests 2016-10-18 23:23:40 +03:00
Sergio Benitez
8250a26b5b Implement RFC#1559: allow all literals in attributes. 2016-08-25 13:25:22 -07:00
Seo Sanghyeon
3c29fc5f6c Fix pretty-printing of lifetime bound 2016-06-29 23:40:29 +09:00
Erick Tryzelaar
9de2de1d21 Pretty-print attributes on tuple structs and add tests
This adds support to the pretty printer to print attributes
added to tuple struct elements.  Furthermore, it adds a test
that makes sure we will print attributes on all variant data
types.
2016-06-17 10:05:19 +01:00
Jeffrey Seyfried
da41e583d6 Fix fallout in tests 2016-03-30 22:00:48 +00:00
Niko Matsakis
bca94230f3 Fix accursed issue-4264.pp 2016-03-25 14:07:20 -04:00
Eduard Burtescu
d6689e5d1c Update the not-at-all-pretty pain-o-tron-4000+264 test. 2016-03-18 02:22:32 +02:00
bors
eeb062b8b1 Auto merge of #31746 - erickt:newline, r=sfackler
syntax: Always pretty print a newline after doc comments

Before this patch, code that had a doc comment as the first
line, as in:

```rust
/// Foo
struct Foo;
```

Was pretty printed into:

```rust
///Foostruct Foo;
```

This makes sure that that there is always a trailing newline
after a doc comment.

Closes #31722
2016-03-16 14:20:36 -07:00
Eduard Burtescu
e4e1242769 Print fn type parameters for TyFnDef. 2016-03-09 16:45:28 +02:00
Erick Tryzelaar
0e3334eba9 syntax: Always pretty print a newline after doc comments
Before this patch, code that had a doc comment as the first
line, as in:

```rust
/// Foo
struct Foo;
```

Was pretty printed into:

```rust
///Foostruct Foo;
```

This makes sure that that there is always a trailing newline
after a doc comment.

Closes #31722
2016-03-07 10:25:02 -05:00
Tomasz Miąsko
9a30ecdf11 libsyntax: fix pretty printing of macro with braces
Pretty printing of macro with braces but without terminated semicolon
removed more boxes from stack than it put there, resulting in panic.
This fixes the issue #30731.
2016-01-28 09:19:43 +01:00
nxnfufunezn
014fc0235a Fix pretty_printer to print omitted type _ marker 2016-01-25 21:36:06 +05:30
Marvin Löbel
296c3613ca Added stmt_expr_attribute feature gate 2015-11-26 21:47:44 +01:00
Marvin Löbel
2a8f358de7 Add syntax support for attributes on expressions and all syntax
nodes in statement position.

Extended #[cfg] folder to allow removal of statements, and
of expressions in optional positions like expression lists and trailing
block expressions.

Extended lint checker to recognize lint levels on expressions and
locals.
2015-11-26 21:46:12 +01:00
Nick Cameron
c1084a3ada Changes to tests 2015-09-17 12:16:46 +12:00
Nick Cameron
facdf2ebb1 Add an intital HIR and lowering step 2015-09-03 10:02:36 +12:00
Tim Neumann
f0ea2b66f3 Fix #27567: remove --crate-type=lib from pretty test 2015-08-11 13:00:38 +02:00
Tim Neumann
c8f32769b8 remove unused file in test/pretty 2015-08-11 13:00:14 +02:00
Sean McArthur
cfcd449c4c rustc: rename multiple imports in a list 2015-08-08 11:54:15 -07:00
Eduard Burtescu
6a3b385cbd Feature-gate #[prelude_import]. 2015-07-05 22:35:20 +03:00
petrochenkov
bddb685e73 Use assert_eq! instead of assert! in tests 2015-06-13 14:55:55 +03:00
Steve Klabnik
bba934f19a ignore-test cleanup
Most of these are old, but some specific messages for specific tests:

* trait-contravariant-self.rs: failed due to a soundess hole:
  05e3248a79

* process-detatch: 15966c3c1f
  says "this test is being ignored until signals are implemented" That's
  not happening for a long time, and when it is, we'll write tests for
  it.

* deep-vector{,2}.rs: "too big for our poor macro infrastructure", and has
  been ignored over a year.

* borrowck-nested-calls.rs's FIXME #6268 was closed in favor of
  rust-lang/rfcs#811

* issue-15167.rs works properly now
* issue-9737.rs works properly now
* match-var-hygiene.rs works properly now

Addresses a chunk of #3965
2015-06-12 14:16:16 -04:00
Felix S. Klock II
c62c908f08 Correct pretty-printing of type Foo<T> where T: Bound = ...;
Fix #25031
2015-05-04 10:21:39 +02:00
Alex Crichton
a568a7f9f2 std: Bring back f32::from_str_radix as an unstable API
This API was exercised in a few tests and mirrors the `from_str_radix`
functionality of the integer types.
2015-04-21 15:23:54 -07:00
Piotr Czarnecki
13bc8afa4b Model lexer: Fix remaining issues 2015-04-21 12:02:12 +02:00
Niko Matsakis
890ed5c468 Fallout in tests 2015-04-01 11:22:39 -04:00
Niko Matsakis
e2b2a53d70 Fallout in tests: largely changes to error messages. 2015-03-30 09:05:59 -04:00
Alex Crichton
43bfaa4a33 Mass rename uint/int to usize/isize
Now that support has been removed, all lingering use cases are renamed.
2015-03-26 12:10:22 -07:00
Alex Crichton
91b633aa03 rollup merge of #23546: alexcrichton/hyphens
The compiler will now issue a warning for crates that have syntax of the form
`extern crate "foo" as bar`, but it will still continue to accept this syntax.
Additionally, the string `foo-bar` will match the crate name `foo_bar` to assist
in the transition period as well.

This patch will land hopefully in tandem with a Cargo patch that will start
translating all crate names to have underscores instead of hyphens.

cc #23533
2015-03-24 14:56:00 -07:00
Alex Crichton
eb2f1d925f rustc: Add support for extern crate foo as bar
The compiler will now issue a warning for crates that have syntax of the form
`extern crate "foo" as bar`, but it will still continue to accept this syntax.
Additionally, the string `foo-bar` will match the crate name `foo_bar` to assist
in the transition period as well.

This patch will land hopefully in tandem with a Cargo patch that will start
translating all crate names to have underscores instead of hyphens.

cc #23533
2015-03-24 14:55:15 -07:00
Nick Cameron
95602a759d Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.

Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.

[breaking change]

* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:

```
let x = 42;
let y = &x as *const u32;
```

Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:

```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-25 10:03:57 +13:00
Brian Anderson
e9019101a8 Add #![feature] attributes to doctests 2015-03-23 14:40:26 -07:00
Tamir Duberstein
d51047ded0 Strip all leading/trailing newlines 2015-03-15 09:08:21 -07:00
Alex Crichton
39e2c69541 syntax: Remove deprecated unicode escapes
These have been deprecated for quite some time, so we should be good to remove
them now.
2015-03-06 14:11:09 -08:00
Eduard Burtescu
e64670888a Remove integer suffixes where the types in compiled code are identical. 2015-03-05 12:38:33 +05:30