Commit Graph

358 Commits

Author SHA1 Message Date
David Tolnay
65f0253334
Support environment variable for interned Symbol value 2023-10-26 01:57:11 -07:00
David Tolnay
726a43c1de
Move symbols macro map into a struct 2023-10-26 01:57:10 -07:00
David Tolnay
8dea49ad7b
Delete counter from symbols proc macro in favor of hashmap as source of truth 2023-10-26 01:57:09 -07:00
David Tolnay
95742ff23c
Add a Parse impl for symbol Value 2023-10-26 01:57:08 -07:00
David Tolnay
ba17934bc1
Represent symbol value as enum to prepare for supporting env vars 2023-10-26 01:57:07 -07:00
David Tolnay
173dcb211a
Touch up syn parsing in symbols macro 2023-10-26 01:57:06 -07:00
Oli Scherer
fe8ebb1890 Allow ensure queries to return Result<(), ErrorGuaranteed> 2023-10-23 08:20:29 +00:00
Michael Goulet
60c95448c3 Use v0.0.0 in compiler crates 2023-10-18 21:55:15 +00:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Nicholas Nethercote
3449304722 Make enum decoding errors more informative.
By printing the actual value, as long as the expected range. I found
this helpful when I encountered one of these errors.
2023-08-18 16:50:41 +10:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Matthias Krüger
23815467a2 inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
Oli Scherer
cf325e8187 Bump syn now that it doesn't affect diagnostics anymore 2023-07-26 08:26:50 +00:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Nilstrieb
171be8ce94 Downgrade tracing and syn
There's currently a deadlock with tracing when RUSTC_LOG is enabled.
Downgrade tracing-core for now to avoid blocking the other updates.

syns upgrades cause some nontrivial changes in the diagnostics derive tests,
which are best dealt with in another PR.
2023-07-02 21:02:31 +02:00
bors
08fd6f719e Auto merge of #111269 - clubby789:validate-fluent-variables, r=davidtwco
Validate fluent variable references in tests

Closes #101109

Under `cfg(test)`, the `fluent_messages` macro will emit a list of variables referenced by each message and its attributes. The derive attribute will now emit a `#[test]` that checks that each referenced variable exists in the structure it's applied to.
2023-06-28 03:47:02 +00:00
Takayuki Maeda
c8960622a2 avoid &format in error message code 2023-06-23 02:17:39 +09:00
Deadbeef
4f83717cf7 Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
clubby789
220bb61b33 Fix diagnostics with errors 2023-05-26 10:44:18 +00:00
clubby789
9b5574f028 Validate fluent variable references with debug_assertions 2023-05-26 10:41:36 +00:00
John Kåre Alsaker
f6c6d10443 Merge query property modules into one 2023-05-18 09:45:12 +02:00
John Kåre Alsaker
fff20a703d Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
Dylan DPC
8c51701b8a
Rollup merge of #111120 - chenyukang:yukang-suggest-let, r=Nilstrieb
Suggest let for possible binding with ty

Origin from https://github.com/rust-lang/rust/pull/109128#discussion_r1179866137

r? `@Nilstrieb`
2023-05-09 12:33:46 +05:30
Michael Goulet
a156bd7714 Make spans a bit better 2023-05-08 03:34:46 +00:00
Michael Goulet
2b9279f313 Diagnostic args are still args if they're documented 2023-05-08 03:19:54 +00:00
yukang
0bb43c63c3 Suggest let for possible binding with ty 2023-05-08 10:56:20 +08:00
Maybe Waffle
e496fbec92 Split {Idx, IndexVec, IndexSlice} into their own modules 2023-04-24 13:53:35 +00:00
Nilstrieb
b5d3d970fa Add rustc_fluent_macro to decouple fluent from rustc_macros
Fluent, with all the icu4x it brings in, takes quite some time to
compile. `fluent_messages!` is only needed in further downstream rustc
crates, but is blocking more upstream crates like `rustc_index`. By
splitting it out, we allow `rustc_macros` to be compiled earlier, which
speeds up `x check compiler` by about 5 seconds (and even more after the
needless dependency on `serde_json` is removed from
`rustc_data_structures`).
2023-04-18 18:56:22 +00:00
fee1-dead
a5136f14ae
Rollup merge of #109665 - fee1-dead-contrib:rm-remap-queries, r=oli-obk
Remove `remap_env_constness` in queries

This removes some of the complexities with const traits. #88119 used to be caused by this but was fixed by `param_env = param_env.without_const()`.
2023-04-16 18:55:38 +08:00
bors
45749b21b7 Auto merge of #110092 - clubby789:builtin-macros-translatable, r=compiler-errors
Migrate most of `rustc_builtin_macros` to diagnostic impls

cc #100717

This is a couple of days work, but I decided to stop for now before the PR becomes too big. There's around 50 unresolved failures when `rustc::untranslatable_diagnostic` is denied, which I'll finish addressing once this PR goes thtough

A couple of outputs have changed, but in all instances I think the changes are an improvement/are more consistent with other diagnostics (although I'm happy to revert any which seem worse)
2023-04-11 14:40:54 +00:00
clubby789
64f7597776 Migrate most of rustc_builtin_macros to diagnostic impls
Co-authored-by: Joe ST <joe@fbstj.net>
Co-authored-by: Michael Goulet <michael@errs.io>
2023-04-10 21:16:53 +01:00
Nilstrieb
73417b1e15
Inline format_args
Co-authored-by: Michael Goulet <michael@errs.io>
2023-04-09 23:29:39 +02:00
Nilstrieb
81c320ea77 Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
Nilstrieb
f058d05fc2 Some simple clippy::perf fixes 2023-04-09 21:59:28 +02:00
Deadbeef
954d9a8f8e Remove remap_env_constness in queries 2023-04-08 09:13:18 +00:00
Deadbeef
d764c2da99 address comments 2023-04-06 04:55:58 +00:00
Deadbeef
25fdea009e fix errors 2023-04-06 04:55:58 +00:00
Deadbeef
fc01b4b63c fix and bless ui tests 1/2 2023-04-06 04:55:58 +00:00
Deadbeef
af74ef8993 migrate rustc_macros to syn 2.0 2023-04-06 04:55:58 +00:00
est31
97fb15d950 Don't emit the OS error in a note
This makes it possible to make the normalization of the error message
more precise, allowing us to not normalize all notes away.
2023-03-31 03:49:21 +02:00
est31
f24983222d Use std::fs::read_to_file in fluent_messages macro 2023-03-31 03:18:30 +02:00
clubby789
979c265a5d Check for escape sequences in Fluent resources 2023-03-29 18:34:29 +01:00
clubby789
ef434f04e9 Allow using bool for optional diagnostics 2023-02-27 12:54:11 +00:00
John Kåre Alsaker
7de205ea3a Emit the enum discriminant separately for the Encodable macro 2023-02-25 01:04:56 +01:00
bors
fdbc4329cb Auto merge of #108340 - eggyal:remove_traversal_trait_aliases, r=oli-obk
Remove type-traversal trait aliases

#107924 moved the type traversal (folding and visiting) traits into the type library, but created trait aliases in `rustc_middle` to minimise both the API churn for trait consumers and the arising boilerplate.  As mentioned in that PR, an alternative approach of defining subtraits with blanket implementations of the respective supertraits was also considered at that time but was ruled out as not adding much value.

Unfortunately, it has since emerged that rust-analyzer has difficulty with these trait aliases at present, resulting in a degraded contributor experience (see the recent [r-a has become useless](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/r-a.20has.20become.20useless) topic on the #t-compiler/help Zulip stream).

This PR removes the trait aliases, and accordingly the underlying type library traits are now used directly; they are parameterised by `TyCtxt<'tcx>` rather than just the `'tcx` lifetime, and imports have been updated to reflect the fact that the trait aliases' explicitly named traits are no longer automatically brought into scope.  These changes also roll-back the (no-longer required) workarounds to #107747 that were made in b409329c62.

Since this PR is just a find+replace together with the changes necessary for compilation & tidy to pass, it's currently just one mega-commit.  Let me know if you'd like it broken up.

r? `@oli-obk`
2023-02-22 18:26:51 +00:00
Alan Egerton
695072daa6
Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
David Wood
d1fcf61117 errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:53 +00:00
Alan Egerton
3b510e88ef
Use derive attributes for uninteresting traversals 2023-02-14 15:09:40 +00:00
Alan Egerton
9783fcc13b
Make folding traits generic over the Interner 2023-02-13 10:24:49 +00:00
Alan Egerton
dea342d861
Make visiting traits generic over the Interner 2023-02-13 10:24:49 +00:00
Alan Egerton
ba55a453eb
Alias folding/visiting traits instead of re-export 2023-02-13 10:24:46 +00:00
Xiretza
f2acbb9d1e Forbid #[suggestion_*(...)] on Vecs
It is ambiguous whether this should produce several `.span_suggestions()`
calls or one `.multipart_suggestions()` call.
2023-02-01 21:49:45 +01:00
clubby789
ed707a106c Detect references to non-existant messages in Fluent resources 2023-01-27 11:27:22 +00:00
Scott McMurray
925dc37313 Stop using BREAK & CONTINUE in compiler
Switching them to `Break(())` and `Continue(())` instead.

libs-api would like to remove these constants, so stop using them in compiler to make the removal PR later smaller.
2023-01-17 23:17:51 -08:00
mejrs
7aff210ead
Support eager subdiagnostics again 2023-01-11 14:20:34 -08:00
nils
fd7a159710 Fix uninlined_format_args for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
Michael Goulet
7690fe3bc6 Simplify some iterator combinators 2023-01-04 00:48:07 +00:00
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
bors
eb9e5e711d Auto merge of #105880 - Nilstrieb:make-newtypes-less-not-rust, r=oli-obk
Improve syntax of `newtype_index`

This makes it more like proper Rust and also makes the implementation a lot simpler.

Mostly just turns weird flags in the body into proper attributes.

It should probably also be converted to an attribute macro instead of function-like, but that can be done in a future PR.
2022-12-20 07:27:01 +00:00
Nilstrieb
8bfd6450c7 A few small cleanups for newtype_index
Remove the `..` from the body, only a few invocations used it and it's
inconsistent with rust syntax.

Use `;` instead of `,` between consts. As the Rust syntax gods inteded.
2022-12-18 21:47:28 +01:00
Nilstrieb
d679764fb6 Make #[debug_format] an attribute in newtype_index
This removes the `custom` format functionality as its only user was
trivially migrated to using a normal format.

If a new use case for a custom formatting impl pops up, you can add it
back.
2022-12-18 21:37:38 +01:00
Nilstrieb
91c3c2040c Make #[max] an attribute in newtype_index 2022-12-18 21:22:14 +01:00
Nilstrieb
93429948cf Make #[no_ord_impl] an attribute in newtype_index 2022-12-18 21:06:44 +01:00
Nilstrieb
88d5f7f4ce Make #[custom_encodable] an attribute for newtype_index
Makes the syntax a little more rusty.
2022-12-18 21:02:14 +01:00
Nilstrieb
b4d739ef12 Use #[derive] instead of custom syntax in all newtype_index 2022-12-18 20:53:08 +01:00
Matthias Krüger
3af7df91fc use &str / String literals instead of format!() 2022-12-18 16:17:46 +01:00
Matthias Krüger
de59844c98 more clippy::complexity fixes 2022-12-15 00:09:10 +01:00
bors
fbf8b937b4 Auto merge of #105233 - mejrs:always_eager, r=estebank
Always evaluate vecs of subdiagnostics eagerly

See https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/310186705 for context
2022-12-14 16:16:50 +00:00
bors
ed61c139c2 Auto merge of #105220 - oli-obk:feeding, r=cjgillot
feed resolver_for_lowering instead of storing it in a field

r? `@cjgillot`

opening this as

* a discussion for `no_hash` + `feedable` queries. I think we'll want those, but I don't quite understand why they are rejected beyond a double check of the stable hashes for situations where the query is fed but also read from incremental caches.
* and a discussion on removing all untracked fields from TyCtxt and setting it up so that they are fed queries instead
2022-12-06 03:47:41 +00:00
Oli Scherer
f693b7848e feed resolver_for_lowering instead of storing it in a field 2022-12-05 10:58:55 +00:00
mejrs
a7838d8bd7 Always evaluate vecs of subdiagnostics eagerly 2022-12-04 01:13:21 +01:00
Maybe Waffle
f2b97a8bfe Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
Camille GILLOT
9f2c6b0b09 Sanity check computed value for feeable queries. 2022-11-29 18:42:23 +00:00
Camille GILLOT
5471381349 Allow to set a query's result as a side effect. 2022-11-29 18:40:59 +00:00
bors
8841bee954 Auto merge of #103556 - clubby789:specialize-option-partial-eq, r=scottmcm
Manually implement PartialEq for Option<T> and specialize non-nullable types

This PR manually implements `PartialEq` and `StructuralPartialEq` for `Option`, which seems to produce slightly better codegen than the automatically derived implementation.

It also allows specializing on the `core::num::NonZero*` and `core::ptr::NonNull` types, taking advantage of the niche optimization by transmuting the `Option<T>` to `T` to be compared directly, which can be done in just two instructions.

A comparison of the original, new and specialized code generation is available [here](https://godbolt.org/z/dE4jxdYsa).
2022-11-26 08:56:20 +00:00
mejrs
e8e47e0873 Improve slug name error 2022-11-21 15:24:51 +01:00
mejrs
d494502f64 Fix tests 2022-11-21 15:24:51 +01:00
mejrs
fe212eca76 Match crate and slug names 2022-11-21 15:24:50 +01:00
Matthias Krüger
e3036df003 couple of clippy::perf fixes 2022-11-18 10:30:47 +01:00
wanghaha-dev
009f80b987 Modify comment syntax error 2022-11-07 14:33:33 +08:00
Manish Goregaokar
69e705564d
Rollup merge of #103575 - Xiretza:suggestions-style-attr, r=davidtwco
Change #[suggestion_*] attributes to use style="..."

As discussed [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20tool_only_span_suggestion), this changes `#[(multipart_)suggestion_{short,verbose,hidden}(...)]` attributes to plain `#[(multipart_)suggestion(...)]` attributes with a `style = "{short,verbose,hidden}"` parameter.

It also adds a new style, `tool-only`, that corresponds to `tool_only_span_suggestion`/`tool_only_multipart_suggestion` and causes the suggestion to not be shown in human-readable output at all.

Best reviewed commit-by-commit, there's a bit of noise in there.

cc #100717 `@compiler-errors`
r? `@davidtwco`
2022-11-01 20:00:38 -04:00
bors
11ebe6512b Auto merge of #103217 - mejrs:track, r=eholk
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
2022-11-01 21:09:45 +00:00
clubby789
b9a95d8990 Use allow_internal_unstable and add unstable reason 2022-11-01 00:11:35 +00:00
clubby789
20f2d8b841 Specialize PartialEq for Option<newtype> 2022-10-31 16:43:57 +00:00
mejrs
cbeb244b05 Add more track_caller 2022-10-31 16:14:29 +01:00
Xiretza
2eeb7802b3 Remove #[suggestion_*] attributes 2022-10-26 15:04:09 +02:00
Xiretza
cd621be782 Convert all #[suggestion_*] attributes to #[suggestion(style = "...")]
Using the following command:

find compiler/ -type f -name '*.rs' -exec perl -i -gpe \
    's/(#\[\w*suggestion)_(short|verbose|hidden)\(\s*(\S+,)?/\1(\3style = "\2",/g' \
    '{}' +
2022-10-26 15:04:09 +02:00
Xiretza
20f2958b8a Add "tool-only" suggestion style 2022-10-26 15:04:09 +02:00
Xiretza
368c4a35b9 Add style= parameter to suggestion attributes 2022-10-26 15:04:09 +02:00
Xiretza
8bc43f99e9 Allow specifying multiple alternative suggestions
This allows porting uses of span_suggestions() to diagnostic structs.

Doesn't work for multipart_suggestions() because the rank would be
reversed - the struct would specify multiple spans, each of which has
multiple possible replacements, while multipart_suggestions() creates
multiple possible replacements, each with multiple spans.
2022-10-23 18:59:13 +02:00
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
Nilstrieb
2459569776
Generate fluent message constant in a flat module for all crates
This will make it easier to grep for fluent message names.
2022-10-23 10:09:44 +02:00
David Wood
913f597402 infer: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
David Wood
feeeb11d89 macros: fully specify path to Fn
Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
David Wood
1045e69e73 macros: allow subdiagnostic-kind-less variants
Sometimes it is convenient to return a subdiagnostic enum where one or
more of the variants don't add anything to the diagnostic.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
David Wood
7fbaf27696 macros: support doc comments in diag derives
Documentation comments shouldn't affect the diagnostic derive in any
way, but explicit support has to be added for ignoring the `doc`
attribute.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-17 09:54:24 +01:00
Nilstrieb
167b3bd3b2
Get rid of rustc_query_description!
Queries can provide an arbitrary expression for their description and
their caching behavior. Before, these expressions where stored in a
`rustc_query_description` macro emitted by the `rustc_queries` macro,
and then used in `rustc_query_impl` to fill out the methods for the
`QueryDescription` trait.

Instead, we now emit two new modules from `rustc_queries` containing the
functions with the expressions. `rustc_query_impl` calls these functions
now instead of invoking the macro.

Since we are now defining some of the functions in
`rustc_middle::query`, we now need all the imports for the key types
there as well.
2022-10-14 22:35:56 +02:00
Nilstrieb
1566273f48
Remove unsued variable in query macro 2022-10-14 22:32:05 +02:00
David Wood
fbac1f288b macros: simplify field ordering in diag derive
Following the approach taken in earlier commits to separate formatting
initialization from use in the subdiagnostic derive, simplify the
diagnostic derive by removing the field-ordering logic that previously
solved this problem.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-10-10 14:20:16 +01:00