Commit Graph

240 Commits

Author SHA1 Message Date
Jhonny Bill Mena
e52e2344dc FIX - adopt new Diagnostic naming in newly migrated modules
FIX - ambiguous Diagnostic link in docs

UPDATE - rename diagnostic_items to IntoDiagnostic and AddToDiagnostic

[Gardening] FIX - formatting via `x fmt`

FIX - rebase conflicts. NOTE: Confirm wheather or not we want to handle TargetDataLayoutErrorsWrapper this way

DELETE - unneeded allow attributes in Handler method

FIX - broken test

FIX - Rebase conflict

UPDATE - rename residual _SessionDiagnostic and fix LintDiag link
2022-09-21 11:43:22 -04:00
Jhonny Bill Mena
5f91719f75 UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic
Also renames:
- sym::AddSubdiagnostic to sym:: Subdiagnostic
- rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
a3396b2070 UPDATE - rename DiagnosticHandler macro to Diagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
191fac6826 UPDATE - rename AddSubdiagnostic trait to AddToDiagnostic 2022-09-21 11:39:53 -04:00
Jhonny Bill Mena
19b348fed4 UPDATE - rename DiagnosticHandler trait to IntoDiagnostic 2022-09-21 11:39:52 -04:00
Jhonny Bill Mena
5b8152807c UPDATE - move SessionDiagnostic from rustc_session to rustc_errors 2022-09-21 11:39:52 -04:00
est31
173eb6f407 Only enable the let_else feature on bootstrap
On later stages, the feature is already stable.

Result of running:

rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-09-15 21:06:45 +02:00
bors
294f0eef73 Auto merge of #101173 - jyn514:simplify-macro-arguments, r=cjgillot
Further simplify the macros generated by `rustc_queries`

This doesn't actually move anything outside the macros, but it makes them simpler to read.

- Add a new `rustc_query_names` macro. This allows a much simpler syntax for the matchers in the macros passed to it as a callback.
- Convert `define_dep_nodes` and `alloc_once` to use `rustc_query_names`. This is possible because they only use the names
  (despite the quite complicated matchers in `define_dep_nodes`, none of the other arguments are used).
- Get rid of `rustc_dep_node_append`.

r? `@cjgillot`
2022-09-15 11:54:03 +00:00
Camille Gillot
cb2949e642
Update compiler/rustc_macros/src/query.rs 2022-09-14 19:11:53 +02:00
Joshua Nelson
9273782d55 Move TRY_LOAD_FROM_DISK out of rustc_queries to rustc_query_impl
We want to refer to `crate::plumbing::try_load_from_disk` in the const, but hard-coding it in
rustc_queries, where we don't yet know the crate this macro will be called in, seems kind of hacky.
Do it in query_impl instead.
2022-09-09 20:21:59 -05:00
Joshua Nelson
b164dbc271 Don't create a new try_load_from_disk closure for each query
Instead, define a single function, parameterized only by the return type.
2022-09-09 20:20:12 -05:00
Joshua Nelson
112419c9f0 Remove dead load_cached code in rustc_query 2022-09-09 20:16:48 -05:00
Joshua Nelson
b7c9687d2e Simplify the implementation of rustc_queries 2022-09-09 20:16:47 -05:00
Joshua Nelson
fb0c36a3fe Make the storage query modifier less general
In practice, it was only ever used with `ArenaCacheSelector`. Change it to a single boolean
`arena_cache` rather than allowing queries to specify an arbitrary type.
2022-09-09 20:16:47 -05:00
Joshua Nelson
3a4e3c7788 Get rid of the emitted rustc_query_names and rustc_cached_queries macro
We can avoid these by adding slightly more information to `rustc_query_append` instead.
2022-09-06 21:46:31 -05:00
Joshua Nelson
c630c87ceb Support doc-comments in define_dep_nodes 2022-09-06 21:43:15 -05:00
Joshua Nelson
05886e28a4 Further simplify the macros generated by rustc_queries
- Add a new `rustc_query_names` macro. This allows a much simpler syntax for the matchers in the macros passed to it as a callback.
- Convert `define_dep_nodes` and `alloc_once` to use `rustc_query_names`. This is possible because they only use the names
  (despite the quite complicated matchers in `define_dep_nodes`, none of the other arguments are used).
- Get rid of `rustc_dep_node_append`.
2022-09-06 21:43:15 -05:00
Jhonny Bill Mena
321e60bf34 UPDATE - into_diagnostic to take a Handler instead of a ParseSess
Suggested by the team in this Zulip Topic https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20SessionDiagnostic.20on.20Handler

Handler already has almost all the capabilities of ParseSess when it comes to diagnostic emission, in this migration we only needed to add the ability to access source_map from the emitter in order to get a Snippet and the start_point. Not sure if this is the best way to address this gap
2022-09-05 02:18:45 -04:00
Xiretza
d9b874c083 Allow deriving multiple subdiagnostics using one SessionSubdiagnostic
This reimplements ac638c1, which had to be reverted in the previous
commit because it contains a rebase accident that itself reverted
significant unrelated changes to SessionSubdiagnostic.
2022-09-01 21:18:01 +02:00
Xiretza
9df75ee254 Revert parts of "use derive proc macro to impl SessionDiagnostic"
This reverts parts of commit ac638c1f5f.

During rebase, this commit accidentally reverted unrelated changes to
the subdiagnostic derive (those allowing multipart_suggestions to be
derived). This commit reverts all changes to the subdiagnostic code made
in ac638c1f5f, the next commit will reintroduce the actually intended
changes.
2022-09-01 19:42:49 +02:00
Matthias Krüger
e5356712b9
Rollup merge of #101165 - ldm0:drain_to_iter, r=cjgillot
Use more `into_iter` rather than `drain(..)`

Clearer semantic.
2022-08-31 21:30:13 +02:00
Yuanheng Li
ac638c1f5f use derive proc macro to impl SessionDiagnostic
fixes `SessionSubdiagnostic` to accept multiple attributes
emitting list of fluent message remains unresolved
2022-08-31 19:43:12 +08:00
Xiretza
31b939b315 Rework SessionSubdiagnostic derive to support multipart_suggestion 2022-08-30 12:18:43 +02:00
Xiretza
9dc0643744 SessionSubdiagnostic: make #[applicability] optional 2022-08-30 09:48:03 +02:00
Xiretza
6e8dad5c07 Use span_suggestion_with_style in SessionSubdiagnostic derive 2022-08-30 09:48:00 +02:00
Donough Liu
97b1a6146c Use more into_iter rather than drain(..) 2022-08-30 04:42:03 +01:00
Matthias Krüger
6667754694
Rollup merge of #100959 - LuisCardosoOliveira:translation-rename-attr-warning, r=davidtwco
translations: rename warn_ to warning

## Description

This MR renames the the macro `warn_` to `warning`.

To give a little bit of context, as [explained](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20diag.20translation/near/295074146) by ```````@davidtwco``````` in the Zulip channel, `warn_`  was named like that because the keyword `warn` is a built-in attribute and at the time this macro was created the word `warning` was also
taken.

However, it is no longer the case and we can rename `warn_` to `warning`.
2022-08-29 06:34:47 +02:00
bors
4065b89b1e Auto merge of #100946 - jyn514:query-system-3, r=cjgillot
Simplify the arguments to macros generated by the `rustc_queries` proc macro

Very small cleanup. Based on https://github.com/rust-lang/rust/pull/100436 which modifies some of the same code.

r? `@cjgillot`
2022-08-27 08:53:24 +00:00
bors
cfb5ae26a4 Auto merge of #100748 - SparrowLii:query_depth, r=cjgillot
add `depth_limit` in `QueryVTable` to avoid entering a new tcx in `layout_of`

Fixes #49735
Updates #48685

The `layout_of` query needs to check whether it overflows the depth limit, and the current implementation needs to create a new `ImplicitCtxt` inside `layout_of`. However, `start_query` will already create a new `ImplicitCtxt`, so we can check the depth limit in `start_query`.

We can tell whether we need to check the depth limit simply by whether the return value of `to_debug_str` of the query is `layout_of`. But I think adding the `depth_limit` field in `QueryVTable` may be more elegant and more scalable.
2022-08-25 21:27:38 +00:00
bors
76531befc4 Auto merge of #100436 - jyn514:macro-query-system, r=cjgillot
try and simplify some things in the query system
2022-08-25 05:35:27 +00:00
Luis Cardoso
b508b50617 translations: rename warn_ to warning
The macro warn_ was named like that because it the
keyword warn is a built-in attribute and at the time
this macro was created the word 'warning' was also
taken.

However it is no longer the case and we can rename
warn_ to warning.
2022-08-24 19:12:36 +02:00
bors
ebfc7aa531 Auto merge of #100803 - klensy:do-not-encode-preinterned-symbols, r=bjorn3
Symbols: do not write string values of preinterned symbols into compiled artifacts

r? `@bjorn3`

Followup for #98851

https://github.com/rust-lang/rust/pull/98851#issuecomment-1215606291
2022-08-24 16:56:32 +00:00
Joshua Nelson
b061550ed3 Remove the $tcx:tt parameter from rustc_query_description
It's unnecessary.
2022-08-24 00:37:49 -05:00
Joshua Nelson
7b8e2a52ff Simplify the syntax for macros generated by rustc_queries
- Disallow multiple macros callbacks in the same invocation. In practice, this was never used.
- Remove the `[]` brackets around the macro name
- Require an `ident`, not an arbitrary `tt`
2022-08-24 00:37:49 -05:00
Joshua Nelson
b53761969f Remove $tcx metavariable from rustc_query_append
It's not actually necessary and it makes the code harder to read.
2022-08-23 21:33:19 -05:00
SparrowLii
cbc6bd2019 add depth_limit in QueryVTable 2022-08-24 09:42:12 +08:00
bors
87991d5f5d Auto merge of #100675 - Xiretza:fluent-mandate-crate-prefix, r=davidtwco
fluent: mandate slug names to be prefixed by crate name

This is currently only convention, but not actively checked for.

Additionally, improve error messages to highlight the path of the offending fluent file rather than the identifier preceding it.

This will conflict with #100671, so I'll leave it as draft until that's merged.
2022-08-23 22:30:07 +00:00
Dylan DPC
fd93ab43ef
Rollup merge of #100857 - camsteffen:query-parse-refactor, r=davidtwco
Refactor query modifier parsing

Reduce redundancy and improve error spans.
2022-08-23 20:40:07 +05:30
Xiretza
28b29db8f0 fluent: point to path containing error instead of module name
Example error before:

error: name `generic_does_not_live_long_enough` does not start with the crate name
  --> compiler/rustc_error_messages/src/lib.rs:33:17
   |
33 |     borrowck => "../locales/en-US/borrowck.ftl",
   |     ^^^^^^^^
   |
   = help: prepend `borrowck_` to the slug name: `borrowck_generic_does_not_live_long_enough`

after:

error: name `generic_does_not_live_long_enough` does not start with the crate name
  --> compiler/rustc_error_messages/src/lib.rs:33:17
   |
33 |     borrowck => "../locales/en-US/borrowck.ftl",
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: prepend `borrowck_` to the slug name: `borrowck_generic_does_not_live_long_enough`
2022-08-22 08:42:46 +02:00
Xiretza
c9b1a5874d fluent: mandate slug names to be prefixed by crate name 2022-08-22 08:42:44 +02:00
Cameron Steffen
c31f29626f Refactor query modifier parsing 2022-08-21 20:41:17 -05:00
finalchild
8ed8aac3ca Fix build_format not unescaping braces properly
Co-authored-by: RanolP <public.ranolp@gmail.com>
2022-08-22 01:11:59 +09:00
Xiretza
7f3a6fd7f6 Replace #[lint/warning/error] with #[diag] 2022-08-21 09:17:43 +02:00
Xiretza
bd0d3f745d Disallow #[primary_span] on LintDiagnostics 2022-08-21 09:17:43 +02:00
Xiretza
a960f8304c Make derived SessionDiagnostics generic on diagnostic level
Deriving SessionDiagnostic on a type no longer forces that diagnostic to
be one of warning, error, or fatal. The level is instead decided when
the struct is passed to the respective Handler::emit_*() method.
2022-08-21 09:17:43 +02:00
klensy
0016356f2b symbols: add is_preinterned fn to check if symbol was preinterned in compiler 2022-08-20 15:13:41 +03:00
5225225
09ea9f0a87 Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
est31
ca16a8d76c Change fluent_messages macro to expect _ slugs instead of - slugs
For the most part, the macro actually worked with _ slugs, but the prefix_something -> prefix::something
conversion was not implemented.

We don't want to accept - slugs for consistency reasons.
We thus error if a name is found with - inside.
This ensures a consistent style.
2022-08-12 22:26:08 +02:00
est31
6c4fc85f9c Update rustdoc to new slug style 2022-08-12 22:22:55 +02:00
klensy
754b52669f dedupe 'annotate-snippets' crate versions 2022-08-02 21:07:01 +03:00
Matthias Krüger
611bbcb044 clippy::perf fixes 2022-07-20 11:48:11 +02:00
David Wood
81cf2294b4 macros: support adding warnings to diags
Both diagnostic and subdiagnostic derives were missing the ability to
add warnings to diagnostics - this is made more difficult by the `warn`
attribute already existing, so this name being unavailable for the
derives to use. `#[warn_]` is used instead, which requires
special-casing so that `{span_,}warn` is called instead of
`{span_,}warn_`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:49 +01:00
David Wood
88c11c5bff macros: support MultiSpan in diag derives
Add support for `MultiSpan` with any of the attributes that work on a
`Span` - requires that diagnostic logic generated for these attributes
are emitted in the by-move block rather than the by-ref block that they
would normally have been generated in.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:49 +01:00
Michael Goulet
34d6f08f4d Use dashes instead of underscores in fluent names 2022-07-08 03:37:36 +00:00
Dylan DPC
df1f415305
Rollup merge of #98884 - davidtwco:translation-on-lints-derive, r=oli-obk
macros: `LintDiagnostic` derive

- Move `LintDiagnosticBuilder` into `rustc_errors` so that a diagnostic derive can refer to it.
- Introduce a `DecorateLint` trait, which is equivalent to `SessionDiagnostic` or `AddToDiagnostic` but for lints. Necessary without making more changes to the lint infrastructure as `DecorateLint` takes a `LintDiagnosticBuilder` and re-uses all of the existing logic for determining what type of diagnostic a lint should be emitted as (e.g. error/warning).
- Various refactorings of the diagnostic derive machinery (extracting `build_field_mapping` helper and moving `sess` field out of the `DiagnosticDeriveBuilder`).
- Introduce a `LintDiagnostic` derive macro that works almost exactly like the `SessionDiagnostic` derive macro  except that it derives a `DecorateLint` implementation instead. A new derive is necessary for this because `SessionDiagnostic` is intended for when the generated code creates the diagnostic. `AddToDiagnostic` could have been used but it would have required more changes to the lint machinery.

~~At time of opening this pull request, ignore all of the commits from #98624, it's just the last few commits that are new.~~

r? `@oli-obk`
2022-07-06 14:49:10 +05:30
Alan Egerton
e4b9625b87
Add #[derive(TypeVisitable)] 2022-07-05 22:25:15 +01:00
David Wood
9d864c8d56 macros: add diagnostic derive for lints
`SessionDiagnostic` isn't suitable for use on lints as whether or not it
creates an error or a warning is decided at compile-time by the macro,
whereas lints decide this at runtime based on the location of the lint
being reported (as it will depend on the user's `allow`/`deny`
attributes, etc). Re-using most of the machinery for
`SessionDiagnostic`, this macro introduces a `LintDiagnostic` derive
which implements a `DecorateLint` trait, taking a
`LintDiagnosticBuilder` and adding to the lint according to the
diagnostic struct.
2022-07-05 16:00:21 +01:00
David Wood
7f9d8480d6 macros: move sess out of builder
`sess` field of `SessionDiagnosticDeriveBuilder` is never actually used
in the builder's member functions, so it doesn't need to be a field.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05 16:00:21 +01:00
David Wood
406579ae13 macros: introduce build_field_mapping
Move the logic for building a field mapping (which is used by the
building of format strings in `suggestion` annotations) into a helper
function.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05 16:00:21 +01:00
David Wood
84ec77769f macros: fix documentation link for diag derive
Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-05 16:00:20 +01:00
David Wood
abd3467d47 macros: use typed identifiers in subdiag derive
As in the diagnostic derive, using typed identifiers in the
subdiagnostic derive improves the diagnostics of using the subdiagnostic
derive as Fluent messages will be confirmed to exist at compile-time.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-24 09:08:25 +01:00
David Wood
99bc979403 macros: use typed identifiers in diag derive
Using typed identifiers instead of strings with the Fluent identifier
enables the diagnostic derive to benefit from the compile-time
validation that comes with typed identifiers - use of a non-existent
Fluent identifier will not compile.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-24 09:08:25 +01:00
bors
1a97162cb2 Auto merge of #94732 - nnethercote:infallible-encoder, r=bjorn3
Make `Encodable` and `Encoder` infallible.

A follow-up to #93066.

r? `@ghost`
2022-06-08 10:24:12 +00:00
Nicholas Nethercote
90db033955 Folding revamp.
This commit makes type folding more like the way chalk does it.

Currently, `TypeFoldable` has `fold_with` and `super_fold_with` methods.
- `fold_with` is the standard entry point, and defaults to calling
  `super_fold_with`.
- `super_fold_with` does the actual work of traversing a type.
- For a few types of interest (`Ty`, `Region`, etc.) `fold_with` instead
  calls into a `TypeFolder`, which can then call back into
  `super_fold_with`.

With the new approach, `TypeFoldable` has `fold_with` and
`TypeSuperFoldable` has `super_fold_with`.
- `fold_with` is still the standard entry point, *and* it does the
  actual work of traversing a type, for all types except types of
  interest.
- `super_fold_with` is only implemented for the types of interest.

Benefits of the new model.
- I find it easier to understand. The distinction between types of
  interest and other types is clearer, and `super_fold_with` doesn't
  exist for most types.
- With the current model is easy to get confused and implement a
  `super_fold_with` method that should be left defaulted. (Some of the
  precursor commits fixed such cases.)
- With the current model it's easy to call `super_fold_with` within
  `TypeFolder` impls where `fold_with` should be called. The new
  approach makes this mistake impossible, and this commit fixes a number
  of such cases.
- It's potentially faster, because it avoids the `fold_with` ->
  `super_fold_with` call in all cases except types of interest. A lot of
  the time the compile would inline those away, but not necessarily
  always.
2022-06-08 09:24:03 +10:00
Nicholas Nethercote
1acbe7573d Use delayed error handling for Encodable and Encoder infallible.
There are two impls of the `Encoder` trait: `opaque::Encoder` and
`opaque::FileEncoder`. The former encodes into memory and is infallible, the
latter writes to file and is fallible.

Currently, standard `Result`/`?`/`unwrap` error handling is used, but this is a
bit verbose and has non-trivial cost, which is annoying given how rare failures
are (especially in the infallible `opaque::Encoder` case).

This commit changes how `Encoder` fallibility is handled. All the `emit_*`
methods are now infallible. `opaque::Encoder` requires no great changes for
this. `opaque::FileEncoder` now implements a delayed error handling strategy.
If a failure occurs, it records this via the `res` field, and all subsequent
encoding operations are skipped if `res` indicates an error has occurred. Once
encoding is complete, the new `finish` method is called, which returns a
`Result`. In other words, there is now a single `Result`-producing method
instead of many of them.

This has very little effect on how any file errors are reported if
`opaque::FileEncoder` has any failures.

Much of this commit is boring mechanical changes, removing `Result` return
values and `?` or `unwrap` from expressions. The more interesting parts are as
follows.
- serialize.rs: The `Encoder` trait gains an `Ok` associated type. The
  `into_inner` method is changed into `finish`, which returns
  `Result<Vec<u8>, !>`.
- opaque.rs: The `FileEncoder` adopts the delayed error handling
  strategy. Its `Ok` type is a `usize`, returning the number of bytes
  written, replacing previous uses of `FileEncoder::position`.
- Various methods that take an encoder now consume it, rather than being
  passed a mutable reference, e.g. `serialize_query_result_cache`.
2022-06-08 07:01:26 +10:00
bjorn3
22e8d5f80e Inline many methods of Encoder
They aren't overridden anyway
2022-06-03 17:01:53 +00:00
bjorn3
5cd29225a5 Remove all names from Encoder
They aren't used anymore now that the json format has been removed
2022-06-03 16:56:17 +00:00
David Wood
f669b78ffc errors: simplify referring to fluent attributes
To render the message of a Fluent attribute, the identifier of the
Fluent message must be known. `DiagnosticMessage::FluentIdentifier`
contains both the message's identifier and optionally the identifier of
an attribute. Generated constants for each attribute would therefore
need to be named uniquely (amongst all error messages) or be able to
refer to only the attribute identifier which will be combined with a
message identifier later. In this commit, the latter strategy is
implemented as part of the `Diagnostic` type's functions for adding
subdiagnostics of various kinds.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-30 13:38:19 +01:00
Michael Goulet
4638915940 Make TyCtxt implement Interner, make HashStable generic and move to rustc_type_ir 2022-05-28 12:16:05 -07:00
Wilco Kusee
a7015fe816 Move things to rustc_type_ir 2022-05-28 11:38:22 -07:00
David Wood
552eb3295a macros: introduce fluent_messages macro
Adds a new `fluent_messages` macro which performs compile-time
validation of the compiler's Fluent resources (i.e. that the resources
parse and don't multiply define the same messages) and generates
constants that make using those messages in diagnostics more ergonomic.

For example, given the following invocation of the macro..

```ignore (rust)
fluent_messages! {
    typeck => "./typeck.ftl",
}
```
..where `typeck.ftl` has the following contents..

```fluent
typeck-field-multiply-specified-in-initializer =
    field `{$ident}` specified more than once
    .label = used more than once
    .label-previous-use = first use of `{$ident}`
```
...then the macro parse the Fluent resource, emitting a diagnostic if it
fails to do so, and will generate the following code:

```ignore (rust)
pub static DEFAULT_LOCALE_RESOURCES: &'static [&'static str] = &[
    include_str!("./typeck.ftl"),
];

mod fluent_generated {
    mod typeck {
        pub const field_multiply_specified_in_initializer: DiagnosticMessage =
            DiagnosticMessage::fluent("typeck-field-multiply-specified-in-initializer");
        pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage =
            DiagnosticMessage::fluent_attr(
                "typeck-field-multiply-specified-in-initializer",
                "previous-use-label"
            );
    }
}
```

When emitting a diagnostic, the generated constants can be used as
follows:

```ignore (rust)
let mut err = sess.struct_span_err(
    span,
    fluent::typeck::field_multiply_specified_in_initializer
);
err.span_default_label(span);
err.span_label(
    previous_use_span,
    fluent::typeck::field_multiply_specified_in_initializer_label_previous_use
);
err.emit();
```

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-24 16:48:17 +01:00
David Wood
6e85efda22 macros: change code block language
With `ignore (rust)` rather than `ignore (pseudo-Rust)` my editor
highlights the code in the block, which is nicer.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-24 16:48:17 +01:00
Christian Poveda
8227e69018
formatting 2022-05-19 09:02:50 -05:00
Christian Poveda
d839d2ecc2
let generate_field_attrs_code create FieldInfo
this simplifies the code inside the `structure.each` closure argument
and allows to remove the `vis` field from `FieldInfo`.
2022-05-19 00:47:45 -05:00
Christian Poveda
7e9be9240c
remove unnecessary generics 2022-05-18 10:55:35 -05:00
Christian Poveda
952121933e
move misplaced comment 2022-05-18 10:53:48 -05:00
Christian Poveda
19e1f73085
generate set_arg code inside generate_field_attrs_code 2022-05-18 10:50:59 -05:00
Christian Poveda
462c1c846b
generate code for subdiagnostic fields in the second match 2022-05-17 13:10:15 -05:00
David Wood
de3e8ca2f3 errors: set_arg takes IntoDiagnosticArg
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-12 07:21:51 +01:00
David Wood
7b7061dd89 macros: spanless subdiagnostics from () fields
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-12 07:21:51 +01:00
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