Commit Graph

137 Commits

Author SHA1 Message Date
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
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