Commit Graph

643 Commits

Author SHA1 Message Date
Matthias Krüger
6438f4addc
Rollup merge of #100787 - chenyukang:fix-100770-pretty-crash, r=petrochenkov
Pretty printing give proper error message without panic

Fixes #100770
2022-08-31 21:30:07 +02:00
Nathan Stocks
30adfd6a17 port 5 new diagnostics that appeared in master 2022-08-31 10:56:42 -06:00
Nathan Stocks
0d65819d52 respond to review feedback: mainly eliminate as many conversions as possible...
- ... when creating diagnostics in rustc_metadata
-  use the error_code! macro
- pass macro output to diag.code()
- use fluent from within manual implementation of SessionDiagnostic
- emit the untested errors in case they occur in the wild
- stop panicking in the probably-not-dead code, add fixme to write test
2022-08-31 10:56:42 -06:00
Nathan Stocks
d0ba1fbaa4 port of locator.rs to SessionDiagnostics, fix some of the errors
revealed by tests, manually add a panic to test for dead code
2022-08-31 10:56:42 -06:00
Nathan Stocks
bd8e312d73 port fs.rs to SessionDiagnostics 2022-08-31 10:56:42 -06:00
Nathan Stocks
32e1823b22 port creader.rs to SessionDiagnostics 2022-08-31 10:56:42 -06:00
Nathan Stocks
f7e462a6c7 port encoder.rs to SessionDiagnostics 2022-08-31 10:56:42 -06:00
Nathan Stocks
3ed93107ff port native_libs.rs to SessionDiagnostics 2022-08-31 10:56:42 -06:00
Nathan Stocks
54645e880f set up rustc_metadata for SessionDiagnostics, port dependency_format.rs 2022-08-31 10:56:38 -06:00
Ralf Jung
59d2c1917a
Rollup merge of #100831 - JhonnyBillM:migrate-symbol-mangling-to-diagnostics-structs, r=davidtwco
Migrate `symbol_mangling` module to new diagnostics structs
2022-08-31 14:29:53 +02:00
Ralf Jung
24922b7a82
Rollup merge of #100753 - LuisCardosoOliveira:translation-migrate-session, r=davidtwco
translations(rustc_session): migrates `rustc_session` to use `SessionDiagnostic` - Pt. 1

## Description

This is the first PR for the migration of the module `rustc_session`. You can follow my progress [here](https://github.com/rust-lang/rust/issues/100717#issuecomment-1220279883).

The PR migrates the files `cgu_reuse_tracker` and `parse.rs` to use `SessionDiagnostic `.
2022-08-31 14:29:52 +02:00
Ralf Jung
6c4bda6de4
Rollup merge of #100730 - CleanCut:diagnostics-rustc_monomorphize, r=davidtwco
Migrate rustc_monomorphize to use SessionDiagnostic

### Description

- Migrates diagnostics in `rustc_monomorphize` to use `SessionDiagnostic`
- Adds an `impl IntoDiagnosticArg for PathBuf`

### TODO / Help!
- [x] I'm having trouble figuring out how to apply an optional note. 😕  Help!?
  - Resolved. It was bad docs. Fixed in https://github.com/rust-lang/rustc-dev-guide/pull/1437/files
- [x] `errors:RecursionLimit` should be `#[fatal ...]`, but that doesn't exist so it's `#[error ...]` at the moment.
  - Maybe I can switch after this is merged in? --> https://github.com/rust-lang/rust/pull/100694
  - Or maybe I need to manually implement `SessionDiagnostic` instead of deriving it?
- [x] How does one go about converting an error inside of [a call to struct_span_lint_hir](8064a49508/compiler/rustc_monomorphize/src/collector.rs (L917-L927))?
- [x] ~What placeholder do you use in the fluent template to refer to the value in a vector? It seems like [this code](0b79f758c9/compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs (L83-L114)) ought to have the answer (or something near it)...but I can't figure it out.~ You can't. Punted.
2022-08-31 14:29:51 +02:00
Li Yuanheng
7ce59ebf49 SessionDiagnostic for QueryOverflow error 2022-08-31 19:43:23 +08: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
Yuanheng Li
b8075e4550 migrate rustc_query_system to use SessionDiagnostic
with manual impl SessionDiagnostic
2022-08-31 19:33:51 +08:00
Bryanskiy
0111fb00da add TestReachabilityVisitor 2022-08-31 14:23:07 +03:00
Matthias Krüger
78e5d05ea0
Rollup merge of #101049 - JeanCASPAR:remove-span_fatal-from-ast_lowering, r=davidtwco
Remove span fatal from ast lowering

Now the crate `rustc_ast_lowering` is fully migrated to `SessionDiagnostic`.

r? ``@davidtwco``
2022-08-31 07:57:59 +02:00
Jhonny Bill Mena
8f5fada86d ADD - migrate InvalidDefPath to new diagnostics infra 2022-08-30 14:27:42 -04:00
Jhonny Bill Mena
359002bbeb ADD - migrate InvalidTraitItem and AltInvalidTraitItem errors
Thought of doing this by having a struct and an enum with Default and Alt cases, but not sure if we wanted to have the text in code instead of having “demangling()” and “demangling-alt()” in the ftl file.

Don’t like the current way of having structs representing the same-ish and using long names to distinguish their expectations, instead of putting this in an enum and handling the different cases inside the type.

I am fine with whichever option the team prefers; also understand having them as separate structs keeps it simple.
2022-08-30 14:27:42 -04:00
Jhonny Bill Mena
86f8c4e8e3 ADD - InvalidSymbolName to migrate symbol-name({}) error to new diagnostics infraestructure
ADD - dependencies needed to port a module to new Diagnostics infra (rustc_macros, rustc_errors, errors file, and fluent file)
2022-08-30 14:27:42 -04:00
yukang
77eb1aef52 add UI test for unpretty 2022-08-30 09:31:52 +08:00
Nilstrieb
01acfef1a4 Migrate stable let_chains error to session diagnostics 2022-08-29 19:49:30 +02:00
Nilstrieb
d1ef8180f9 Revert let_chains stabilization
This reverts commit 3266460749.

This is the revert against master, the beta revert was already done in #100538.
2022-08-29 19:34:11 +02:00
Matthias Krüger
a3c965f5fe
Rollup merge of #100843 - IntQuant:issue-100717-infer, r=compiler-errors
Migrate part of rustc_infer to session diagnostic
2022-08-29 06:34:45 +02:00
Jean CASPAR
e89d4fcc7d remove span_fatal from ast_lowering 2022-08-27 09:15:55 +02:00
Michael Goulet
96ceadde76
Rollup merge of #100900 - AndyJado:diag-migrate, r=davidtwco
on `region_errors.rs`

`@rustbot` label +A-translation
2022-08-26 15:56:30 -07:00
Michael Goulet
e7d870b188
Rollup merge of #100890 - adriantombu:migrate_diagnostic_rustc_driver, r=davidtwco
Migrate rustc_driver to SessionDiagnostic

First timer noob here 👋🏽 I'm having a problem understanding how I can retrieve the span, and how to properly construct the error structs to avoid the current compilation errors.

Any help pointing me in the right direction would be much appreciated 🙌🏽
2022-08-26 15:56:29 -07:00
Michael Goulet
d97e616e21
Rollup merge of #100836 - hampuslidin:migrate-attr-crate-diagnostics, r=davidtwco
Migrate `rustc_attr` crate diagnostics

Hi!

This is my first PR to the rustc project, excited to be part of the development! This PR is part of the diagnostics effort, to make diagnostics translatable.

`@rustbot` label +A-translation
2022-08-26 15:56:28 -07:00
Michael Goulet
389dda149c
Rollup merge of #100776 - Rejyr:diagnostic-migration-rustc-lint, r=davidtwco
Migrate `rustc_lint` errors to `SessionDiagnostic`

Draft PR for migrating `rustc_lint` to `SessionDiagnostic`, as part of the [recent blog post](https://blog.rust-lang.org/inside-rust/2022/08/16/diagnostic-effort.html)
2022-08-26 15:56:25 -07:00
Michael Goulet
93b2acd88a
Rollup merge of #100744 - 5225225:migrate-rustc-mir-dataflow, r=davidtwco
Migrate rustc_mir_dataflow to diagnostic structs
2022-08-26 15:56:24 -07:00
Michael Goulet
b54344401a
Rollup merge of #100738 - nidnogg:diagnostics_migr_const_eval, r=davidtwco
Diagnostics migr const eval

This PR should eventually contain all diagnostic migrations for the `rustc_const_eval` crate.

r? `@davidtwco`
`@rustbot` label +A-translation
2022-08-26 15:56:23 -07:00
Michael Goulet
181b0410ec
Rollup merge of #100735 - Facel3ss1:ty-utils-translation, r=davidtwco
Migrate `rustc_ty_utils` to `SessionDiagnostic`

I have migrated the `rustc_ty_utils` crate to use `SessionDiagnostic`, motivated by the [recent blog post about the diagnostic translation effort](https://blog.rust-lang.org/inside-rust/2022/08/16/diagnostic-effort.html).

This is my first PR to the Rust repository, so if I have missed anything, or anything needs to be changed, please let me know! 😄

`@rustbot` label +A-translation
2022-08-26 15:56:22 -07:00
Michael Goulet
bc1d205e4c
Rollup merge of #100724 - JeanCASPAR:migrate-ast_lowering-to-session-diagnostic, r=davidtwco
Migrate ast lowering to session diagnostic

I migrated the whole rustc_ast_lowering crate to session diagnostic *except* the for the use of `span_fatal` at /compiler/rustc_ast_lowering/src/expr.rs#L1268 because `#[fatal(...)]` is not yet supported (see https://github.com/rust-lang/rust/pull/100694).
2022-08-26 15:56:21 -07:00
Luis Cardoso
2c77f3e9c5 translations(rustc_session): migrate check_expected_reuse
This commit migrates the errors in the function check_expected_reuse
to use the new SessionDiagnostic. It also does some small refactor
for the IncorrectCguReuseType to include the 'at least' word in the
fluent translation file
2022-08-26 16:10:11 +02:00
Luis Cardoso
d5262a9452 translations(rustc_session): migrate 80% of the file parse.rs
This commit migrates around 80% of the parse file to use SsessionDiagnostic
We still have to migrate struct_err and struct_warn.
2022-08-26 16:10:11 +02:00
Luis Cardoso
706452eba7 translations(rustc_session): migrate the file cgu_reuse_tracker
This commit migrates the errors that indicates an incorrect
CGU type and the fatal error that indicates that a CGU has
not been correctly recorded
2022-08-26 16:10:11 +02:00
Peter Medus
01c1616b25 Migrate rustc_ty_utils to use SessionDiagnostic 2022-08-26 14:36:51 +01:00
AndyJado
622217da59 diag-mig 2022-08-26 10:32:59 +08:00
Nathan Stocks
30c7506655 allow non-monomorphize modules to access hard-coded error message through new struct, use fluent message in monomorphize 2022-08-25 11:06:45 -06:00
Nathan Stocks
40f44736e8 replace some usages of [Span]FatalError with error-specific types 2022-08-25 11:06:45 -06:00
Nathan Stocks
137f20c112 rebased: convert rustc_monomorphize errors to SessionDiagnostic 2022-08-25 11:06:32 -06:00
Adrian Tombu
bf7ce6a1a6
Replace spaghetti with a simple errors enum 2022-08-25 18:06:12 +02:00
Adrian Tombu
3f883b850d
Start adding enum errors for deserialize_rlink 2022-08-25 18:06:12 +02:00
Adrian Tombu
1c575c5fe0
Use std::io::Error and remove useless to_string 2022-08-25 18:06:12 +02:00
Adrian Tombu
dbe39d835e
Start moving rustc_driver to SessionDiagnostic 2022-08-25 18:06:11 +02:00
Yuki Okushi
0fd4a74139
Rollup merge of #100808 - SkiFire13:migrate_diagnostics_rustc_interface, r=davidtwco
Migrate `rustc_interface` diagnostics

``@rustbot`` label +A-translation

r? rust-lang/diagnostics
cc #100717
2022-08-25 08:50:58 +09:00
Yuki Okushi
2e4760c7e7
Rollup merge of #100780 - wonchulee:translation_save_analysis, r=davidtwco
save_analysis: Migrate diagnostic

* Migrate the `rustc_save_analysis` crate's diagnostic to translatable diagnostic structs.

Depends on https://github.com/rust-lang/rust/pull/100694 and https://github.com/rust-lang/rust/pull/100754 for #[fatal(..)] support, then aa68eb4179, f5219a3960, 7da52f694a can be removed. (I copied commits from https://github.com/rust-lang/rust/pull/100754)
2022-08-25 08:50:57 +09:00
Nikita Tomashevich
3fae3904b1
Use IntoDiagnosticArg where it makes sense 2022-08-24 15:46:29 +03:00
bors
87991d5f5d Auto merge of #100675 - Xiretza:fluent-mandate-crate-prefix, r=davidtwco
fluent: mandate slug names to be prefixed by crate name

This is currently only convention, but not actively checked for.

Additionally, improve error messages to highlight the path of the offending fluent file rather than the identifier preceding it.

This will conflict with #100671, so I'll leave it as draft until that's merged.
2022-08-23 22:30:07 +00:00
Wonchul Lee
9b95eef6ea
save_analysis: Migrate diagnostics 2022-08-24 06:50:16 +09:00
Dylan DPC
35f2d125ca
Rollup merge of #100768 - Facel3ss1:plugin-impl-translation, r=davidtwco
Migrate `rustc_plugin_impl` to `SessionDiagnostic`

Migration of the `rustc_plugin_impl` crate.
~Draft PR because it is blocked on #100694 for `#[fatal(...)]` support~ (this has been merged, and I've changed over to `#[diag(...)]` now too), but I would also like to know if what I did with `LoadPluginError` is okay, because all it does is display the error message from `libloading` ([See conversation on zulip](https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/.23100717.20diagnostic.20translation/near/294327843)). This crate is apparently for a deprecated feature which is used by servo, so I don't know how much this matters anyway.
2022-08-23 20:40:04 +05:30
5225225
f20cc9ae4e Rename rustc_mir_dataflow diagnostic to mir_dataflow 2022-08-23 13:48:15 +01:00
Nikita Tomashevich
74f9973824
Fix formating in infer.ftl to make tidy happy 2022-08-23 15:33:06 +03:00
5225225
7f125ed7d5 Remove full stop in diagnostic message 2022-08-23 13:18:45 +01:00
Nikita Tomashevich
f50d1713fd
Migrate note_region_origin function 2022-08-23 14:47:08 +03:00
Nikita Tomashevich
313d474b35
Migrate OpaqueHiddenType, E0282, E0283, E0284, E0698 2022-08-23 14:47:07 +03:00
5225225
ee2b16100e Migrate rustc_mir_dataflow to diagnostic structs 2022-08-23 11:24:51 +01:00
Hampus Lidin
1c28006bf6 Reorder diagnostics in code order, then alphabetical order 2022-08-22 20:19:19 +02:00
Hampus Lidin
c4f59605d2 Refactor remaining diagnostics 2022-08-22 20:19:19 +02:00
Hampus Lidin
b731bfa2d4 Refactor 'invalid issue' diagnostic to use labels within the same Fluent object 2022-08-22 20:19:19 +02:00
Hampus Lidin
b3be7698d6 Refactor additional diagnostics in rustc_attr 2022-08-22 20:19:19 +02:00
Hampus Lidin
83a724eab5 Refactor more diagnostics in rustc_attr 2022-08-22 20:19:19 +02:00
Hampus Lidin
0005f628f0 Refactor diagnostics in handle_errors function 2022-08-22 20:19:15 +02:00
Jean CASPAR
9472df10d0 Changes made in response to feedback 2022-08-22 19:24:14 +02:00
Jean CASPAR
e701c72a63 Migrate all span_err(...) in ast_lowering to SessionDiagnostic 2022-08-22 19:21:41 +02:00
Jean CASPAR
5164966591 Migrate ast_lowering::pat to SessionDiagnostic 2022-08-22 19:21:41 +02:00
Jean CASPAR
d75fd91d50 Migrate ast_lowering::ast to SessionDiagnostic 2022-08-22 19:21:39 +02:00
Jean CASPAR
1382d307d3 Migrate ast_lowering::expr to SessionDiagnostic 2022-08-22 19:21:39 +02:00
Jean CASPAR
0043d10c71 Migrate ast_lowering::lib and ast_lowering::item to SessionDiagnostic 2022-08-22 19:19:59 +02:00
Jean CASPAR
73ae38bac1 Migrate ast_lowering::path to SessionDiagnostic 2022-08-22 19:19:58 +02:00
nidnogg
5101688d4f Addressed trailing newlines, odd whitespace skipped by x.py fmt 2022-08-22 12:38:16 -03:00
Peter Medus
8c2413c4c6 Migrate rustc_plugin_impl to SessionDiagnostic 2022-08-22 16:35:05 +01:00
nidnogg
649749c7b0 Addressing last comment on PR review 2022-08-22 12:14:49 -03:00
Dylan DPC
75b7089d1e
Rollup merge of #100713 - Xiretza:parser-expr-session-diagnostics, r=estebank
Convert diagnostics in parser/expr to SessionDiagnostic

This migrates all the easy cases in `rustc_parse::parser::expr` to `SessionDiagnostic`s, I've left things such as `multipart_suggestion`s out for now in the hopes of a derive API being developed soon.
2022-08-22 20:34:14 +05:30
Giacomo Stevanato
217a11bdb1 Prefix fluent resources with interface_ 2022-08-22 14:59:41 +02:00
Rejyr
1974186d32 migrate: rustc_lint::context 2022-08-22 08:24:14 -04:00
Rejyr
dbe838079c rename: UnknownTool to UnknownToolInScopedLint 2022-08-22 08:24:14 -04:00
Rejyr
7a6ae2367d migrate: OverruledAttribute 2022-08-22 08:24:14 -04:00
Rejyr
874a79fae3 migrate: bad_attr to SessionDiagnostic 2022-08-22 08:24:14 -04:00
Rejyr
d197c1eb5b migrate: UnknownTool error to SessionDiagnostic 2022-08-22 08:24:14 -04:00
Giacomo Stevanato
b411adec2a Move rustc_interface diagnostics to struct SessionDiagnostic derives 2022-08-22 13:22:00 +02:00
Xiretza
c9b1a5874d fluent: mandate slug names to be prefixed by crate name 2022-08-22 08:42:44 +02:00
Dylan DPC
57e521e0e5
Rollup merge of #100694 - finalchild:ast-passes-diag, r=TaKO8Ki
Migrate rustc_ast_passes diagnostics to `SessionDiagnostic` and translatable messages (first part)

Doing a full migration of the `rustc_ast_passes` crate.
Making a draft here since there's not yet a tracking issue for the migrations going on.

`@rustbot` label +A-translation
2022-08-22 11:45:44 +05:30
bors
d0ea1d7679 Auto merge of #100671 - Xiretza:tidy-fluent-files, r=davidtwco
tidy: check fluent files for style

Inspired by https://github.com/rust-lang/rust/pull/100651#discussion_r947600576

There were a lot of line length violations, so I've excepted that lint - I'm not sure if fluent files can be formatted to avoid long lines at all.
2022-08-22 03:02:50 +00:00
nidnogg
0a58b26e8a Hotfix ftl err name, added check for err.code in create_feature_err 2022-08-21 23:22:55 -03:00
nidnogg
4c82845b3a Fixed failing tests (missing labels), added automatic error code in create_feature_err() builder 2022-08-21 23:22:55 -03:00
nidnogg
d1f14ee1b0 Added several more migrations under ops.rs, failing some tests though 2022-08-21 23:22:54 -03:00
nidnogg
33e8aaf830 Migration on ops.rs for unstable const functions 2022-08-21 23:22:53 -03:00
nidnogg
70ea98633e Migrated Unallowed function pointer calls in interpreter/ops 2022-08-21 23:22:51 -03:00
nidnogg
6af8e46a9a Finished const_eval module migration, moving onto sibling folders 2022-08-21 23:22:50 -03:00
finalchild
e331ae57df Migrate forbidden_default and *_without_body 2022-08-22 01:11:59 +09:00
finalchild
bfefefbcfa Migrate fn_param_forbidden_self and rename others to have prefix fn_param_ 2022-08-22 00:57:22 +09:00
finalchild
07e0bc9600 Rename c_var_args_without_named_arg to c_var_args_is_sole_param 2022-08-22 00:57:22 +09:00
finalchild
c6903c04b1 Migrate doc_comment_on_fn_param, forbidden_attr_on_fn_param 2022-08-22 00:57:21 +09:00
finalchild
269c85390c Migrate forbidden_lifetime_bound, forbidden_non_lifetime_param, too_many_params, c_var_args_without_named_arg, c_var_args_not_last 2022-08-22 00:57:21 +09:00
finalchild
8d042f4483 Migrate trait_fn_const 2022-08-22 00:57:21 +09:00
finalchild
e3d4c4039a Migrate trait_fn_async 2022-08-22 00:57:21 +09:00
finalchild
e144a2367a Migrate deprecated_where_clause_location, forbidden_assoc_constraint, keyword_lifetime, invalid_label, invalid_visibility 2022-08-22 00:57:21 +09:00
finalchild
d6fdf14eb7 Migrate forbidden_let 2022-08-22 00:57:21 +09:00
Xiretza
ffcaa0dee2 Migrate diagnostics in parser/expr to SessionDiagnostic 2022-08-21 14:54:05 +02:00
Matthias Krüger
84f81e7974
Rollup merge of #100723 - 5225225:the-easy-ones, r=compiler-errors
Add the diagnostic translation lints to crates that don't emit them

Some of these have a note saying that they should build on a stable compiler, does that mean they shouldn't get these lints? Or can we cfg them out on those?
2022-08-20 07:09:03 +02:00
Matthias Krüger
67f77f5a55
Rollup merge of #100709 - JhonnyBillM:port-expected-used-symbol-diagnostic, r=compiler-errors
Migrate typeck's `used` expected symbol diagnostic to `SessionDiagnostic`

r? ``@davidtwco``
2022-08-20 07:09:02 +02:00
Matthias Krüger
eacbe5437e
Rollup merge of #100667 - Xiretza:diag-structs-parser-ivd, r=davidtwco
Migrate "invalid variable declaration" errors to SessionDiagnostic

After seeing the great blog post on Inside Rust, I decided to try my hand at this. Just one diagnostic for now to get used to the workflow and to check if this is the way to do it or if there are any problems.
2022-08-20 07:09:01 +02:00
Dylan DPC
078844283c
Rollup merge of #99576 - compiler-errors:foreign-fundamental-drop-is-bad, r=TaKO8Ki
Do not allow `Drop` impl on foreign fundamental types

`Drop` should not be implemented on `Pin<T>` even if `T` is local.

This does not trigger regular orphan rules is because `Pin` is `#[fundamental]`... but we don't allow specialized `Drop` impls anyways, so these rules are not sufficient to prevent this impl on stable. Let's just choose even stricter rules, since we shouldn't be implementing `Drop` on a foreign ADT ever.

Fixes #99575
2022-08-19 12:26:38 +05:30
5225225
09ea9f0a87 Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
Jhonny Bill Mena
af4f66ef93 ADD - ExpectedUsedSymbol diagnostic to port used() diagnostic 2022-08-18 08:18:26 -04:00
Xiretza
295457192d fluent: fix slug name for borrowck::generic_does_not_live_long_enough 2022-08-18 12:34:11 +02:00
Xiretza
00fec76ab5 tidy: check fluent files for style 2022-08-18 12:34:11 +02:00
Matthias Krüger
3de034d401
Rollup merge of #100674 - PragmaTwice:mig-typeck-unused-crate-diag, r=davidtwco
Migrate lint reports in typeck::check_unused to LintDiagnostic

In this PR, I migrate two lint reports in `typeck::check_unused` by `LintDiagnostic`, all of which is about extern crates.

```@rustbot``` label +A-translation
r? rust-lang/diagnostics
2022-08-18 05:10:50 +02:00
Matthias Krüger
8b180ed3c0
Rollup merge of #100651 - nidnogg:diagnostics_migration_expand_transcribe, r=davidtwco
Migrations for rustc_expand transcribe.rs

This PR includes some migrations to the new diagnostics API for the `rustc_expand` module.
r? ```@davidtwco```
2022-08-18 05:10:47 +02:00
Xiretza
e8499cfadc Migrate "invalid variable declaration" errors to SessionDiagnostic 2022-08-17 19:08:37 +02:00
nidnogg
c6f9a9c410 Moved structs to rustc_expand::errors, added several more migrations, fixed slug name 2022-08-17 11:18:19 -03:00
PragmaTwice
98fb65eff9 Migrate lint reports in typeck::check_unused to LintDiagnostic 2022-08-17 17:47:44 +08:00
nidnogg
be18a9bf75 Migrated more diagnostics under transcribe.rs 2022-08-16 19:02:51 -03:00
nidnogg
7e15fbab75 Added first migration for repeated expressions without syntax vars 2022-08-16 18:34:13 -03:00
finalchild
c1a98416e3 Migrate emoji identifier diagnostics to SessionDiagnostic 2022-08-17 05:07:47 +09:00
Michael Goulet
fd934c99bc Do not allow Drop impl on foreign fundamental types 2022-08-16 00:59:06 +00:00
Matthias Krüger
3aa5734a2c
Rollup merge of #100377 - est31:fluent_grepability, r=davidtwco
Replace - with _ in fluent slugs to improve developer workflows

This is a proposal to smoothen the compiler contribution experience in the face of the move to fluent.

## Context

The fluent project has introduced a layer of abstraction to compiler errors. Previously, people would write down error messages directly in the same file the code was located to emit them. Now, there is a slug that connects the code in the compiler to the error message in the ftl file.

You can look at 7ef610c003 to see an example of the changes:

Old:
```Rust
let msg = format!(
    "bounds on `{}` are most likely incorrect, consider instead \
        using `{}` to detect whether a type can be trivially dropped",
    predicate,
    cx.tcx.def_path_str(needs_drop)
);
lint.build(&msg).emit();
```
New (Rust side):
```Rust
lint.build(fluent::lint::drop_trait_constraints)
    .set_arg("predicate", predicate)
    .set_arg("needs_drop", cx.tcx.def_path_str(needs_drop))
    .emit();
```
New (Fluent side):
```fluent
lint-drop-trait-constraints =
    bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped
```

You will note that in the ftl file, the slug is slightly different from the slug in the Rust file: The ftl slug uses `-` (e.g. `lint-drop-trait-constraints`) while the rust slug uses `::` and `_` (e.g. `lint::drop_trait_constraints`). This choice was probably done due to:

* Rust not accepting `-` in identifiers (as it is an operator)
* fluent not supporting the `:` character in slug names (parse error upon attempts)
* all official fluent documentation using `-` instead of `_`

## The problem

The two different types of slugs, one with `-`, and one with `_`, cause difficulties for contributors. Imagine you don't have perfect knowledge of where stuff is in the compiler (i would say this is most people), and you encounter an error for which you think there is something you could improve that is not just a rewording.

So you want to find out where in the compiler's code that error is being emitted. The best way is via grepping.

1. you grep for the message in the compiler's source code. You discover the ftl file and find out the slug for that error.
2. That slug however contains `-` instead of `_`, so you have to manually translate the `-`'s into `_`s, and furthermore either remove the leading module name, or replace the first `-` with a `::`.
3. you do a second grep to get to the emitting location in the compiler's code.

This translation difficulty in step 2 appears also in the other direction when you want to figure out what some code in the compiler is doing and use error messages to help your understanding. Comments and variable names are way less exposed to users so [are more likely going to lie](cc3c5d2700) than error messages.

I think that at least the `-`→`_` translation which makes up most of step 2 can be removed at low cost.

## The solution

If you look closely, the practice of fluent to use `-` is only a stylistic choice and it is not enforced by fluent implementations, neither the playground nor the one the rust compiler uses, that slugs may not contain `_`. Thus, we can in fact migrate the ftl side to `_`. So now we'll have slugs like  `lint_drop_trait_constraints` on the ftl side. You only have to do one replacement now to get to the Rust slug: remove the first `_` and place a `::` in its stead. I would argue that this change is in fact useful as it allows you to control whether you want to look at the rust side of things or the ftl side of things via changing the query string only: with an increased number of translations checked into the repository, grepping for raw slugs will return the slug in many ftl files, so an explicit step to look for the source code is always useful. In the other direction (rust to fluent), you don't need a translation at all any more, as you can just take the final piece of the slug (e.g. `drop_trait_constraints`) and grep for that. The PR also adds enforcement to forbid usage of `_` in slug names. Internal slug names (those leading with a `-`) are exempt from that enforcement.

As another workflow that benefits from this change, people who add new errors don't have to do that `-` conversion either.

| Before/After | Fluent slug | Rust slug (no change) |
|--|--|--|
| Before | `lint-drop-trait-constraints` | `lint::drop_trait_constraints`|
| After | `lint_drop_trait_constraints` | `lint::drop_trait_constraints`|

Note that I've suggested this previously in the translation thread on zulip. I think it's important to think about non-translator contribution impact of fluent. I have certainly plans for more improvements, but this is a good first step.

``@rustbot`` label A-diagnostics
2022-08-15 20:11:34 +02:00
Mark Rousskov
154a09dd91 Adjust cfgs 2022-08-12 16:28:15 -04:00
est31
cc6cff564f Replace - with _ in ftl slugs for better grepability
Having to replace - with _ (and vice versa) makes the slugs less greppable
and thus constitutes a contributor roadblock.

Result of running this repeatedly up until reaching a fixpoint:

find compiler/rustc_error_messages/locales/en-US/ -type f -exec sed -i 's/\(.+\)-\(.*\)=/\1_\2=/' {} \;

Plus some fixes to update usages of slugs leading with -.
2022-08-12 22:22:55 +02:00
yukang
e614bbcd30 link_ordinal is available for foreign static 2022-08-04 09:28:59 +08:00
yukang
0d1b832667 check link ordinal make sure target is foreign function 2022-08-03 11:30:27 +08:00
David Wood
7bab769b58 lint: add bad opt access internal lint
Some command-line options accessible through `sess.opts` are best
accessed through wrapper functions on `Session`, `TyCtxt` or otherwise,
rather than through field access on the option struct in the `Session`.

Adds a new lint which triggers on those options that should be accessed
through a wrapper function so that this is prohibited. Options are
annotated with a new attribute `rustc_lint_opt_deny_field_access` which
can specify the error message (i.e. "use this other function instead")
to be emitted.

A simpler alternative would be to simply rename the options in the
option type so that it is clear they should not be used, however this
doesn't prevent uses, just discourages them. Another alternative would
be to make the option fields private, and adding accessor functions on
the option types, however the wrapper functions sometimes rely on
additional state from `Session` or `TyCtxt` which wouldn't be available
in an function on the option type, so the accessor would simply make the
field available and its use would be discouraged too.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-27 11:24:27 +01:00
David Wood
76cf6bd03e passes: port more of check_attr module
Signed-off-by: David Wood <david.wood@huawei.com>
2022-07-25 15:11:22 +01:00
Matthias Krüger
611bbcb044 clippy::perf fixes 2022-07-20 11:48:11 +02:00
bors
9a7b7d5e50 Auto merge of #98180 - notriddle:notriddle/rustdoc-fn, r=petrochenkov,GuillaumeGomez
Improve the function pointer docs

This is #97842 but for function pointers instead of tuples. The concept is basically the same.

* Reduce duplicate impls; show `fn (T₁, T₂, …, Tₙ)` and include a sentence saying that there exists up to twelve of them.
* Show `Copy` and `Clone`.
* Show auto traits like `Send` and `Sync`, and blanket impls like `Any`.

https://notriddle.com/notriddle-rustdoc-test/std/primitive.fn.html
2022-07-19 19:36:57 +00:00
Tomasz Miąsko
45afc214af Update invalid atomic ordering lint
The restriction that success ordering must be at least as strong as its
failure ordering in compare-exchange operations was lifted in #98383.
2022-07-18 12:02:11 +02:00
Michael Howell
1169832f2f rustdoc: extend #[doc(tuple_variadic)] to fn pointers
The attribute is also renamed `fake_variadic`.
2022-07-17 16:32:06 -07:00
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
Isak Nyberg
657ae03f60
Update compiler/rustc_error_messages/src/lib.rs
Co-authored-by: Janusz Marcinkiewicz <virrages@gmail.com>
2022-04-16 23:52:18 +02:00
Isak Nyberg
53b2aca9da Refactor loop into iterator; simplify negation logic. 2022-04-14 00:22:08 +02:00
David Wood
9bfe0e39e4 errors: lazily load fallback fluent bundle
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-13 02:44:59 +01:00
David Wood
fc3cca24f1 sess: try sysroot candidates for fluent bundle
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-12 10:15:37 +01:00
Maybe Waffle
d5440926e2 Suggest replacing typeof(...) with an actual type
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-07 23:40:32 +04:00
David Wood
ccd4820326 errors: support fluent + parallel compiler
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-05 07:01:03 +01:00
David Wood
66f22e550b errors: use impl Into<FluentId>
`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-05 07:01:03 +01:00
David Wood
3c2f864ffb session: opt for enabling directionality markers
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-05 07:01:03 +01:00
David Wood
e27389b068 errors: add links to fluent documentation
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-05 07:01:03 +01:00
David Wood
141f8404a8 errors: don't try load default locale from sysroot
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-05 07:01:03 +01:00
David Wood
d0fd8d7880 macros: translatable struct attrs and warnings
Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05 07:01:03 +01:00
David Wood
a52b5072ac errors: disable directionality isolation markers
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-05 07:01:02 +01:00
David Wood
d5119c5b9f errors: implement sysroot/testing bundle loading
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-05 07:01:02 +01:00
David Wood
7f91697b50 errors: implement fallback diagnostic translation
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-05 07:01:02 +01:00
David Wood
c45f29595d span: move MultiSpan
`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-05 07:01:00 +01:00