Commit Graph

217 Commits

Author SHA1 Message Date
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
Nilstrieb
2459569776
Generate fluent message constant in a flat module for all crates
This will make it easier to grep for fluent message names.
2022-10-23 10:09:44 +02:00
David Wood
913f597402 infer: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
David Wood
feeeb11d89 macros: fully specify path to Fn
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
David Wood
1045e69e73 macros: allow subdiagnostic-kind-less variants
Sometimes it is convenient to return a subdiagnostic enum where one or
more of the variants don't add anything to the diagnostic.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
David Wood
7fbaf27696 macros: support doc comments in diag derives
Documentation comments shouldn't affect the diagnostic derive in any
way, but explicit support has to be added for ignoring the `doc`
attribute.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
Nilstrieb
167b3bd3b2
Get rid of rustc_query_description!
Queries can provide an arbitrary expression for their description and
their caching behavior. Before, these expressions where stored in a
`rustc_query_description` macro emitted by the `rustc_queries` macro,
and then used in `rustc_query_impl` to fill out the methods for the
`QueryDescription` trait.

Instead, we now emit two new modules from `rustc_queries` containing the
functions with the expressions. `rustc_query_impl` calls these functions
now instead of invoking the macro.

Since we are now defining some of the functions in
`rustc_middle::query`, we now need all the imports for the key types
there as well.
2022-10-14 22:35:56 +02:00
Nilstrieb
1566273f48
Remove unsued variable in query macro 2022-10-14 22:32:05 +02:00
David Wood
fbac1f288b macros: simplify field ordering in diag derive
Following the approach taken in earlier commits to separate formatting
initialization from use in the subdiagnostic derive, simplify the
diagnostic derive by removing the field-ordering logic that previously
solved this problem.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood
7e20929e55 macros: separate suggestion fmt'ing and emission
Diagnostic derives have previously had to take special care when
ordering the generated code so that fields were not used after a move.

This is unlikely for most fields because a field is either annotated
with a subdiagnostic attribute and is thus likely a `Span` and copiable,
or is a argument, in which case it is only used once by `set_arg`
anyway.

However, format strings for code in suggestions can result in fields
being used after being moved if not ordered carefully. As a result, the
derive currently puts `set_arg` calls last (just before emission), such
as:

```rust
let diag = { /* create diagnostic */ };

diag.span_suggestion_with_style(
    span,
    fluent::crate::slug,
    format!("{}", __binding_0),
    Applicability::Unknown,
    SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */

diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */

diag.emit();
```

For eager translation, this doesn't work, as the message being
translated eagerly can assume that all arguments are available - so
arguments _must_ be set first.

Format strings for suggestion code are now separated into two parts - an
initialization line that performs the formatting into a variable, and a
usage in the subdiagnostic addition.

By separating these parts, the initialization can happen before
arguments are set, preserving the desired order so that code compiles,
while still enabling arguments to be set before subdiagnostics are
added.

```rust
let diag = { /* create diagnostic */ };

let __code_0 = format!("{}", __binding_0);
/* + other formatting */

diag.set_arg("foo", __binding_0);
/* + other `set_arg` calls */

diag.span_suggestion_with_style(
    span,
    fluent::crate::slug,
    __code_0,
    Applicability::Unknown,
    SuggestionStyle::ShowAlways
);
/* + other subdiagnostic additions */

diag.emit();
```

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood
291a4736d9 macros: #[subdiagnostic(eager)]
Add support for `eager` argument to the `subdiagnostic` attribute which
generates a call to `eager_subdiagnostic`.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood
b4ac26289f errors: AddToDiagnostic::add_to_diagnostic_with
`AddToDiagnostic::add_to_diagnostic_with` is similar to the previous
`AddToDiagnostic::add_to_diagnostic` but takes a function that can be
used by the caller to modify diagnostic messages originating from the
subdiagnostic (such as performing translation eagerly).

`add_to_diagnostic` now just calls `add_to_diagnostic_with` with an
empty closure.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00
David Wood
febbf71219 macros: tidy up lint changes
Small tweaks to changes made in a previous PR, unrelated to eager
translation.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 13:32:23 +01:00
David Wood
c4418e1940 errors: rename typeck.ftl to hir_analysis.ftl
In #102306, `rustc_typeck` was renamed to `rustc_hir_analysis` but the
diagnostic resources were not renamed - which is what this commit
changes.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-03 13:52:17 +01:00
Maybe Waffle
a8f7e244b7 Refactor rustc lint API 2022-10-01 10:03:06 +00:00
Xiretza
4d02892acf Allow raw identifiers to be used as fluent arguments 2022-09-27 20:29:18 +02:00
bors
de0b511daa Auto merge of #102189 - davidtwco:translation-derive-enums, r=compiler-errors
macros: diagnostic derive on enums

Part of #100717.

Extends `#[derive(Diagnostic)]` to work on enums too where each variant acts like a distinct diagnostic - being able to represent diagnostics this way can be quite a bit simpler for some parts of the compiler.

r? `@compiler-errors`
cc `@Xiretza`
2022-09-27 04:39:25 +00:00
David Wood
f20c882b8b macros: support diagnostic derive on enums
Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-26 11:59:19 +01:00
Pietro Albini
3975d55d98
remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
Xiretza
336a72a8da Unify subdiagnostic attribute parsing 2022-09-22 17:25:50 +02:00
Xiretza
57679fb1c5 Better error recovery in Subdiagnostic derive 2022-09-22 17:25:50 +02:00
Xiretza
e7251cc441 Extract subdiagnostic attribute parsing 2022-09-22 17:25:50 +02:00
Xiretza
d4a1a6f698 Make SetOnce nicer to use 2022-09-22 17:25:50 +02:00
Xiretza
efb20bc855 Point to previous applicability when declared multiple times 2022-09-22 17:25:50 +02:00
Xiretza
ec85a1b263 Ensure #[suggestion] is only applied to correct tuple types 2022-09-22 17:25:50 +02:00
Xiretza
2e72387fd0 Ensure code= in #[suggestion(...)] is only set once 2022-09-22 17:25:50 +02:00
Xiretza
adcc55d622 Cleanups in SessionDiagnostic derive 2022-09-22 17:25:50 +02:00
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