summary refs log tree commit diff
path: root/compiler/rustc_macros/src
AgeCommit message (Collapse)AuthorLines
2022-05-12errors: `set_arg` takes `IntoDiagnosticArg`David Wood-2/+2
Manual implementors of translatable diagnostics will need to call `set_arg`, not just the derive, so make this function a bit more ergonomic by taking `IntoDiagnosticArg` rather than `DiagnosticArgValue`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-12macros: spanless subdiagnostics from `()` fieldsDavid Wood-33/+75
Type attributes could previously be used to support spanless subdiagnostics but these couldn't easily be made optional in the same way that spanned subdiagnostics could by using a field attribute on a field with an `Option<Span>` type. Spanless subdiagnostics can now be specified on fields with `()` type or `Option<()>` type. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-06macros: allow `Vec` fields in diagnostic deriveDavid Wood-39/+85
Diagnostics can have multiple primary spans, or have subdiagnostics repeated at multiple locations, so support `Vec<..>` fields in the diagnostic derive which become loops in the generated code. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: add interop between diagnostic derivesDavid Wood-1/+3
Add `#[subdiagnostic]` field attribute to the diagnostic derive which is applied to fields that have types which use the subdiagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: allow setting applicability in attributeDavid Wood-51/+75
In the initial implementation of the `SessionSubdiagnostic`, the `Applicability` of a suggestion can be set both as a field and as part of the attribute, this commit adds the same support to the original `SessionDiagnostic` derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: add more documentation commentsDavid Wood-1/+13
Documentation comments are always good. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: reuse `SetOnce` trait in diagnostic deriveDavid Wood-60/+11
`SetOnce` trait was introduced in the subdiagnostic derive to simplify the code a little bit, re-use it in the diagnostic derive too. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: add helper functions for invalid attrsDavid Wood-229/+149
Remove some duplicated code between both diagnostic derives by introducing helper functions for reporting an error in case of a invalid attribute. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: split diagnostic derives into modulesDavid Wood-1593/+1631
Split `SessionDiagnostic` and `SessionSubdiagnostic` derives and the various helper functions into multiple modules. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: subdiagnostic deriveDavid Wood-132/+772
Add a new derive, `#[derive(SessionSubdiagnostic)]`, which enables deriving structs for labels, notes, helps and suggestions. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-25fix formattingChristian Poveda-3/+1
2022-04-25use `ParseSess` instead of `Session` in `into_diagnostic`Christian Poveda-2/+4
2022-04-21macros: update doc comment for diagnostic deriveDavid Wood-8/+18
The documentation comment for this derive is out-of-date, it should have been updated in #95512. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-13couple of clippy::complexity fixesMatthias Krüger-1/+1
2022-04-05macros: support translatable suggestionsDavid Wood-66/+93
Extends support for generating `DiagnosticMessage::FluentIdentifier` messages from `SessionDiagnostic` derive to `#[suggestion]`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: note/help in `SessionDiagnostic` deriveDavid Wood-9/+45
Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: support translatable labelsDavid Wood-34/+75
Extends support for generating `DiagnosticMessage::FluentIdentifier` messages from `SessionDiagnostic` derive to `#[label]`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: optional error codesDavid Wood-23/+19
In an effort to make it easier to port diagnostics to `SessionDiagnostic` (for translation) and since translation slugs could replace error codes, make error codes optional in the `SessionDiagnostic` derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: add `#[no_arg]` to skip `set_arg` callDavid Wood-1/+12
A call to `set_arg` is generated for every field of a `SessionDiagnostic` struct without attributes, but not all types support being an argument, so `#[no_arg]` is introduced to skip these fields. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: rename `#[message]` to `#[primary_span]`David Wood-7/+4
Small commit renaming `#[message]` to `#[primary_span]` as this more accurately reflects what it does now. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: translatable struct attrs and warningsDavid Wood-116/+274
Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: update session diagnostic errorsDavid Wood-9/+9
Small commit adding backticks around types and annotations in the error messages from the session diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: add args for non-subdiagnostic fieldsDavid Wood-24/+54
Non-subdiagnostic fields (i.e. those that don't have `#[label]` attributes or similar and are just additional context) have to be added as arguments for Fluent messages to refer them. This commit extends the `SessionDiagnostic` derive to do this for all fields that do not have attributes and introduces an `IntoDiagnosticArg` trait that is implemented on all types that can be converted to a argument for Fluent. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: move suggestion type handling to fnDavid Wood-68/+61
Move the handling of `Span` or `(Span, Applicability)` types in `#[suggestion]` attributes to its own function. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: update commentsDavid Wood-27/+34
Various small changes to comments, like wrapping code in backticks, changing comments to doc comments and adding newlines. Signed-off-by: David Wood <david.wood@huawei.com>
2022-03-08add `#[rustc_pass_by_value]` to more typeslcnr-0/+1
2022-03-03Make `Ord`, `PartialOrd` opt-out in `newtype_index`pierwill-24/+46
Also remove `step` impl if `ORD_IMPL = off`
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-1/+1
2022-03-01Rollup merge of #93926 - PatchMixolydic:bugfix/must_use-on-exprs, r=cjgillotDylan DPC-1/+0
Lint against more useless `#[must_use]` attributes This expands the existing `#[must_use]` check in `unused_attributes` to lint against pretty much everything `#[must_use]` doesn't support. Fixes #93906.
2022-02-27Lint against more useless `#[must_use]` attributesRuby Lazuli-1/+0
This expands the existing `#[must_use]` check in `unused_attributes` to lint against pretty much everything `#[must_use]` doesn't support. Fixes #93906.
2022-02-25Auto merge of #93878 - Aaron1011:newtype-macro, r=cjgillotbors-0/+333
Convert `newtype_index` to a proc macro The `macro_rules!` implementation was becomng excessively complicated, and difficult to modify. The new proc macro implementation should make it much easier to add new features (e.g. skipping certain `#[derive]`s)
2022-02-24Address review commentsAaron Hill-24/+10
2022-02-24Convert `newtype_index` to a proc macroAaron Hill-0/+347
The `macro_rules!` implementation was becomng excessively complicated, and difficult to modify. The new proc macro implementation should make it much easier to add new features (e.g. skipping certain `#[derive]`s)
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-1/+1
2022-02-20Delete Decoder::read_enum_variantMark Rousskov-8/+4
2022-02-20Delete Decoder::read_struct_fieldMark Rousskov-19/+6
2022-02-20Delete Decoder::read_structMark Rousskov-9/+1
2022-02-20Delete read_enum_variant_argMark Rousskov-11/+12
2022-02-20Delete read_enum_variant namesMark Rousskov-8/+0
2022-02-20Delete Decoder::read_enumMark Rousskov-13/+8
2022-02-16Move ty::print methods to Drop-based scope guardsMark Rousskov-1/+3
2022-01-22Make `Decodable` and `Decoder` infallible.Nicholas Nethercote-13/+5
`Decoder` has two impls: - opaque: this impl is already partly infallible, i.e. in some places it currently panics on failure (e.g. if the input is too short, or on a bad `Result` discriminant), and in some places it returns an error (e.g. on a bad `Option` discriminant). The number of places where either happens is surprisingly small, just because the binary representation has very little redundancy and a lot of input reading can occur even on malformed data. - json: this impl is fully fallible, but it's only used (a) for the `.rlink` file production, and there's a `FIXME` comment suggesting it should change to a binary format, and (b) in a few tests in non-fundamental ways. Indeed #85993 is open to remove it entirely. And the top-level places in the compiler that call into decoding just abort on error anyway. So the fallibility is providing little value, and getting rid of it leads to some non-trivial performance improvements. Much of this commit is pretty boring and mechanical. Some notes about a few interesting parts: - The commit removes `Decoder::{Error,error}`. - `InternIteratorElement::intern_with`: the impl for `T` now has the same optimization for small counts that the impl for `Result<T, E>` has, because it's now much hotter. - Decodable impls for SmallVec, LinkedList, VecDeque now all use `collect`, which is nice; the one for `Vec` uses unsafe code, because that gave better perf on some benchmarks.
2022-01-03Rollup merge of #92011 - Aaron1011:decode-span, r=michaelwoeristerMatthias Krüger-11/+15
Use field span in `rustc_macros` when emitting decode call This will cause backtraces to point to the location of the field in the struct/enum, rather than the derive macro. This makes it clear which field was being decoded when the backtrace was captured (which is especially useful if there are multiple fields with the same type).
2021-12-16Use field span in `rustc_macros` when emitting decode callAaron Hill-11/+15
This will cause backtraces to point to the location of the field in the struct/enum, rather than the derive macro. This makes it clear which field was being decoded when the backtrace was captured (which is especially useful if there are multiple fields with the same type).
2021-12-15Remove `in_band_lifetimes` from `rustc_middle`Aaron Hill-0/+5
See #91867 This was mostly straightforward. In several places, I take advantage of the fact that lifetimes are non-hygenic: a macro declares the 'tcx' lifetime, which is then used in types passed in as macro arguments.
2021-12-12Query modifierDeadbeef-0/+20
2021-12-02Rename TypeFolderFallible to FallibleTypeFolderAlan Egerton-1/+1
2021-12-02Reduce boilerplate around infallible foldersAlan Egerton-2/+2
2021-11-26Make `TypeFoldable` implementors short-circuit on errorLeSeulArtichaut-3/+3
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-22Avoid generating empty closures for fieldless enumsMark Rousskov-7/+18
For many enums, this avoids generating lots of tiny stubs that need to be codegen'd and then inlined and removed by LLVM.