Commit Graph

366 Commits

Author SHA1 Message Date
Nicholas Nethercote 8d32578fe1 Rename and reorder lots of lifetimes.
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and
  'me with vanilla 'a. These are cases where the original name isn't
  really any more informative than 'a.
- Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime
  applies to multiple fields and so the original lifetime name isn't
  really accurate.
- Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13 15:46:20 +10:00
Nicholas Nethercote 71bffef4f9 Add `warn(unreachable_pub)` to `rustc_privacy`. 2024-08-29 20:18:44 +10:00
Michael Goulet 4609841c07 Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
Nicholas Nethercote 84ac80f192 Reformat `use` declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Camille GILLOT 9074427c69 Do not ICE in privacy when type inference fails. 2024-06-17 10:09:27 +00:00
Nicholas Nethercote 75b164d836 Use `tidy` to sort crate attributes for all compiler crates.
We already do this for a number of crates, e.g. `rustc_middle`,
`rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`.

For the ones we don't, in many cases the attributes are a mess.
- There is no consistency about order of attribute kinds (e.g.
  `allow`/`deny`/`feature`).
- Within attribute kind groups (e.g. the `feature` attributes),
  sometimes the order is alphabetical, and sometimes there is no
  particular order.
- Sometimes the attributes of a particular kind aren't even grouped
  all together, e.g. there might be a `feature`, then an `allow`, then
  another `feature`.

This commit extends the existing sorting to all compiler crates,
increasing consistency. If any new attribute line is added there is now
only one place it can go -- no need for arbitrary decisions.

Exceptions:
- `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`,
  because they have no crate attributes.
- `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's
  ignored in `rustfmt.toml`).
2024-06-12 15:49:10 +10:00
Oli Scherer a34c26e7ec Make `body_owned_by` return the body directly.
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29 10:04:08 +00:00
Michael Goulet 3bcdf3058e split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
Michael Goulet 1e5ec0a12c Lift `TraitRef` into `rustc_type_ir` 2024-05-10 15:44:03 -04:00
Michael Goulet 1c19b6ad60 Rename Generics::params to Generics::own_params 2024-05-09 20:58:46 -04:00
Nicholas Nethercote 9b3ef5404c Remove some unneeded `Cargo.toml` dependencies.
I found these with a hacky shell script.
2024-05-03 15:33:52 +10:00
Nicholas Nethercote 6341935a13 Remove `extern crate tracing` from numerous crates. 2024-04-30 16:47:49 +10:00
Oli Scherer 84acfe86de Actually create ranged int types in the type system. 2024-04-08 12:02:19 +00:00
Guillaume Gomez b376f49e30 Rename `hir::Local` into `hir::LetStmt` 2024-03-22 20:36:21 +01:00
Ralf Jung 0dd8a83e5e rename items -> free_items 2024-03-21 14:27:11 +01:00
Oli Scherer 746e4eff26 Test and implement reachability for trait objects and generic parameters of functions 2024-03-14 14:10:45 +00:00
Oli Scherer 9816915954 Change `DefKind::Static` to a struct variant 2024-03-12 05:53:46 +00:00
Jason Newcomb ea9ae30671 Convert `SpannedTypeVisitor` to use `VisitorResult` 2024-03-05 13:30:46 -05:00
Jason Newcomb be9b125d41 Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult` 2024-03-05 13:28:15 -05:00
Nicholas Nethercote b4e9f93eb4 Mark some once-again-unreachable paths as unreachable.
This undoes the changes from #121482 and #121586, now that stashed errors
will trigger more early aborts.
2024-02-29 11:08:29 +11:00
Nicholas Nethercote d0ef108ce9 Rename `DiagnosticArgFromDisplay` as `DiagArgFromDisplay`. 2024-02-28 08:55:37 +11:00
Nicholas Nethercote 21bb1a4359 Allow for a missing `adt_def` in `NamePrivacyVisitor`.
This was caused by 72b172bdf6 in #121206. That commit removed an early
return from `analysis` when there are stashed errors. As a result, it's
possible to reach privacy analysis when there are stashed errors, which
means more code paths can be reached. One such code path was handled in
that commit, where a `span_bug` was changed to a `span_delayed_bug`.

This commit handles another such code path uncovered by fuzzing, in much
the same way.

Fixes #121455.
2024-02-23 10:57:11 +11:00
Shoyu Vanilla 3856df059e Dejargnonize subst 2024-02-12 15:46:35 +09:00
Matthias Krüger 46a0448405
Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco
Invert diagnostic lints.

That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.

r? ````@davidtwco````
2024-02-09 14:41:50 +01:00
Oli Scherer e867886c6a Remove dead code 2024-02-07 15:26:07 +00:00
Oli Scherer 5c25de67d4 Remove now-useless method override 2024-02-07 15:03:31 +00:00
Oli Scherer 4389a1cc42 Stop using `hir_ty_to_ty` in rustc_privacy 2024-02-07 14:59:26 +00:00
Michael Goulet c567eddec2 Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
Nicholas Nethercote 0ac1195ee0 Invert diagnostic lints.
That is, change `diagnostic_outside_of_impl` and
`untranslatable_diagnostic` from `allow` to `deny`, because more than
half of the compiler has be converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow`
attributes, which proves that this change is warranted.
2024-02-06 13:12:33 +11:00
Nicholas Nethercote 5d9dfbd08f Stop using `String` for error codes.
Error codes are integers, but `String` is used everywhere to represent
them. Gross!

This commit introduces `ErrCode`, an integral newtype for error codes,
replacing `String`. It also introduces a constant for every error code,
e.g. `E0123`, and removes the `error_code!` macro. The constants are
imported wherever used with `use rustc_errors::codes::*`.

With the old code, we have three different ways to specify an error code
at a use point:
```
error_code!(E0123)  // macro call

struct_span_code_err!(dcx, span, E0123, "msg");  // bare ident arg to macro call

\#[diag(name, code = "E0123")]  // string
struct Diag;
```

With the new code, they all use the `E0123` constant.
```
E0123  // constant

struct_span_code_err!(dcx, span, E0123, "msg");  // constant

\#[diag(name, code = E0123)]  // constant
struct Diag;
```

The commit also changes the structure of the error code definitions:
- `rustc_error_codes` now just defines a higher-order macro listing the
  used error codes and nothing else.
- Because that's now the only thing in the `rustc_error_codes` crate, I
  moved it into the `lib.rs` file and removed the `error_codes.rs` file.
- `rustc_errors` uses that macro to define everything, e.g. the error
  code constants and the `DIAGNOSTIC_TABLES`. This is in its new
  `codes.rs` file.
2024-01-29 07:41:41 +11:00
Matthias Krüger c48c77e160
Rollup merge of #120339 - petrochenkov:nameprivisit, r=michaelwoerister
privacy: Refactor top-level visiting in `NamePrivacyVisitor`

Full hierarchical visiting (`nested_filter::All`) is not necessary, visiting all item-likes in isolation is enough.
Tracking current item is not necessary, passing any `HirId` with the same parent module to `adjust_ident_and_get_scope` is enough.

Follow up to https://github.com/rust-lang/rust/pull/120284.
2024-01-26 14:43:31 +01:00
clubby789 fd29f74ff8 Remove unused features 2024-01-25 14:01:33 +00:00
Vadim Petrochenkov 15dbdabdb5 privacy: Refactor top-level visiting in `NamePrivacyVisitor` 2024-01-25 16:55:29 +03:00
Vadim Petrochenkov ba75970473 privacy: Refactor top-level visiting in `TypePrivacyVisitor` 2024-01-24 00:42:01 +03:00
Nicholas Nethercote e164cf30f8 Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`. 2024-01-23 08:09:05 +11:00
Nicholas Nethercote 99472c7049 Remove `Session` methods that duplicate `DiagCtxt` methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Vadim Petrochenkov 5e5d82e803 resolve: Eagerly feed closure visibilities
Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`
2023-12-20 13:42:58 +03:00
Vadim Petrochenkov be321aa473 resolve: Replace visibility table in resolver outputs with query feeding
Also feed missing visibilities for import stems and trait impl items, which were previously evaluated lazily.
2023-12-18 02:26:55 +03:00
zetanumbers 24f009c5e5 Move some methods from `tcx.hir()` to `tcx`
Renamings:
- find -> opt_hir_node
- get -> hir_node
- find_by_def_id -> opt_hir_node_by_def_id
- get_by_def_id -> hir_node_by_def_id

Fix rebase changes using removed methods

Use `tcx.hir_node_by_def_id()` whenever possible in compiler

Fix clippy errors

Fix compiler

Apply suggestions from code review

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>

Add FIXME for `tcx.hir()` returned type about its removal

Simplify with with `tcx.hir_node_by_def_id`
2023-12-12 06:40:29 -08:00
David Wood 5d97724002
privacy: visit trait def id of projections
A refactoring in #117076 changed the `DefIdVisitorSkeleton` to avoid
calling `visit_projection_ty` for `ty::Projection` aliases, and instead
just iterate over the args - this makes sense, as `visit_projection_ty`
will indirectly visit all of the same args, but in doing so, will also
create a `TraitRef` containing the trait's `DefId`, which also gets
visited. The trait's `DefId` isn't visited when we only visit the
arguments without separating them into `TraitRef` and own args first.

Signed-off-by: David Wood <david@davidtw.co>
2023-12-08 14:26:03 +00:00
Vadim Petrochenkov 55d08f50ea privacy: Simplify `update_macro_reachable`
Address a FIXME in code.
2023-12-06 16:44:14 +03:00
bors 2da59b8676 Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errors
Cleanup error handlers

Mostly by making function naming more consistent. More to do after this, but this is enough for one PR.

r? compiler-errors
2023-12-02 02:48:34 +00:00
Nicholas Nethercote 5d1d384443 Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
bohan d0941f92d7 vis note for no pub reexports glob import 2023-12-01 12:10:07 +08:00
Guillaume Gomez c6d20d70b4
Rollup merge of #118311 - bvanjoi:merge_coroutinue_into_closure, r=petrochenkov
merge `DefKind::Coroutine` into `Defkind::Closure`

Related to #118188

We no longer need to be concerned about the precise type whether it's `DefKind::Closure` or `DefKind::Coroutine`.

Furthermore, thanks for the great work done by `@petrochenkov` on investigating https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Why.20does.20it.20hang.20when.20querying.20.EF.BB.BF.60opt_def_kind.60.3F

r? `@petrochenkov`
2023-11-26 15:44:54 +01:00
bohan f23befe6c1 merge `DefKind::Coroutine` into `DefKind::Closure` 2023-11-26 21:05:08 +08:00
Vadim Petrochenkov c697927f44 rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` cleanup 2023-11-26 12:41:21 +03:00
bors 5c97719393 Auto merge of #118250 - petrochenkov:optdefkind, r=compiler-errors
rustc: Make `def_kind` mandatory for all `DefId`s

Prerequisite for https://github.com/rust-lang/rust/pull/118188.
2023-11-26 04:44:20 +00:00
Nicholas Nethercote 57cd5e6551 Use `rustc_fluent_macro::fluent_messages!` directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nicholas Nethercote a733082be9 Avoid need for `{D,Subd}iagnosticMessage` imports.
The `fluent_messages!` macro produces uses of
`crate::{D,Subd}iagnosticMessage`, which means that every crate using
the macro must have this import:
```
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
```

This commit changes the macro to instead use
`rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the
imports.
2023-11-26 08:38:00 +11:00