about summary refs log tree commit diff
path: root/compiler/rustc_macros/src
AgeCommit message (Collapse)AuthorLines
2022-11-07Modify comment syntax errorwanghaha-dev-2/+2
2022-11-01Rollup merge of #103575 - Xiretza:suggestions-style-attr, r=davidtwcoManish Goregaokar-20/+104
Change #[suggestion_*] attributes to use style="..." As discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20tool_only_span_suggestion), this changes `#[(multipart_)suggestion_{short,verbose,hidden}(...)]` attributes to plain `#[(multipart_)suggestion(...)]` attributes with a `style = "{short,verbose,hidden}"` parameter. It also adds a new style, `tool-only`, that corresponds to `tool_only_span_suggestion`/`tool_only_multipart_suggestion` and causes the suggestion to not be shown in human-readable output at all. Best reviewed commit-by-commit, there's a bit of noise in there. cc #100717 `@compiler-errors` r? `@davidtwco`
2022-11-01Auto merge of #103217 - mejrs:track, r=eholkbors-0/+3
Track where diagnostics were created. This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`. For example, the following code... ```rust struct A; struct B; fn main(){ let _: A = B; } ``` ...now emits the following error message: ``` error[E0308]: mismatched types --> src\main.rs:5:16 | 5 | let _: A = B; | - ^ expected struct `A`, found struct `B` | | | expected due to this -Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31 ```
2022-11-01Use `allow_internal_unstable` and add unstable reasonclubby789-1/+1
2022-10-31Specialize PartialEq for `Option<newtype>`clubby789-0/+26
2022-10-31Add more track_callermejrs-0/+3
2022-10-26Remove #[suggestion_*] attributesXiretza-15/+37
2022-10-26Convert all #[suggestion_*] attributes to #[suggestion(style = "...")]Xiretza-1/+1
Using the following command: find compiler/ -type f -name '*.rs' -exec perl -i -gpe \ 's/(#\[\w*suggestion)_(short|verbose|hidden)\(\s*(\S+,)?/\1(\3style = "\2",/g' \ '{}' +
2022-10-26Add "tool-only" suggestion styleXiretza-5/+8
2022-10-26Add style= parameter to suggestion attributesXiretza-14/+73
2022-10-23Allow specifying multiple alternative suggestionsXiretza-21/+107
This allows porting uses of span_suggestions() to diagnostic structs. Doesn't work for multipart_suggestions() because the rank would be reversed - the struct would specify multiple spans, each of which has multiple possible replacements, while multipart_suggestions() creates multiple possible replacements, each with multiple spans.
2022-10-23Migrate all diagnosticsNilstrieb-9/+9
2022-10-23Generate fluent message constant in a flat module for all cratesNilstrieb-34/+31
This will make it easier to grep for fluent message names.
2022-10-17infer: use derive moreDavid Wood-0/+2
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17macros: fully specify path to `Fn`David Wood-1/+1
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17macros: allow subdiagnostic-kind-less variantsDavid Wood-5/+16
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-17macros: support doc comments in diag derivesDavid Wood-14/+60
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-14Get rid of `rustc_query_description!`Nilstrieb-17/+28
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-14Remove unsued variable in query macroNilstrieb-7/+0
2022-10-10macros: simplify field ordering in diag deriveDavid Wood-102/+38
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-10macros: separate suggestion fmt'ing and emissionDavid Wood-23/+81
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-10macros: `#[subdiagnostic(eager)]`David Wood-21/+63
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-10errors: `AddToDiagnostic::add_to_diagnostic_with`David Wood-19/+30
`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-10macros: tidy up lint changesDavid Wood-3/+6
Small tweaks to changes made in a previous PR, unrelated to eager translation. Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-03errors: rename `typeck.ftl` to `hir_analysis.ftl`David Wood-2/+2
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-01Refactor rustc lint APIMaybe Waffle-15/+20
2022-09-27Allow raw identifiers to be used as fluent argumentsXiretza-0/+5
2022-09-27Auto merge of #102189 - davidtwco:translation-derive-enums, r=compiler-errorsbors-220/+252
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-26macros: support diagnostic derive on enumsDavid Wood-220/+252
Signed-off-by: David Wood <david.wood@huawei.com>
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-22Unify subdiagnostic attribute parsingXiretza-275/+139
2022-09-22Better error recovery in Subdiagnostic deriveXiretza-20/+28
2022-09-22Extract subdiagnostic attribute parsingXiretza-232/+297
2022-09-22Make SetOnce nicer to useXiretza-26/+39
2022-09-22Point to previous applicability when declared multiple timesXiretza-24/+11
2022-09-22Ensure #[suggestion] is only applied to correct tuple typesXiretza-33/+24
2022-09-22Ensure code= in #[suggestion(...)] is only set onceXiretza-2/+2
2022-09-22Cleanups in SessionDiagnostic deriveXiretza-11/+9
2022-09-21FIX - adopt new Diagnostic naming in newly migrated modulesJhonny Bill Mena-6/+6
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-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-15/+15
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-21UPDATE - rename DiagnosticHandler macro to DiagnosticJhonny Bill Mena-9/+9
2022-09-21UPDATE - rename AddSubdiagnostic trait to AddToDiagnosticJhonny Bill Mena-1/+1
2022-09-21UPDATE - rename DiagnosticHandler trait to IntoDiagnosticJhonny Bill Mena-19/+19
2022-09-21UPDATE - move SessionDiagnostic from rustc_session to rustc_errorsJhonny Bill Mena-1/+1
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
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-15Auto merge of #101173 - jyn514:simplify-macro-arguments, r=cjgillotbors-22/+7
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-14Update compiler/rustc_macros/src/query.rsCamille Gillot-1/+1
2022-09-09Move `TRY_LOAD_FROM_DISK` out of `rustc_queries` to `rustc_query_impl`Joshua Nelson-5/+4
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-09Don't create a new `try_load_from_disk` closure for each queryJoshua Nelson-1/+1
Instead, define a single function, parameterized only by the return type.
2022-09-09Remove dead `load_cached` code in rustc_queryJoshua Nelson-33/+2