Commit Graph

110 Commits

Author SHA1 Message Date
David Wood
859079ff12 macros: allow Vec fields in diagnostic derive
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-05-06 03:43:30 +01:00
David Wood
dca88612b9 macros: add interop between diagnostic derives
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-29 02:12:10 +01:00
David Wood
e5d9371b30 macros: allow setting applicability in attribute
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-29 02:12:10 +01:00
David Wood
e8ee0d7a20 macros: add more documentation comments
Documentation comments are always good.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:10 +01:00
David Wood
2647a4812c macros: reuse SetOnce trait in diagnostic derive
`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-29 02:12:10 +01:00
David Wood
36a396ce51 macros: add helper functions for invalid attrs
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-29 02:12:10 +01:00
David Wood
071f07274b macros: split diagnostic derives into modules
Split `SessionDiagnostic` and `SessionSubdiagnostic` derives and the
various helper functions into multiple modules.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29 02:12:08 +01:00
David Wood
49ec909ca7 macros: subdiagnostic derive
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-29 02:05:20 +01:00
Christian Poveda
5874b09806
fix formatting 2022-04-25 23:17:32 +02:00
Christian Poveda
eb55cdce4b
use ParseSess instead of Session in into_diagnostic 2022-04-25 22:54:16 +02:00
David Wood
f79d5e9458 macros: update doc comment for diagnostic derive
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-21 04:22:18 +01:00
Matthias Krüger
7c2d57e0fa couple of clippy::complexity fixes 2022-04-13 22:51:34 +02:00
David Wood
22685b9607 macros: support translatable suggestions
Extends support for generating `DiagnosticMessage::FluentIdentifier`
messages from `SessionDiagnostic` derive to `#[suggestion]`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:03 +01:00
David Wood
b40ee88a28 macros: note/help in SessionDiagnostic derive
Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:03 +01:00
David Wood
a88717cef0 macros: support translatable labels
Extends support for generating `DiagnosticMessage::FluentIdentifier`
messages from `SessionDiagnostic` derive to `#[label]`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:03 +01:00
David Wood
72dec56028 macros: optional error codes
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-05 07:01:03 +01:00
David Wood
70ee0c96fc macros: add #[no_arg] to skip set_arg call
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-05 07:01:03 +01:00
David Wood
8100541d54 macros: rename #[message] to #[primary_span]
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-05 07:01:03 +01:00
David Wood
d0fd8d7880 macros: translatable struct attrs and warnings
Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:03 +01:00
David Wood
f0de7df204 macros: update session diagnostic errors
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-05 07:01:03 +01:00
David Wood
9956d4f99d macros: add args for non-subdiagnostic fields
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-05 07:01:02 +01:00
David Wood
8677fef192 macros: move suggestion type handling to fn
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-05 07:01:02 +01:00
David Wood
2bf64d6483 macros: update comments
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-04-05 07:01:02 +01:00
lcnr
b8135fd5c8 add #[rustc_pass_by_value] to more types 2022-03-08 15:39:52 +01:00
pierwill
c08a9a4f1d Make Ord, PartialOrd opt-out in newtype_index
Also remove `step` impl if `ORD_IMPL = off`
2022-03-03 11:52:40 -06:00
mark
e489a94dee rename ErrorReported -> ErrorGuaranteed 2022-03-02 09:45:25 -06:00
Dylan DPC
daed86445d
Rollup merge of #93926 - PatchMixolydic:bugfix/must_use-on-exprs, r=cjgillot
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-03-01 03:41:49 +01:00
Ruby Lazuli
6dcf5d8fde
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-27 08:52:37 -06:00
bors
f6a79936da Auto merge of #93878 - Aaron1011:newtype-macro, r=cjgillot
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-25 03:16:22 +00:00
Aaron Hill
01efe6d5c2
Address review comments 2022-02-24 16:02:07 -05:00
Aaron Hill
339bbebbc1
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-24 16:02:06 -05:00
Eduard-Mihai Burtescu
b7e95dee65 rustc_errors: let DiagnosticBuilder::emit return a "guarantee of emission". 2022-02-23 06:38:52 +00:00
Mark Rousskov
75614c06ee Delete Decoder::read_enum_variant 2022-02-20 18:58:23 -05:00
Mark Rousskov
19288951e1 Delete Decoder::read_struct_field 2022-02-20 18:58:22 -05:00
Mark Rousskov
c021ba48a7 Delete Decoder::read_struct 2022-02-20 18:58:22 -05:00
Mark Rousskov
a421b631ba Delete read_enum_variant_arg 2022-02-20 18:58:22 -05:00
Mark Rousskov
c87060a72d Delete read_enum_variant names 2022-02-20 18:58:22 -05:00
Mark Rousskov
c6bd6b444c Delete Decoder::read_enum 2022-02-20 18:58:22 -05:00
Mark Rousskov
9763486034 Move ty::print methods to Drop-based scope guards 2022-02-16 17:24:23 -05:00
Nicholas Nethercote
416399dc10 Make Decodable and Decoder infallible.
`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-22 10:38:31 +11:00
Matthias Krüger
fd09f342f3
Rollup merge of #92011 - Aaron1011:decode-span, r=michaelwoerister
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).
2022-01-03 14:44:16 +01:00
Aaron Hill
44fdb98764
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-16 18:35:15 -05:00
Aaron Hill
070bf94a6f
Remove in_band_lifetimes from rustc_middle
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-15 19:50:43 -05:00
Deadbeef
42963f4d50
Query modifier 2021-12-12 12:35:00 +08:00
Alan Egerton
cf683e644f
Rename TypeFolderFallible to FallibleTypeFolder 2021-12-02 16:14:18 +00:00
Alan Egerton
bfc434b6d0
Reduce boilerplate around infallible folders 2021-12-02 16:14:16 +00:00
LeSeulArtichaut
6e3fa20b00
Make TypeFoldable implementors short-circuit on error
Co-authored-by: Alan Egerton <eggyal@gmail.com>
2021-11-26 07:17:59 +00:00
Mark Rousskov
3228603cce Avoid generating empty closures for fieldless enums
For many enums, this avoids generating lots of tiny stubs that need to be
codegen'd and then inlined and removed by LLVM.
2021-11-22 21:22:35 -05:00
Matthias Krüger
5c454551da more clippy fixes 2021-11-07 16:59:05 +01:00
bjorn3
f5c3e83013 Avoid a branch on key being local for queries that use the same local and extern providers 2021-10-25 13:36:23 +02:00