Commit Graph

873 Commits

Author SHA1 Message Date
bors
7c75fe4c85 Auto merge of #104170 - cjgillot:hir-def-id, r=fee1-dead
Record `LocalDefId` in HIR nodes instead of a side table

This is part of an attempt to remove the `HirId -> LocalDefId` table from HIR.
This attempt is a prerequisite to creation of `LocalDefId` after HIR lowering (https://github.com/rust-lang/rust/pull/96840), by controlling how `def_id` information is accessed.

This first part adds the information to HIR nodes themselves instead of a table.
The second part is https://github.com/rust-lang/rust/pull/103902
The third part will be to make `hir::Visitor::visit_fn` take a `LocalDefId` as last parameter.
The fourth part will be to completely remove the side table.
2022-11-17 07:42:27 +00:00
Matthias Krüger
eefea28dea
Rollup merge of #104320 - fee1-dead-contrib:use-derive-const-in-std, r=oli-obk
Use `derive_const` and rm manual StructuralEq impl

This does not change any semantics of the impl except for the const stability. It should be fine because trait methods and const bounds can never be used in stable without enabling `const_trait_impl`.

cc `@oli-obk`
2022-11-13 17:37:37 +01:00
Camille GILLOT
9d20aca983 Store a LocalDefId in hir::Variant & hir::Field. 2022-11-13 14:06:51 +00:00
Camille GILLOT
18482f7b23 Store a LocalDefId in hir::GenericParam. 2022-11-13 14:05:30 +00:00
Camille GILLOT
290f0781b4 Store LocalDefId in hir::Closure. 2022-11-13 14:04:02 +00:00
Camille GILLOT
dba1503ed3 Ensure codegen_fn_attrs during collection. 2022-11-13 14:02:15 +00:00
bors
8ef2485bd5 Auto merge of #103812 - clubby789:improve-include-bytes, r=petrochenkov
Delay `include_bytes` to AST lowering

Hopefully addresses #65818.
This PR introduces a new `ExprKind::IncludedBytes` which stores the path and bytes of a file included with `include_bytes!()`. We can then create a literal from the bytes during AST lowering, which means we don't need to escape the bytes into valid UTF8 which is the cause of most of the overhead of embedding large binary blobs.
2022-11-12 14:30:34 +00:00
Deadbeef
4b217e4624 Use derive_const and rm manual StructuralEq impl 2022-11-12 12:57:10 +00:00
Dylan DPC
fcbe990093
Rollup merge of #103970 - oli-obk:unhide_unknown_spans, r=estebank
Unhide unknown spans

r? ```@estebank```
2022-11-12 12:02:51 +05:30
clubby789
b2da155a9a Introduce ExprKind::IncludedBytes 2022-11-11 16:31:32 +00:00
Oli Scherer
df2adc4760 Print all labels, even if they have no span. Fall back to main item's span. 2022-11-11 14:45:28 +00:00
Esteban Küber
243496e129 Consider #[must_use] annotation on async fn as also affecting the Future::Output
No longer lint against `#[must_use] async fn foo()`.

When encountering a statement that awaits on a `Future`, check if the
`Future`'s parent item is annotated with `#[must_use]` and emit a lint
if so. This effectively makes `must_use` an annotation on the
`Future::Output` instead of only the `Future` itself.

Fix #78149.
2022-11-10 18:01:03 -08:00
Michael Goulet
fbce7decd8 DiagnosticBuilder -> Diagnostic 2022-11-09 19:42:23 +00:00
bors
534ddc6166 Auto merge of #103720 - crlf0710:most_translation_attr, r=compiler-errors
Lint against usages of `struct_span_lint_hir`.

r? `@compiler-errors`
2022-11-06 11:23:24 +00:00
clubby789
2f882c014f Specify that break cannot be used outside of loop *or* labeled block 2022-11-05 01:12:58 +00:00
Matthias Krüger
612bb7890c
Rollup merge of #103397 - crlf0710:port_dead_code_lint, r=davidtwco
Port `dead_code` lints to be translatable.

This adds an additional comma to lists with three or more items, to be consistent with list formatters like `icu4x`.

r? `@davidtwco`
2022-11-04 18:52:26 +01:00
Charles Lew
a777c46dff Use derive(Subdiagnostic) for ChangeFieldsToBeOfUnitType. 2022-11-04 03:02:09 +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
Amanieu d'Antras
56074b5231 Rewrite implementation of #[alloc_error_handler]
The new implementation doesn't use weak lang items and instead changes
`#[alloc_error_handler]` to an attribute macro just like
`#[global_allocator]`.

The attribute will generate the `__rg_oom` function which is called by
the compiler-generated `__rust_alloc_error_handler`. If no `__rg_oom`
function is defined in any crate then the compiler shim will call
`__rdl_oom` in the alloc crate which will simply panic.

This also fixes link errors with `-C link-dead-code` with
`default_alloc_error_handler`: `__rg_oom` was previously defined in the
alloc crate and would attempt to reference the `oom` lang item, even if
it didn't exist. This worked as long as `__rg_oom` was excluded from
linking since it was not called.

This is a prerequisite for the stabilization of
`default_alloc_error_handler` (#102318).
2022-10-31 16:32:57 +00:00
mejrs
cbeb244b05 Add more track_caller 2022-10-31 16:14:29 +01:00
Cameron Steffen
a6180ede5c Simplify lang item groups 2022-10-29 16:04:10 -05:00
Cameron Steffen
6621279a75 Cleanup weak lang items 2022-10-29 16:04:10 -05:00
Cameron Steffen
f808430497 Factor out ITEM_REFS 2022-10-29 16:04:10 -05:00
Cameron Steffen
ebfa1f0185 Encode LangItem directly 2022-10-29 16:04:10 -05:00
Cameron Steffen
99de57ae13 Improve LanguageItems api 2022-10-29 16:04:04 -05:00
Charles Lew
3b6b6047b6 Lint against usages of struct_span_lint_hir. 2022-10-29 18:03:47 +08:00
Nicholas Nethercote
c8c25ce5a1 Rename some OwnerId fields.
spastorino noticed some silly expressions like `item_id.def_id.def_id`.

This commit renames several `def_id: OwnerId` fields as `owner_id`, so
those expressions become `item_id.owner_id.def_id`.

`item_id.owner_id.local_def_id` would be even clearer, but the use of
`def_id` for values of type `LocalDefId` is *very* widespread, so I left
that alone.
2022-10-29 20:28:38 +11: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
Vadim Petrochenkov
34eb73c72d privacy: Rename "accessibility levels" to "effective visibilities"
And a couple of other naming tweaks

Related to https://github.com/rust-lang/rust/issues/48054
2022-10-26 16:34:53 +04:00
Charles Lew
113e8dfb72 Port dead_code lints to be translatable. 2022-10-24 17:02:31 +08:00
Nilstrieb
c65ebae221
Migrate all diagnostics 2022-10-23 10:09:44 +02:00
Mara Bos
c4f829b2e5 Allow #[unstable] impl for fn() -> UnstableType.
(But not fn() -> !, which is stable.)
2022-10-19 13:34:18 +02:00
Mara Bos
ead96f7f74 Allow #[unstable] impls for fn() with unstable abi. 2022-10-19 12:41:35 +02:00
Dylan DPC
59e0af68ab
Rollup merge of #102954 - GuillaumeGomez:cfg-hide-attr-checks, r=Manishearth
Add missing checks for `doc(cfg_hide(...))`

Part of  #43781.

The `doc(cfg_hide(...))` attribute can only be used at the crate level and takes a list of attributes as argument.

r? ```@Manishearth```
2022-10-15 15:45:32 +05:30
Guillaume Gomez
f528414e40 Add missing checks for doc(cfg_hide(...)) attribute 2022-10-14 11:29:54 +02:00
Rageking8
7122abaddf more dupe word typos 2022-10-14 12:57:56 +08:00
Dylan DPC
32471a7035
Rollup merge of #102110 - CleanCut:migrate_rustc_passes_diagnostics, r=davidtwco
Migrate rustc_passes diagnostics

Picks up abandoned work from https://github.com/rust-lang/rust/pull/100870

I would like to do this collaboratively, as there is a lot of work! Here's the process:

- Comment below that you are willing to help and I will add you as a collaborator to my `rust` fork (that gives you write access)
- Indicate which file/task you would like to work on (so we don't duplicate work) from the list below
- Do the work, push up a commit, comment that you're done with that file/task
- Repeat until done 😄

### Files to Migrate (in `compiler/rustc_passes/src/`)

- [x] check_attr.rs ``@CleanCut``
- [x] check_const.rs ``@CleanCut``
- [x] dead.rs ``@CleanCut``
- [x] debugger_visualizer.rs ``@CleanCut``
- [x] diagnostic_items.rs ``@CleanCut``
- [x] entry.rs ``@CleanCut``
- [x] lang_items.rs ``@CleanCut``
- [x] layout_test.rs ``@CleanCut``
- [x] lib_features.rs ``@CleanCut``
- [x] ~liveness.rs~ ``@CleanCut`` Nothing to do
- [x] loops.rs ``@CleanCut``
- [x] naked_functions.rs ``@CleanCut``
- [x] stability.rs ``@CleanCut``
- [x] weak_lang_items.rs ``@CleanCut``

### Tasks

- [x] Rebase on current `master` ``@CleanCut``
- [x] Review work from [the earlier PR](https://github.com/rust-lang/rust/pull/100870) and make sure it all looks good
  - [x] compiler/rustc_error_messages/locales/en-US/passes.ftl ``@CleanCut``
  - [x] compiler/rustc_passes/src/check_attr.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/errors.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/lang_items.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/lib.rs ``@CleanCut``
  - [x] compiler/rustc_passes/src/weak_lang_items.rs ``@CleanCut``
2022-10-12 11:11:23 +05:30
Nathan Stocks
5ef1c03bd8 make up your mind, rustfmt 2022-10-10 10:06:52 -06:00
Nathan Stocks
50e2795624 remove out-of-date fixme 2022-10-10 09:52:53 -06:00
Michael Goulet
d3bd6beb97 Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
Michael Goulet
70f3c79c50 ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
Nathan Stocks
31c269ae75 avoid string dispatch in fluent 2022-10-07 14:39:09 -06:00
Nathan Stocks
57eba4f535 avoid string dispatch in fluent 2022-10-07 13:19:28 -06:00
Nathan Stocks
8e07a85ad7 Remove code that was removed in master, and the corresponding diagnostic 2022-10-07 13:19:28 -06:00
Nathan Stocks
965dbf6c28 First batch of review feedback changes from #102110 2022-10-07 13:19:28 -06:00
Nathan Stocks
be4059dd3e migrate stability.rs to translateable diagnostics 2022-10-07 13:19:27 -06:00
Nathan Stocks
3fe8e004e9 migrate the rest of check_attr.rs to translateable diagnostics 2022-10-07 13:19:27 -06:00
Nathan Stocks
a7aa1850b2 migrate dead.rs to translateable diagnostics 2022-10-07 13:19:27 -06:00
Nathan Stocks
f0afb88302 migrate lang_items.rs to translateable diagnostics 2022-10-07 13:19:27 -06:00