Commit Graph

341 Commits

Author SHA1 Message Date
Mara Bos d274d87e10 Update test/pretty output for edition preludes. 2021-02-25 13:43:11 +01:00
Matthew Jasper dfa581ff87 Fix pretty printing of generic associated type constraints 2021-02-13 19:29:55 +00:00
Eric Huss cadffa74df Fix pretty printer macro_rules with semicolon. 2021-02-08 12:08:27 -08:00
Jeremy Fitzhardinge d7ce9d5b6d test for issue 80832 2021-01-11 10:44:46 -08:00
Camelid 810324d1f3 Rename `optin_builtin_traits` to `auto_traits`
They were originally called "opt-in, built-in traits" (OIBITs), but
people realized that the name was too confusing and a mouthful, and so
they were renamed to just "auto traits". The feature flag's name wasn't
updated, though, so that's what this PR does.

There are some other spots in the compiler that still refer to OIBITs,
but I don't think changing those now is worth it since they are internal
and not particularly relevant to this PR.

Also see <https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/opt-in.2C.20built-in.20traits.20(auto.20traits).20feature.20name>.
2020-11-23 14:14:06 -08:00
thiolliere 775f1e5acd fix pretty print for qpath 2020-11-12 12:47:25 +01:00
Dan Aloni 07e7823c01 pretty: trim paths of unique symbols
If a symbol name can only be imported from one place for a type, and
as long as it was not glob-imported anywhere in the current crate, we
can trim its printed path and print only the name.

This has wide implications on error messages with types, for example,
shortening `std::vec::Vec` to just `Vec`, as long as there is no other
`Vec` importable anywhere.

This adds a new '-Z trim-diagnostic-paths=false' option to control this
feature.

On the good path, with no diagnosis printed, we should try to avoid
issuing this query, so we need to prevent trimmed_def_paths query on
several cases.

This change also relies on a previous commit that differentiates
between `Debug` and `Display` on various rustc types, where the latter
is trimmed and presented to the user and the former is not.
2020-09-02 22:26:37 +03:00
David Wood c773226aba
tests: add regression test for #74745
This commit adds a regression test for #74745. While a
`ignore-tidy-trailing-lines` header is required, this doesn't stop the
test from reproducing, so long as there is no newline at the end of the
file.

However, adding the header comments made the test fail due to a bug in
pprust, fixed in the previous commit.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-02 15:33:06 +01:00
David Wood 86f80d3ba8
pprust: adjust mixed comment printing
This commit adjusts the pretty printing of mixed comments so that the
initial zero-break isn't emitted at the beginning of the line. Through
this, the `block-comment-wchar` test can have the `pp-exact` file
removed, as it no longer converges from pretty printing of the source.

Signed-off-by: David Wood <david@davidtw.co>
2020-08-02 15:33:03 +01:00
Mara Bos 0c51f53edf Make fmt::Arguments::as_str() return a 'static str. 2020-07-17 17:56:55 +02:00
David Wood 083c2f6ceb
pprust: support multiline comments within lines
This commit adds support to rustc_ast_pretty for multiline comments that
start and end within a line of source code.

Signed-off-by: David Wood <david@davidtw.co>
2020-07-12 18:22:09 +01:00
Josh Triplett 1078b6f942 asm: Allow multiple template strings; interpret them as newline-separated
Allow the `asm!` macro to accept a series of template arguments, and
interpret them as if they were concatenated with a '\n' between them.
This allows writing an `asm!` where each line of assembly appears in a
separate template string argument.

This syntax makes it possible for rustfmt to reliably format and indent
each line of assembly, without risking changes to the inside of a
template string. It also avoids the complexity of having the user
carefully format and indent a multi-line string (including where to put
the surrounding quotes), and avoids the extra indentation and lines of a
call to `concat!`.

For example, rewriting the second example from the [blog post on the new
inline assembly
syntax](https://blog.rust-lang.org/inside-rust/2020/06/08/new-inline-asm.html)
using multiple template strings:

```rust

fn main() {
    let mut bits = [0u8; 64];
    for value in 0..=1024u64 {
        let popcnt;
        unsafe {
            asm!(
                "    popcnt {popcnt}, {v}",
                "2:",
                "    blsi rax, {v}",
                "    jz 1f",
                "    xor {v}, rax",
                "    tzcnt rax, rax",
                "    stosb",
                "    jmp 2b",
                "1:",
                v = inout(reg) value => _,
                popcnt = out(reg) popcnt,
                out("rax") _, // scratch
                inout("rdi") bits.as_mut_ptr() => _,
            );
        }
        println!("bits of {}: {:?}", value, &bits[0..popcnt]);
    }
}
```

Note that all the template strings must appear before all other
arguments; you cannot, for instance, provide a series of template
strings intermixed with the corresponding operands.

In order to get srcloc mappings right for macros that generate
multi-line string literals, create one line_span for each
line in the string literal, each pointing to the macro.

Make `rustc_parse_format::Parser::curarg` `pub`, so that we can
propagate it from one template string argument to the next.
2020-06-15 12:35:27 -07:00
Yerkebulan Tulibergenov 249a46f56c pretty/asm.rs should only be tested for x86_64 and not AArch64 2020-06-13 00:41:39 -07:00
Amanieu d'Antras 8ab0f2d3c5 Add tests for asm! 2020-05-18 14:41:32 +01:00
Amanieu d'Antras 1cc521ef9d Update tests to use llvm_asm! 2020-03-26 15:49:22 +00:00
Niko Matsakis fda3378e3f introduce `negative_impls` feature gate and document
They used to be covered by `optin_builtin_traits` but negative impls
are now applicable to all traits, not just auto traits.

This also adds docs in the unstable book for the current state of auto traits.
2020-03-26 06:52:55 -04:00
Mazdak Farrokhzad 60a2d063a9
Rollup merge of #70075 - GuillaumeGomez:fix-repr-display, r=petrochenkov
Fix repr pretty display

Fixes #70027.

r? @varkor
2020-03-18 18:03:47 +01:00
Mazdak Farrokhzad 23b79d83f2
Rollup merge of #69838 - Centril:expand-module, r=petrochenkov
Expansion-driven outline module parsing

After this PR, the parser will not do any conditional compilation or loading of external module files when `mod foo;` is encountered. Instead, the parser only leaves `mod foo;` in place in the AST, with no items filled in. Expansion later kicks in and will load the actual files and do the parsing. This entails that the following is now valid:

```rust
#[cfg(FALSE)]
mod foo {
    mod bar {
        mod baz; // `foo/bar/baz.rs` doesn't exist, but no error!
    }
}
```

Fixes https://github.com/rust-lang/rust/issues/64197.

r? @petrochenkov
2020-03-18 18:03:38 +01:00
Mazdak Farrokhzad 41a0b3ec53 use pretty-compare-only in a test 2020-03-18 15:08:25 +01:00
Guillaume Gomez 81172d8f39 Update pretty tests 2020-03-17 20:58:31 +01:00
Matthew Jasper 1ee5829575 Update tests for erasing regions in typeck 2020-03-17 09:07:56 +00:00
Aaron Hill 37c2c38aeb
Extent pretty-print test 2020-03-04 16:43:14 -05:00
Aaron Hill f63b88c761
Permit attributes on 'if' expressions
Previously, attributes on 'if' expressions (e.g. #[attr] if true {})
were disallowed during parsing. This made it impossible for macros to
perform any custom handling of such attributes (e.g. stripping them
away), since a compilation error would be emitted before they ever had a
chance to run.

This PR permits attributes on 'if' expressions ('if-attrs' from here on).
Both built-in attributes (e.g. `#[allow]`, `#[cfg]`) are supported.

We still do *not* accept attributes on 'other parts' of an if-else
chain. That is, the following code snippet still fails to parse:

```rust
if true {} #[attr] else if false {} else #[attr] if false {} #[attr]
else {}
```
2020-03-04 16:43:13 -05:00
Mazdak Farrokhzad 14442e0ebb print vis & defaultness for nested items 2020-02-21 18:30:56 +01:00
Mazdak Farrokhzad 7737d0ffde parser: unify item list parsing.
as a consequence, `trait X { #![attr] }` becomes legal.
2020-02-13 15:16:29 +01:00
Mikhail Babenko ab6ea2bba7 add regression test 2020-02-07 18:18:07 +03:00
Mazdak Farrokhzad 00f0b0cd3a pretty: print attrs in struct expr 2020-02-02 09:25:54 +01:00
Tomasz Miąsko 2fd6c4a18a Remove unused ignore-license directives
The tidy check was removed in rust-lang/rust#53617
2020-01-24 00:00:00 +00:00
Mazdak Farrokhzad 19db2d2fed ast_stmt_expr_attr -> pretty & ui tests 2019-12-20 22:53:40 +01:00
Matthew Jasper 6dcc78997f Add more tests for raw_ref_op 2019-12-18 20:30:00 +00:00
Mazdak Farrokhzad e9840d94b9 Print the visibility in `print_variant`. 2019-12-07 05:59:41 +01:00
Jon Gjengset 31fc42b7f7 Merge branch 'master' into format-temporaries 2019-11-02 11:12:42 -04:00
Patryk Wychowaniec e188e2db84
Fix a previously forgotten pretty-printing test after a change to the pretty-printing mechanism. 2019-10-28 18:43:59 +01:00
Jon Gjengset 8990f7d627 Update pretty-print test with new format! impl 2019-09-28 09:55:26 -04:00
Matthew Jasper b4ef99f4a6 Print visibility of `macro` items 2019-09-15 10:22:13 +01:00
Vadim Petrochenkov 5b7df0922e pprust: Do not print spaces before some tokens 2019-08-25 21:23:17 +03:00
sd234678 56ebd57960 Remove meaningless comments in src/test 2019-08-16 10:54:20 +01:00
Vadim Petrochenkov fa7fe19601 resolve: Remove remaining special cases from built-in macros 2019-08-10 21:50:56 +03:00
Vadim Petrochenkov 0cdd18d0a7 pprust: Support `macro` macros 2019-07-15 12:42:07 +03:00
Vadim Petrochenkov a2a1cd1864 pprust: Fix formatting regressions from the previous commits
Fix some remaining cases of bad formatting
Update some failing tests
2019-07-15 12:42:07 +03:00
Vadim Petrochenkov 75896011dc pprust: Do not convert attributes into `MetaItem`s for printing
Fixes https://github.com/rust-lang/rust/issues/62628
2019-07-15 12:42:07 +03:00
Vadim Petrochenkov 11585b598c pprust: Use `print_mac_common` for delimited token groups 2019-07-15 12:42:07 +03:00
Vadim Petrochenkov 500b00127b pprust: Use `print_mac_common` for `macro_rules` definitions 2019-07-15 12:42:07 +03:00
Vadim Petrochenkov 65a714a6a0 pprust: Move some methods to the `PrintState` trait
So that path and macro argument printing code can be shared
2019-07-15 12:42:07 +03:00
Vadim Petrochenkov ea4ad555d7 Introduce `#[rustc_dummy]` attribute and use it in tests
Unlike other built-in attributes, this attribute accepts any input
2019-06-08 23:55:25 +03:00
varkor 59762baf8a Move async/await tests to test/ui/async-await 2019-05-24 21:49:34 +01:00
Eduard-Mihai Burtescu 3e1cef7007 rustc: pass Option<&Substs> and Namespace around in ty::item_path. 2019-03-15 13:25:10 +02:00
Alexander Regueiro fe30743c79 Moved issue tests to subdirs and normalised names. 2019-03-14 01:00:49 +00:00
Alexander Regueiro 379cd29d1c Nit 2019-03-03 02:58:09 +00:00
Dan Robertson 04d0a8cb83
Fix C-variadic function printing
There is no longer a need to append the string `", ..."` to a functions
args as `...` is parsed as an argument and will appear in the functions
arguments.
2019-03-02 15:03:09 +00:00