about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2022-08-04Rollup merge of #98796 - compiler-errors:no-semi-if-comma, r=estebankMatthias Krüger-1/+2
Do not exclusively suggest `;` when `,` is also a choice Fixes #96791
2022-07-29Add diagnostic when using public instead of pubGimgim-0/+11
2022-07-23Do not suggest adding `;` when `,` is also a choiceMichael Goulet-1/+2
2022-07-01update cfg(bootstrap)sPietro Albini-2/+2
2022-06-27various: add `rustc_lint_diagnostics` to diag fnsDavid Wood-0/+2
The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this commit adds the attribute to many more functions. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-24macros: use typed identifiers in subdiag deriveDavid Wood-3/+3
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-24macros: use typed identifiers in diag deriveDavid Wood-9/+9
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-20Rollup merge of #98183 - dtolnay:emptybound, r=lcnrYuki Okushi-1/+4
Fix pretty printing of empty bound lists in where-clause Repro: ```rust macro_rules! assert_item_stringify { ($item:item $expected:literal) => { assert_eq!(stringify!($item), $expected); }; } fn main() { assert_item_stringify! { fn f<'a, T>() where 'a:, T: {} "fn f<'a, T>() where 'a:, T: {}" } } ``` Previously this assertion would fail because rustc renders the where-clause as `where 'a, T` which is invalid syntax. This PR makes the above assertion pass. This bug also affects `-Zunpretty=expanded`. The intention is for that to emit syntactically valid code, but the buggy output is not valid Rust syntax. ```console $ rustc <(echo "fn f<'a, T>() where 'a:, T: {}") -Zunpretty=expanded #![feature(prelude_import)] #![no_std] #[prelude_import] use ::std::prelude::rust_2015::*; #[macro_use] extern crate std; fn f<'a, T>() where 'a, T {} ``` ```console $ rustc <(echo "fn f<'a, T>() where 'a:, T: {}") -Zunpretty=expanded | rustc - error: expected `:`, found `,` --> <anon>:7:23 | 7 | fn f<'a, T>() where 'a, T {} | ^ expected `:` ```
2022-06-17remove the rest of unnecessary `to_string`Takayuki Maeda-4/+4
2022-06-16Fix pretty printing of empty type bound lists in where-clauseDavid Tolnay-1/+4
2022-06-14Rollup merge of #95211 - terrarier2111:improve-parser, r=compiler-errorsYuki Okushi-0/+30
Improve parser diagnostics This pr fixes https://github.com/rust-lang/rust/issues/93867 and contains a couple of diagnostics related changes to the parser. Here is a short list with some of the changes: - don't suggest the same thing that is the current token - suggest removing the current token if the following token is one of the suggestions (maybe incorrect) - tell the user to put a type or lifetime after where if there is none (as a warning) - reduce the amount of tokens suggested (via the new eat_noexpect and check_noexpect methods) If any of these changes are undesirable, i can remove them, thanks!
2022-06-13remove unnecessary `to_string` and `String::new` for `tool_only_span_suggestion`Takayuki Maeda-1/+1
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-19/+19
2022-06-12Improves parser diagnostics, fixes #93867threadexception-0/+30
2022-06-12use `create_snapshot_for_diagnostic` instead of `clone`Takayuki Maeda-2/+2
2022-06-02Rollup merge of #97587 - pvdrz:maybe-recover-from-bad-qpath-stage-2, r=davidtwcoDylan DPC-44/+77
Migrate more diagnostics to use the `#[derive(SessionDiagnostic)]` r? ``@davidtwco``
2022-06-02Rollup merge of #97166 - nnethercote:move-conditions-out, r=estebankYuki Okushi-31/+11
Move conditions out of recover/report functions. `Parser` has six recover/report functions that are passed a boolean, and nothing is done if the boolean has a particular value. This PR moves the tests outside the functions. This has the following effects. - The number of lines of code goes down. - Some `use` items become shorter. - Avoids the strangeness whereby 11 out of 12 calls to `maybe_recover_from_bad_qpath` pass `true` as the second argument. - Makes it clear at the call site that only one of `maybe_recover_from_bad_type_plus` and `maybe_report_ambiguous_plus` will be run. r? `@estebank`
2022-06-01rename `sp` to `span`Christian Poveda-2/+2
2022-05-31migrate `check_for_for_in_in_typo` diagnosticChristian Poveda-8/+13
2022-05-31merge diagnostics about incorrect uses of `.await`Christian Poveda-3/+3
2022-05-31migrate `error_on_incorrect_await` diagnosticChristian Poveda-9/+22
2022-05-31use `suggestion_short` for incorrect semicolon diagnosticChristian Poveda-1/+1
2022-05-31migrate `recover_from_await_method_call` diagnosticChristian Poveda-8/+10
2022-05-31migrate `maybe_consume_incorrect_semicolon` diagnosticChristian Poveda-9/+18
2022-05-31migrate `maybe_recover_from_bad_qpath_stage_2` diagnosticChristian Poveda-9/+13
2022-05-30errors: simplify referring to fluent attributesDavid Wood-7/+4
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-24Auto merge of #97121 - pvdrz:do-subdiagnostics-later, r=davidtwcobors-9/+7
Avoid double binding of subdiagnostics inside `#[derive(SessionDiagnostic)]` r? `@davidtwco`
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-5/+5
2022-05-19Move condition out of `maybe_recover_unexpected_comma`.Nicholas Nethercote-4/+3
2022-05-19Move condition out of `maybe_recover_colon_colon_in_pat_typo`.Nicholas Nethercote-4/+3
2022-05-19Move condition out of `maybe_report_ambiguous_plus` and ↵Nicholas Nethercote-14/+4
`maybe_recover_from_bad_type_plus`.
2022-05-19Move condition out of `maybe_recover_from_question_mark`.Nicholas Nethercote-9/+2
2022-05-19Move condition out of `maybe_recover_from_bad_qpath`.Nicholas Nethercote-3/+2
2022-05-17generate code for `subdiagnostic` fields in the second `match`Christian Poveda-9/+7
2022-05-16keep bounds where they wereChristian Poveda-2/+1
2022-05-16migrate `maybe_recover_from_bad_type_plus` diagnosticChristian Poveda-25/+48
2022-05-11Remove some unnecessary invisible delimiter checks.Nicholas Nethercote-2/+1
These seem to have no useful effect... they don't seem useful from a code inspection point of view, and they affect anything in the test suite.
2022-04-28Rollup merge of #96433 - petrochenkov:delim, r=nnethercoteDylan DPC-42/+43
rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter` Compiler cannot reuse `proc_macro::Delimiter` directly due to extra impls, but can at least use the same naming. After this PR the only difference between these two enums is that `proc_macro::Delimiter::None` is turned into `token::Delimiter::Invisible`. It's my mistake that the invisible delimiter is called `None` on stable, during the stabilization I audited the naming and wrote the docs, but missed the fact that the `None` naming gives a wrong and confusing impression about what this thing is. cc https://github.com/rust-lang/rust/pull/96421 r? ``@nnethercote``
2022-04-28Rollup merge of #96405 - pvdrz:ambiguous-plus-diagnostic, r=davidtwcoDylan DPC-9/+12
Migrate ambiguous plus diagnostic to the new derive macro r? ````@davidtwco```` ````@jyn514````
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-42/+43
2022-04-27rename `sum_with_parens`Christian Poveda-6/+3
2022-04-26move `AmbigousPlus` outsideChristian Poveda-9/+10
2022-04-26avoid `format!`Christian Poveda-2/+2
2022-04-25remove old codeChristian Poveda-9/+0
2022-04-25migrate ambiguous plus diagnosticChristian Poveda-9/+23
2022-04-23Better handle too many `#` recovery in raw strEsteban Küber-9/+34
Point at all the unnecessary trailing `#`. Better handle interaction with outer attributes when `;` is missing. Fix #95030.
2022-04-05errors: implement fallback diagnostic translationDavid Wood-14/+22
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
2022-04-05span: move `MultiSpan`David Wood-3/+3
`MultiSpan` contains labels, which are more complicated with the introduction of diagnostic translation and will use types from `rustc_errors` - however, `rustc_errors` depends on `rustc_span` so `rustc_span` cannot use types like `DiagnosticMessage` without dependency cycles. Introduce a new `rustc_error_messages` crate that can contain `DiagnosticMessage` and `MultiSpan`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-03Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwcobors-1/+213
Suggest `i += 1` when we see `i++` or `++i` Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--` is tricky to handle). This is a continuation of #83536. r? `@estebank`
2022-04-02Fix doctest multi-line mod attributes handlingGuillaume Gomez-0/+4