132 Commits

Author SHA1 Message Date
Camelid
c31785a4ed Run ./x.py fmt 2020-06-20 11:12:43 -07:00
Camelid
8d80cc5679 Fix duplicate options error
The UI isn't glitching anymore.
2020-06-20 11:12:43 -07:00
Camelid
58f812bd61 Use p.token instead of p.look_ahead() 2020-06-20 11:12:43 -07:00
Camelid
db9d3769b4 Add documentation 2020-06-20 11:12:43 -07:00
Camelid
8fe6710b4d Create a separate, tool-only suggestion for the comma
That way the comma isn't highlighted as part of the option in the UI.

Weirdly, the comma removal suggestion shows up in the UI.
2020-06-20 11:12:43 -07:00
Camelid
4ba66970d8 Make suggestion machine-applicable 2020-06-20 11:12:43 -07:00
Camelid
b00b1a4598 Use span_suggestion instead of span_label 2020-06-20 11:12:43 -07:00
Camelid
e8be7971d1 Use bitflags function instead of custom one 2020-06-20 11:12:43 -07:00
Camelid
c7da50d23f Get option name from symbol instead of snippet 2020-06-20 11:12:43 -07:00
Camelid
ac54265b13 Use span_label 2020-06-20 11:12:43 -07:00
Camelid
b94b7e7f1b Make warning an error; use help instead of suggestion; clean up code
For some reason, the help message is now in a separate message, which
adds a lot of noise. I would like to try to get it back to one message.
2020-06-20 11:12:42 -07:00
Camelid
2be403ce3e Warn on duplicate asm! options 2020-06-20 11:12:42 -07:00
Camelid
27cc7c7d9f Clean up 2020-06-20 11:12:42 -07:00
Camelid
1d2acdf8ec Use Vec<Span> instead of Option<Vec<Span>> 2020-06-20 11:12:42 -07:00
Camelid
c883fa45d3 Allow multiple asm! options 2020-06-20 10:42:49 -07: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
Josh Triplett
840176ab6f asm: Unify pseudo-keyword parsing using eat, rather than a final expect
Currently, `asm!` parsing uses an `expect` for the last parsed
pseudo-keyword (`sym`), which makes it difficult to extend without
simultaneously refactoring. Use `eat` for the last pseudo-keyword, and
then add an `else` that fails parsing. No change to error output.
2020-06-14 14:17:51 -07:00
Dylan DPC
657a41fe73
Rollup merge of #73178 - petrochenkov:explint, r=varkor
expand: More precise locations for expansion-time lints

First commit: a macro expansion doesn't have a `NodeId` associated with it, but it has a parent `DefId` which we can use for linting.
The observable effect is that lints associated with macro expansions can now be `allow`ed at finer-grained level than whole crate.

Second commit: each macro definition has a `NodeId` which we can use for linting, unless that macro definition was decoded from other crate.
2020-06-12 12:28:25 +02:00
Dylan DPC
8650df5dea
Rollup merge of #73230 - Amanieu:asm-unused2, r=petrochenkov
Suggest including unused asm arguments in a comment to avoid error

We require all arguments to an `asm!` to be used in the template string, just like format strings. However in some cases (e.g. `black_box`) it may be desirable to have `asm!` arguments that are not used in the template string.

Currently this is a hard error rather than a lint since `#[allow]` does not work on macros (#63221), so this PR suggests using the unused arguments in an asm comment as a workaround.

r? @petrochenkov
2020-06-11 19:04:20 +02:00
Dylan DPC
2ac1598d83
Rollup merge of #73172 - matthiaskrgr:cl9ppy, r=Dylan-DPC
Fix more clippy warnings

Fixes more of:

clippy::unused_unit
clippy::op_ref
clippy::useless_format
clippy::needless_return
clippy::useless_conversion
clippy::bind_instead_of_map
clippy::into_iter_on_ref
clippy::redundant_clone
clippy::nonminimal_bool
clippy::redundant_closure
clippy::option_as_ref_deref
clippy::len_zero
clippy::iter_cloned_collect
clippy::filter_next

r? @Dylan-DPC
2020-06-11 13:16:04 +02:00
Amanieu d'Antras
ddacc67190 Add a suggestion to use unused asm arguments in comments 2020-06-11 05:34:43 +01:00
Vadim Petrochenkov
73d5cb0a45 expand: Give reasonable NodeIds to lints associated with macro expansions 2020-06-09 22:27:13 +03:00
Matthias Krüger
58023fedfc Fix more clippy warnings
Fixes more of:

clippy::unused_unit
clippy::op_ref
clippy::useless_format
clippy::needless_return
clippy::useless_conversion
clippy::bind_instead_of_map
clippy::into_iter_on_ref
clippy::redundant_clone
clippy::nonminimal_bool
clippy::redundant_closure
clippy::option_as_ref_deref
clippy::len_zero
clippy::iter_cloned_collect
clippy::filter_next
2020-06-09 18:51:08 +02:00
Aaron Hill
0fcea2e423
Don't lose empty where clause when pretty-printing
Previously, we would parse `struct Foo where;` and `struct Foo;`
identically, leading to an 'empty' `where` clause being omitted during
pretty printing. This will cause us to lose spans when proc-macros
involved, since we will have a collected `where` token that does not
appear in the pretty-printed item.

We now explicitly track the presence of a `where` token during parsing,
so that we can distinguish between `struct Foo where;` and `struct Foo;`
during pretty-printing
2020-06-08 21:09:54 -04:00
Vadim Petrochenkov
283e5b4106 Rename the crates in source code 2020-06-02 20:42:54 +03:00
Vadim Petrochenkov
11d951492c Make things build again 2020-06-02 20:38:24 +03:00
Amanieu d'Antras
d49020573c Clarify errors and warnings about the transition to the new asm! 2020-05-31 18:25:05 +01:00
Ralf Jung
40fb1913e7
Rollup merge of #72637 - euclio:env-hygiene, r=davidtwco
expand `env!` with def-site context

Similar to #66349.

Fixes rust-lang/rust-clippy#5619.
2020-05-30 23:08:46 +02:00
Amanieu d'Antras
b78b15665b Improve inline asm error diagnostics 2020-05-29 17:05:35 +01:00
Andy Russell
68bf8d2487
expand env! with def-site context 2020-05-26 21:49:55 -04:00
Aaron Hill
14382c6437
Collect tokens for ast::Expr 2020-05-24 15:54:48 -04:00
bors
963bf52829 Auto merge of #70705 - lcnr:generic_discriminant, r=nikomatsakis
Use `T`'s discriminant type in `mem::Discriminant<T>` instead of `u64`.

fixes #70509

Adds the lang-item `discriminant_kind`.
Updates the function signature of `intrinsics::discriminant_value`.
Adds the *probably permanently unstable* trait `DiscriminantKind`.
`mem::Discriminant` should now be smaller in some cases.

r? @ghost
2020-05-21 03:48:47 +00:00
Bastian Kauschke
3188ca7dd9 update discriminant_value usage in the compiler 2020-05-19 10:25:13 +02:00
Amanieu d'Antras
a656349b55 Move InlineAsmTemplatePiece and InlineAsmOptions to librustc_ast 2020-05-18 14:41:33 +01:00
Amanieu d'Antras
08822546a5 Implement att_syntax option 2020-05-18 14:41:33 +01:00
Amanieu d'Antras
ff97db1e54 Apply review feedback 2020-05-18 14:41:32 +01:00
Amanieu d'Antras
a0adf53bc9 Implement asm! in librustc_builtin_macros 2020-05-18 14:39:54 +01:00
Camille GILLOT
d4e143ed2f Remove ast::{Ident, Name} reexports. 2020-05-08 13:13:15 +02:00
Andy Russell
36f51f97c7
fix typo in function name 2020-05-04 18:27:23 -04:00
Dylan DPC
35e7745105
Rollup merge of #71773 - tshepang:links, r=davidtwco
doc: misc rustdoc things
2020-05-04 16:15:32 +02:00
Tshepang Lekhonkhobe
3be52b5941 fix rustdoc warnings 2020-05-02 10:41:04 +02:00
Tshepang Lekhonkhobe
5314f0126c doc: misc rustdoc things 2020-05-01 22:32:33 +02:00
Josh Stone
7b005c5fcb Dogfood more or_patterns in the compiler 2020-04-19 07:33:58 -07:00
Yuki Okushi
58ad251ea8
Move MapInPlace to rustc_data_structures 2020-04-18 13:02:33 +09:00
Matthias Krüger
3837df2992 don't clone types that are copy (clippy::clone_on_copy) 2020-04-16 00:17:38 +02:00
Matthias Krüger
9bba047c2e Use if let instead of match when only matching a single variant (clippy::single_match)
Makes code more compact and reduces nestig.
2020-03-30 10:52:29 +02:00
Amanieu d'Antras
d162d096dd Rename asm! to llvm_asm!
asm! is left as a wrapper around llvm_asm! to maintain compatibility.
2020-03-26 15:49:22 +00:00
Esteban Küber
f18a6dcec0 Rename def_span to guess_head_span 2020-03-25 16:45:12 -07:00
Mazdak Farrokhzad
3979964200 defatalize expand_test_or_bench 2020-03-24 06:28:56 +01:00
Mazdak Farrokhzad
0e0f9311da defatalize get_test_runner 2020-03-24 06:28:56 +01:00