about summary refs log tree commit diff
path: root/compiler/rustc_error_messages
AgeCommit message (Collapse)AuthorLines
2022-06-24macros: use typed identifiers in diag deriveDavid Wood-2/+2
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-21Migrate `builtin-macros-expected-one-cfg-pattern` to `SessionDiagnostic`beetrees-0/+2
2022-06-21Migrate `builtin-macros-requires-cfg-pattern` to `SessionDiagnostic`beetrees-0/+4
2022-06-20Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnayYuki Okushi-1/+0
Stabilize `Path::try_exists()` and improve doc This stabilizes the `Path::try_exists()` method which returns `Result<bool, io::Error>` instead of `bool` allowing handling of errors unrelated to the file not existing. (e.g permission errors) Along with the stabilization it also: * Warns that the `exists()` method is error-prone and suggests to use the newly stabilized one. * Suggests it instead of `metadata()` to handle errors. * Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is completely safe fixed version of `exists()`. * Renames the feature of still-unstable `std::fs::try_exists()` to `fs_try_exists` to avoid name conflict. The tracking issue #83186 remains open to track `fs_try_exists`.
2022-06-16Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock`Maybe Waffle-1/+1
2022-06-16Move/rename `lazy::{OnceCell, Lazy}` to `cell::{OnceCell, LazyCell}`Maybe Waffle-1/+1
2022-06-14Stabilize `Path::try_exists()` and improve docMartin Habovstiak-1/+0
This stabilizes the `Path::try_exists()` method which returns `Result<bool, io::Error>` instead of `bool` allowing handling of errors unrelated to the file not existing. (e.g permission errors) Along with the stabilization it also: * Warns that the `exists()` method is error-prone and suggests to use the newly stabilized one. * Suggests it instead of `metadata()` to handle errors. * Mentions TOCTOU bugs to avoid false assumption that `try_exists()` is completely safe fixed version of `exists()`. * Renames the feature of still-unstable `std::fs::try_exists()` to `fs_try_exists` to avoid name conflict. The tracking issue #83186 remains open to track `fs_try_exists`.
2022-06-14Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obkDylan DPC-0/+3
lint: add diagnostic translation migration lints Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic` or `AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. These lints are intended to be temporary - once all diagnostics have been changed then we can just change the APIs we have and that will enforce these constraints thereafter. r? `````@oli-obk`````
2022-06-10lint: add diagnostic translation migration lintsDavid Wood-0/+3
Introduce allow-by-default lints for checking whether diagnostics are written in `SessionDiagnostic`/`AddSubdiagnostic` impls and whether diagnostics are translatable. These lints can be denied for modules once they are fully migrated to impls and translation. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-06Deactivate feature gate explicit_generic_args_with_impl_traitNick Cameron-6/+0
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-05-31migrate `check_for_for_in_in_typo` diagnosticChristian Poveda-0/+4
2022-05-31merge diagnostics about incorrect uses of `.await`Christian Poveda-6/+2
2022-05-31migrate `error_on_incorrect_await` diagnosticChristian Poveda-0/+5
2022-05-31migrate `recover_from_await_method_call` diagnosticChristian Poveda-0/+4
2022-05-31migrate `maybe_consume_incorrect_semicolon` diagnosticChristian Poveda-0/+5
2022-05-31migrate `maybe_recover_from_bad_qpath_stage_2` diagnosticChristian Poveda-0/+4
2022-05-30errors: simplify referring to fluent attributesDavid Wood-6/+66
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-24macros: introduce `fluent_messages` macroDavid Wood-3/+8
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-16migrate `maybe_recover_from_bad_type_plus` diagnosticChristian Poveda-0/+9
2022-05-12typeck: port "no resolve overridden impl substs"David Wood-0/+2
Port "could not resolve substs on overridden impl" diagnostic to use the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-12typeck: port "manual implementations"David Wood-0/+5
Port the "manual implementations of `X` are experimental" diagnostic to use the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-12typeck: port "missing type params"David Wood-0/+22
Port the "the type parameter `T` must be explicitly specified" diagnostic to using a diagnostic struct. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-12typeck: simplify error type using `()` fieldDavid Wood-3/+1
Using new support for spanless subdiagnostics from `()` fields in the diagnostic derive, simplify the "explicit generic args with impl trait" diagnostic's struct. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-10Auto merge of #96715 - cjgillot:trait-alias-loop, r=compiler-errorsbors-0/+1
Fortify handing of where bounds on trait & trait alias definitions Closes https://github.com/rust-lang/rust/issues/96664 Closes https://github.com/rust-lang/rust/issues/96665 Since https://github.com/rust-lang/rust/pull/93803, when listing all bounds and predicates we now need to account for the possible presence of predicates on any of the generic parameters. Both bugs were hidden by the special handling of bounds at the generic parameter declaration position. Trait alias expansion used to confuse predicates on `Self` and where predicates. Exiting too late when listing all the bounds caused a cycle error.
2022-05-09Point to the empty trait alias.Camille GILLOT-0/+1
2022-05-06typeck: port "explicit generic args w/ impl trait"David Wood-0/+8
Port the "explicit generic arguments with impl trait" diagnostic to using the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-06typeck: port "unconstrained opaque type" diagDavid Wood-0/+3
Port the "unconstrained opaque type" diagnostic to using the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-29macros: subdiagnostic deriveDavid Wood-0/+8
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-26separate messages by a newlineChristian Poveda-0/+1
2022-04-25migrate ambiguous plus diagnosticChristian Poveda-0/+3
2022-04-19Rollup merge of #96029 - IsakNyberg:error-messages-fix, r=Dylan-DPCDylan DPC-8/+2
Refactor loop into iterator; simplify negation logic. is_dummy should return when a non-dummy is found, but instead is iterated until completion. With some inspiration from line 323 this was refactored to a single line that returns once a single counterexample is found.
2022-04-16Update compiler/rustc_error_messages/src/lib.rsIsak Nyberg-1/+1
Co-authored-by: Janusz Marcinkiewicz <virrages@gmail.com>
2022-04-14Refactor loop into iterator; simplify negation logic.Isak Nyberg-8/+2
2022-04-13errors: lazily load fallback fluent bundleDavid Wood-15/+32
Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-12sess: try sysroot candidates for fluent bundleDavid Wood-30/+39
Instead of checking only the user provided sysroot or the default (when no sysroot is provided), search user provided sysroot and then check default sysroots for locale requested by the user. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-07Suggest replacing typeof(...) with an actual typeMaybe Waffle-0/+1
This commit suggests replacing typeof(...) with an actual type of "...", for example in case of `typeof(1)` we suggest replacing it with `i32`. If the expression - Is not const (`{ let a = 1; let _: typeof(a); }`) - Can't be found (`let _: typeof(this_variable_does_not_exist)`) - Or has non-suggestable type (closure, generator, error, etc) we don't suggest anything.
2022-04-05errors: support fluent + parallel compilerDavid Wood-3/+19
Conditional on the parallel compiler being enabled, use a different `IntlLangMemoizer` which supports being sent between threads in `FluentBundle`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: use `impl Into<FluentId>`David Wood-5/+2
`FluentId` is the type alias that is used everywhere else so it should be used here too so that this doesn't need updated if the alias changes. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05session: opt for enabling directionality markersDavid Wood-3/+6
Add an option for enabling and disabling Fluent's directionality isolation markers in output. Disabled by default as these can render in some terminals and applications. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: add links to fluent documentationDavid Wood-1/+5
Add some links to the Fluent documentation to `DiagnosticMessage::FluentIdentifier` which explain what a Fluent message and attribute are. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: don't try load default locale from sysrootDavid Wood-3/+9
If the user requests a diagnostic locale of "en-US" then it doesn't make sense to try and load that from the `$sysroot` because it is just the default built-in locale. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05macros: translatable struct attrs and warningsDavid Wood-1/+86
Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: disable directionality isolation markersDavid Wood-0/+9
Fluent diagnostics can insert directionality isolation markers around interpolated variables indicating that there may be a shift from right-to-left to left-to-right text (or vice-versa). These are disabled because they are sometimes visible in the error output, but may be worth investigating in future (for example: if type names are left-to-right and the surrounding diagnostic messages are right-to-left, then these might be helpful). Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: implement sysroot/testing bundle loadingDavid Wood-12/+158
Extend loading of Fluent bundles so that bundles can be loaded from the sysroot based on the language requested by the user, or using a nightly flag. Sysroot bundles are loaded from `$sysroot/share/locale/$locale/*.ftl`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: implement fallback diagnostic translationDavid Wood-17/+63
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-0/+183
`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>