Commit Graph

165 Commits

Author SHA1 Message Date
Caio
3266460749 Stabilize let_chains 2022-07-16 20:17:58 -03:00
David Wood
78b19a90b7 passes: migrate half of check_attr
Migrate half of the `rustc_passes::check_attr` diagnostics to using
diagnostic derives and being translatable.
2022-07-15 16:13:49 +01:00
David Wood
c3fdf74885 errors: lint on LintDiagnosticBuilder::build
Apply the `#[rustc_lint_diagnostics]` attribute to
`LintDiagnosticBuilder::build` so that diagnostic migration lints will
trigger for it.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-15 16:13:47 +01:00
Michael Goulet
d2e5a929b9 use subdiagnostic for message 2022-07-10 23:43:46 +00:00
Michael Goulet
2058333780 simplify plurals in fluent messages using hir::ConstContext 2022-07-08 03:48:10 +00:00
Michael Goulet
f97f2a47ff Migrate MutDeref, TransientMutBorrow diagnostics 2022-07-08 03:48:10 +00:00
Michael Goulet
584e5d4c4f Migrate PanicNonStr, RawPtrComparison, RawPtrToInt diagnostics 2022-07-08 03:47:59 +00:00
Michael Goulet
c48f482813 Migrate StaticAccess diagnostic 2022-07-08 03:47:46 +00:00
Michael Goulet
1c4afbd1de Migrate NonConstOp diagnostic 2022-07-08 03:47:28 +00:00
Michael Goulet
934079fd9e Migrate unstable-in-stable diagnostic 2022-07-08 03:39:08 +00:00
Michael Goulet
34d6f08f4d Use dashes instead of underscores in fluent names 2022-07-08 03:37:36 +00:00
David Wood
fedd4c63f8 lint: port asm labels diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
5524ca1a1d lint: port deref nullptr diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
2e563a4a3e lint: port clashing extern diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
bd8fe82138 lint: port incomplete features diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
acea23e796 lint: port explicit outlives diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
10676418fa lint: port keyword idents diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
10f2d3f566 lint: port test items diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
3a498a7436 lint: port ... range pattern diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
3c9bda5b20 lint: port trivial bounds diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
01a64af4dd lint: port type alias bounds diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
dbced105db lint: port unreachable pub diagnostic
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
23ee3e0914 lint: port unstable feature diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
d071f504f8 lint: port mutable transmutes diagnostic
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
dbdbdb6874 lint: port no-mangle diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
a13b70ea83 lint: port unused doc comment diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
e151d66343 lint: port deprecated attr diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
18a48c1d6c lint: port anonymous parameter diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
284ec37810 lint: port missing debug impl diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
28655bc955 lint: port missing copy impl diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
82bd2c23e5 lint: port missing documentation diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
7dffd14b96 lint: port unsafe diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
4c63a2145c lint: port non-shorthand pattern diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
d433c9a446 lint: port box pointers diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
588977b350 lint: port while true diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
4f7b10f484 lint: port unused allocation diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
e24833869f lint: port unused import braces diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
fc4f8d9bc2 lint: port unused delimiter diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
2829f519a0 lint: port path statement diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:22 +01:00
David Wood
1999a4c421 lint: port unused diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
0602729c71 lint: port atomic ordering diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
14c3016583 lint: port variant size difference diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
e5f2e0e16c lint: port improper ctypes diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
7a9bef4d83 lint: port overflowing literals diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
7ef610c003 lint: port drop trait/glue diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
8e836566f0 lint: port redundant semicolons diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
37588d6d4e lint: port pass-by-value diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
855f23773b lint: port no-op method call diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
096a69dd19 lint: port non-standard style diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
7ee4aa7003 lint: port non-fmt-panic diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
48e4bf115f lint: port non-ascii-idents diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
c29e05e745 lint: port CString ptr diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
4f35c7993b lint: port translation migration diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
674ac60d5a lint: port non-existant doc keyword diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
1c3a3e0711 lint: port impl LintPass by hand diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
0996a7ab5c lint: port ty diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
8139542598 lint: port query instability diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
e88916cc92 lint: port default hash types diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
fd57269e8c lint: port hidden unicode codepoints diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
a0624eb6c9 lint: port expectation diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
2a69640eb2 lint: port enum intrinsics diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:21 +01:00
David Wood
0f4c4c5e18 lint: port array-into-iter diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-30 08:59:19 +01:00
Michael Goulet
98af1bfecc Migrate some rustc_borrowck diagnostics to SessionDiagnostic 2022-06-28 22:41:56 +00:00
David Wood
74f3a965f4 privacy: port "in public interface" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
0557d02a9d privacy: port unnamed "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
cb90a4f30c privacy: port "item is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
be9ebfdbce privacy: port "field is private" diag
Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-27 08:53:42 +01:00
David Wood
dc90d1d987 errors: remove diagnostic message ctors
Now that typed identifiers are used in both derives, constructors for
the `DiagnosticMessage` and `SubdiagnosticMessage` types are not
required.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-24 09:08:25 +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
beetrees
be5337cde5
Migrate builtin-macros-expected-one-cfg-pattern to SessionDiagnostic 2022-06-21 20:20:00 +01:00
beetrees
6264ffbfef
Migrate builtin-macros-requires-cfg-pattern to SessionDiagnostic 2022-06-21 20:10:31 +01:00
Yuki Okushi
77316a4aaa
Rollup merge of #97912 - Kixunil:stabilize_path_try_exists, r=dtolnay
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-20 07:37:41 +09:00
Maybe Waffle
c1a2db3372 Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
Maybe Waffle
7c360dc117 Move/rename lazy::{OnceCell, Lazy} to cell::{OnceCell, LazyCell} 2022-06-16 19:53:59 +04:00
Martin Habovstiak
56087074c6 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-14 17:48:55 +02:00
Dylan DPC
d8333a7b59
Rollup merge of #97948 - davidtwco:diagnostic-translation-lints, r=oli-obk
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-14 10:35:31 +02:00
David Wood
5ba81faba6 lint: add diagnostic translation migration lints
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-10 15:50:06 +01:00
Nick Cameron
640a461388 Deactivate feature gate explicit_generic_args_with_impl_trait
Signed-off-by: Nick Cameron <nrc@ncameron.org>
2022-06-06 12:21:49 +01:00
Christian Poveda
e1d63d1d7c
migrate check_for_for_in_in_typo diagnostic 2022-05-31 16:28:05 -05:00
Christian Poveda
9ce04e3783
merge diagnostics about incorrect uses of .await 2022-05-31 15:07:44 -05:00
Christian Poveda
a06ba45487
migrate error_on_incorrect_await diagnostic 2022-05-31 14:32:07 -05:00
Christian Poveda
93a427e3ca
migrate recover_from_await_method_call diagnostic 2022-05-31 12:33:35 -05:00
Christian Poveda
29ed9a56e3
migrate maybe_consume_incorrect_semicolon diagnostic 2022-05-31 11:45:44 -05:00
Christian Poveda
bd4d1cd7a2
migrate maybe_recover_from_bad_qpath_stage_2 diagnostic 2022-05-31 11:22:26 -05: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
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
Christian Poveda
7e8517df61
migrate maybe_recover_from_bad_type_plus diagnostic 2022-05-16 17:16:27 -05:00
David Wood
47582471c6 typeck: port "no resolve overridden impl substs"
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-12 07:21:51 +01:00
David Wood
664733efd5 typeck: port "manual implementations"
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-12 07:21:51 +01:00
David Wood
78cc331bd7 typeck: port "missing type params"
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-12 07:21:51 +01:00
David Wood
5685abc96b typeck: simplify error type using () field
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-12 07:21:51 +01:00
bors
362010d6be Auto merge of #96715 - cjgillot:trait-alias-loop, r=compiler-errors
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-10 00:40:57 +00:00
Camille GILLOT
e947fad68c Point to the empty trait alias. 2022-05-09 19:03:37 +02:00
David Wood
af47257c0d typeck: port "explicit generic args w/ impl trait"
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-06 03:46:12 +01:00
David Wood
3dac70fcc0 typeck: port "unconstrained opaque type" diag
Port the "unconstrained opaque type" diagnostic to using the diagnostic
derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-05-06 03:04:30 +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
1e35bab104
separate messages by a newline 2022-04-26 11:13:23 +02:00
Christian Poveda
519dd8e9de
migrate ambiguous plus diagnostic 2022-04-25 22:55:15 +02:00
Dylan DPC
113f079a97
Rollup merge of #96029 - IsakNyberg:error-messages-fix, r=Dylan-DPC
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-19 22:57:41 +02:00