Commit Graph

255 Commits

Author SHA1 Message Date
Vadim Petrochenkov
b6312eb943 Create some minimal HIR for associated opaque types 2024-03-13 17:33:09 +03:00
Gary Guo
93fa8579c6 Add asm label support to AST and HIR 2024-02-24 18:49:39 +00:00
Frank King
879a1e5713 Lower anonymous structs or unions to HIR 2024-02-12 12:47:23 +08: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
Vadim Petrochenkov
a61019b290 hir: Remove fn opt_hir_id and fn opt_span 2024-02-07 09:38:24 +03:00
Vadim Petrochenkov
363b098245 hir: Make sure all HirIds have corresponding HIR Nodes 2024-02-07 09:38:24 +03: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
Vadim Petrochenkov
b2b5b91bfb hir: Use InferArg in ArrayLen::Infer 2024-01-28 02:04:39 +03:00
Lieselotte
7889e99b55
Add PatKind::Err 2024-01-17 03:14:16 +01:00
Bryanskiy
d69cd6473c Delegation implementation: step 1 2024-01-12 14:11:16 +03:00
Matthew Jasper
407cb24142 Remove hir::Guard
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2024-01-05 10:56:59 +00:00
Michael Goulet
909dd864f1 Make closures carry their own ClosureKind, rather than deducing what it is from movability 2023-12-25 16:29:15 +00:00
León Orell Valerian Liehr
b09889b959
Rid the AST & HIR pretty printers of syntactic cruft 2023-12-22 14:32:40 +01:00
Alona Enraght-Moony
11337805fb Give VariantData::Struct named fields, to clairfy recovered. 2023-12-20 00:07:34 +00:00
Jubilee
1d54949765
Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillot
Collect lang items from AST, get rid of `GenericBound::LangItemTrait`

r? `@cjgillot`
cc #115178

Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change:
1. A lot of `rustc_ast_lowering` for things like expr `..`
2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently.
3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem`

Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15 14:08:15 -08:00
Michael Goulet
fc010de26b banish hir::GenericBound::LangItemTrait 2023-12-15 16:17:27 +00:00
Michael Goulet
70b9dad3dc Annotate some bugs 2023-12-15 14:45:06 +00:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Deadbeef
65212a07e7 Remove #[rustc_host], use internal desugaring 2023-12-05 01:15:21 +00:00
Nadrieril
a3838c8550 Add never_patterns feature gate 2023-11-29 03:58:29 +01:00
Michael Goulet
fa7633dda1 Remove HirId from QPath::LangItem 2023-11-25 18:02:11 +00:00
bors
cc4bb0de20 Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-dead
`rustc_ast_pretty` cleanups

Some improvements I found while looking at this code.

r? `@fee1-dead`
2023-11-22 05:09:33 +00:00
Nicholas Nethercote
9fe6bb4a10 Add some comments. 2023-11-22 11:06:16 +11:00
Nicholas Nethercote
10c8b56af1 Factor out common code in PrintState.
The AST and HIR versions of `State::print_ident` are textually
identical, but the types differ slightly. This commit factors out the
common code they both have by replacing `print_ident` with `ann_post`,
which is a smaller function that still captures the type difference.
2023-11-22 08:13:21 +11:00
Nicholas Nethercote
33cee0b22c Remove NO_ANN.
This makes `rustc_hir_pretty` more like `rustc_ast_pretty`.
2023-11-22 08:13:21 +11:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
Dinu Blanovschi
241a654c07 Fix remaining uses of CaptureBy::Value 2023-11-04 19:48:44 +01:00
Guillaume Gomez
824e3677c2
Rollup merge of #117068 - nnethercote:clean-up-Cargo-toml, r=wesleywiser
Clean up `compiler/rustc*/Cargo.toml`

Mostly by sorting dependencies, plus some other minor things.

r? ``@wesleywiser``
2023-10-30 17:33:15 +01:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
DaniPopes
2c1dbed4aa
Print variadic argument pattern in HIR pretty printer 2023-10-25 17:36:04 +02:00
Nicholas Nethercote
7d35902c62 Fiddle with State functions.
Remove and inline `new_from_input`, because it has a single call site.
And move `attrs` into the earlier `impl` block.
2023-10-11 10:46:55 +11:00
Nicholas Nethercote
494bc8514a Tweak comments.
- Remove an out-of-date comment. (There is no `PpAnn` implementation for `hir::Crate`.)
- Remove a low-value comment.
- And break a very long comment.
2023-10-11 10:46:33 +11:00
Nicholas Nethercote
664b1858aa Remove many unneeded pubs. 2023-10-11 09:28:06 +11:00
Nicholas Nethercote
b6b11c72c9 Rejig some top-level rustc_hir_pretty functions.
There are several that are unused and can be removed.

And there are some calls to `to_string`, which can be expressed more
nicely as a `foo_to_string` call, and then `to_string` need not be
`pub`. (This requires adding `pat_to_string`).
2023-10-10 14:08:12 +11:00
Michael Goulet
087a571e70 Record asyncness span in HIR 2023-09-21 19:18:14 +00:00
bors
f88a8b71ce Auto merge of #114545 - fee1-dead-contrib:lower-impl-effect, r=oli-obk
correctly lower `impl const` to bind to host effect param

r? `@oli-obk`
2023-08-08 19:23:41 +00:00
Deadbeef
92f4c59e48 lower impl const to bind to host effect param 2023-08-06 13:34:53 +00:00
Nilstrieb
5706be1854 Improve spans for indexing expressions
Indexing is similar to method calls in having an arbitrary
left-hand-side and then something on the right, which is the main part
of the expression. Method calls already have a span for that right part,
but indexing does not. This means that long method chains that use
indexing have really bad spans, especially when the indexing panics and
that span in coverted into a panic location.

This does the same thing as method calls for the AST and HIR, storing an
extra span which is then put into the `fn_span` field in THIR.
2023-08-04 13:17:39 +02:00
León Orell Valerian Liehr
9213aec762
Lower generic const items to HIR 2023-07-28 22:21:40 +02:00
Maybe Waffle
ccb71ff424 hir: Add Become expression kind 2023-06-26 08:56:32 +00:00
Camille GILLOT
ca4d0d4c24 Separate AnonConst from ConstBlock in HIR. 2023-06-02 21:25:18 +00:00
Nilstrieb
c63b6a437e Rip it out
My type ascription
Oh rip it out
Ah
If you think we live too much then
You can sacrifice diagnostics
Don't mix your garbage
Into my syntax
So many weird hacks keep diagnostics alive
Yet I don't even step outside
So many bad diagnostics keep tyasc alive
Yet tyasc doesn't even bother to survive!
2023-05-01 16:15:13 +08:00
DrMeepster
3206960ec6 minor tweaks 2023-04-21 02:14:04 -07:00
DrMeepster
511e457c4b offset_of 2023-04-21 02:14:02 -07:00
Nilstrieb
4b4948c2e3 Remove identity casts 2023-04-09 23:22:14 +02:00
Michael Goulet
8b592db27a Add (..) syntax for RTN 2023-03-28 01:14:28 +00:00
clubby789
9afffc5b61 Remove box expressions from HIR 2023-03-14 17:18:26 +00:00
clubby789
dd7df04e16 Remove uses of box_syntax in rustc and tools 2023-03-12 13:19:46 +00:00
Michael Goulet
c0e58c3420 Add ErrorGuaranteed to HIR ExprKind::Err 2023-02-25 19:46:36 +00:00
Michael Goulet
a772a6fc2a Add ErrorGuaranteed to HIR TyKind::Err 2023-02-25 19:46:36 +00:00
Maybe Waffle
4d75f61832 Use Mutability::{is_mut, is_not} 2023-01-30 12:26:26 +00:00
Deadbeef
4fb10c0ce4 parse const closures 2023-01-12 02:28:37 +00: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
Nilstrieb
9067e4417e Rename Rptr to Ref in AST and HIR
The name makes a lot more sense, and `ty::TyKind` calls it `Ref` already
as well.
2022-12-28 18:52:36 +01:00
Matthias Krüger
de59844c98 more clippy::complexity fixes 2022-12-15 00:09:10 +01:00
bors
2cd2070af7 Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`.

Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-12 05:16:50 +00:00
Maybe Waffle
12ce0c2a89 Remove outdated syntax from trait alias pretty printing 2022-12-06 13:45:11 +00:00
Nicholas Nethercote
7e0c6dba0d Remove LitKind::synthesize_token_lit.
It has a single call site in the HIR pretty printer, where the resulting
token lit is immediately converted to a string.

This commit replaces `LitKind::synthesize_token_lit` with a `Display`
impl for `LitKind`, which can be used by the HIR pretty printer.
2022-12-05 16:33:24 +11:00
Matthias Krüger
c89bff29e5
Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot
Keep track of the start of the argument block of a closure

This removes a call to `tcx.sess.source_map()` from [compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs](https://github.com/rust-lang/rust/compare/master...SarthakSingh31:issue-97417-1?expand=1#diff-8406bbc0d0b43d84c91b1933305df896ecdba0d1f9269e6744f13d87a2ab268a) as required by #97417.

VsCode automatically applied `rustfmt` to the files I edited under `src/tools`. I can undo that if its a problem.

r? `@cjgillot`
2022-12-03 17:37:41 +01:00
Nicholas Nethercote
e658144586 Rename LitKind::to_token_lit as LitKind::synthesize_token_lit.
This makes it clearer that it's not a lossless conversion, which I find
helpful.
2022-12-02 10:23:44 +11:00
Vadim Petrochenkov
1f259ae679 rustc_hir: Change representation of import paths to support multiple resolutions 2022-12-01 18:51:05 +03:00
Sarthak Singh
8f705e2425 Keep track of the start of the argument block of a closure 2022-11-28 14:09:00 +05:30
bors
454784afba Auto merge of #104048 - cjgillot:split-lifetime, r=compiler-errors
Separate lifetime ident from lifetime resolution in HIR

Drive-by: change how suggested generic args are computed.
Fixes https://github.com/rust-lang/rust/issues/103815

I recommend reviewing commit-by-commit.
2022-11-27 14:30:19 +00:00
Maybe Waffle
da40965300 Add Mutability::{is_mut,is_not} 2022-11-23 20:26:31 +00:00
Camille GILLOT
fb7d25e978 Separate lifetime ident from resolution in HIR. 2022-11-23 19:33:06 +00:00
Camille GILLOT
9d20aca983 Store a LocalDefId in hir::Variant & hir::Field. 2022-11-13 14:06:51 +00:00
Camille GILLOT
290f0781b4 Store LocalDefId in hir::Closure. 2022-11-13 14:04:02 +00:00
Yutaro Ohno
7334526c38 pretty: fix to print some lifetimes on HIR pretty-print 2022-10-15 23:34:21 +09:00
Yuki Okushi
24424d0acb
Rollup merge of #102829 - compiler-errors:rename-impl-item-kind, r=TaKO8Ki
rename `ImplItemKind::TyAlias` to `ImplItemKind::Type`

The naming of this variant seems inconsistent given that this is not really a "type alias", and the associated type variant for `TraitItemKind` is just called `Type`.
2022-10-10 00:09:42 +09:00
Michael Goulet
70f3c79c50 ImplItemKind::TyAlias => ImplItemKind::Type 2022-10-09 07:09:57 +00:00
reez12g
9a4c5abe45 Remove from compiler/ crates 2022-09-29 16:49:04 +09:00
Nicholas Nethercote
e67f39f8bc Introduce DotDotPos.
This shrinks `hir::Pat` from 88 to 72 bytes.
2022-09-08 15:25:50 +10:00
bors
6c358c67d4 Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cjgillot
`BindingAnnotation` refactor

* `ast::BindingMode` is deleted and replaced with `hir::BindingAnnotation` (which is moved to `ast`)
* `BindingAnnotation` is changed from an enum to a tuple struct e.g. `BindingAnnotation(ByRef::No, Mutability::Mut)`
* Associated constants added for convenience `BindingAnnotation::{NONE, REF, MUT, REF_MUT}`

One goal is to make it more clear that `BindingAnnotation` merely represents syntax `ref mut` and not the actual binding mode. This was especially confusing since we had `ast::BindingMode`->`hir::BindingAnnotation`->`thir::BindingMode`.

I wish there were more symmetry between `ByRef` and `Mutability` (variant) naming (maybe `Mutable::Yes`?), and I also don't love how long the name `BindingAnnotation` is, but this seems like the best compromise. Ideas welcome.
2022-09-06 03:16:29 +00:00
bors
b44197abb0 Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-hir, r=cjgillot
Separate the receiver from arguments in HIR

Related to #100232

cc `@cjgillot`
2022-09-05 16:21:40 +00:00
Takayuki Maeda
87c6da363f separate the receiver from arguments in HIR 2022-09-05 22:25:49 +09:00
Nicholas Nethercote
ee244bf196 Remove dead code from print_generic_args. 2022-09-05 14:20:25 +10:00
Cameron Steffen
02ba216e3c Refactor and re-use BindingAnnotation 2022-09-02 12:55:05 -05:00
5225225
09ea9f0a87 Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
Nicholas Nethercote
5d3cc1713a Rename some things related to literals.
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is
  `token::Lit`, which is not a token. (This has been confusing me for a
  long time.)
  reasonable because we have an `ast::token::Lit` inside an `ast::Lit`.
- Rename `LitKind::{from,to}_lit_token` as
  `LitKind::{from,to}_token_lit`, to match the above change and
  `token::Lit`.
2022-08-16 13:41:34 +10:00
bors
6ce76091c7 Auto merge of #96745 - ehuss:even-more-attribute-validation, r=cjgillot
Visit attributes in more places.

This adds 3 loosely related changes (I can split PRs if desired):

- Attribute checking on pattern struct fields.
- Attribute checking on struct expression fields.
- Lint level visiting on pattern struct fields, struct expression fields, and generic parameters.

There are still some lints which ignore lint levels in various positions. This is a consequence of how the lints themselves are implemented. For example, lint levels on associated consts don't work with `unused_braces`.
2022-08-15 05:50:54 +00:00
Eric Huss
b651c1cebe Check attributes on struct expression fields.
Attributes on struct expression fields were not being checked for
validity. This adds the fields as HIR nodes so that `CheckAttrVisitor`
can visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Eric Huss
1b464c73b7 Check attributes on pattern fields.
Attributes on pattern struct fields were not being checked for validity.
This adds the fields as HIR nodes so that the `CheckAttrVisitor` can
visit those nodes to check their attributes.
2022-08-11 21:48:39 -07:00
Michael Goulet
e182d12a84 Fix HIR pretty printing of let else 2022-08-12 02:47:57 +00:00
Michael Goulet
7a45a60418 use rustc_hir_pretty::qpath_to_string to avoid span_to_snippet when rendering path 2022-07-17 04:58:38 +00:00
Dylan DPC
e5a86d7358
Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillot
Implement `for<>` lifetime binder for closures

This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following:

```rust
let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) };
//       ^^^^^^^^^^^--- new!
```

cc ``@Aaron1011`` ``@cjgillot``
2022-07-14 14:14:21 +05:30
Maybe Waffle
df4fee9841 Add an indirection for closures in hir::ExprKind
This helps bring `hir::Expr` size down, `Closure` was the biggest
variant, especially after `for<>` additions.
2022-07-12 21:00:13 +04:00
Maybe Waffle
c2dbd62c7c Lower closure binders to hir & properly check them 2022-07-12 21:00:03 +04:00
Ding Xiang Fei
1cd30e7b32
move else block into the Local struct 2022-07-11 23:20:37 +02:00
Ding Xiang Fei
6c529ded86
lower let-else in MIR instead 2022-07-11 23:20:36 +02:00
KaDiWa
46ccde4408
clean up the borrowing in rustc_hir_pretty
a lot of the `&`s and `ref`s were redundant
2022-07-03 18:51:14 +02:00
Cameron Steffen
ec82bc1996 Factor out hir::Node::Binding 2022-07-01 10:04:19 -05:00
Camille GILLOT
7437136f0e Use CreateParameter mode for closures too. 2022-06-21 21:13:43 +02:00
Camille GILLOT
3039cfeb6a Make ExprKind::Closure a struct variant. 2022-06-12 00:16:27 +02:00
Camille GILLOT
a07290047e Compute lifetimes in scope at diagnostic time. 2022-06-04 15:28:15 +02:00
SparrowLii
5251a80c0a use hir::Let in hir::Guard 2022-05-09 20:35:58 +08:00
Camille GILLOT
94449e6101 Store all generic bounds as where predicates. 2022-04-30 13:55:13 +02:00
Camille GILLOT
05b29f9a92 Inline WhereClause into Generics. 2022-04-30 13:51:49 +02:00
Camille GILLOT
71b4e2d852 Box HIR Generics and Impl. 2022-04-30 13:51:49 +02:00
Camille GILLOT
4e8046f67a Stop pretty-printing HIR visibility. 2022-04-23 09:55:25 +02:00
Camille GILLOT
10d10efb21 Stop visiting visibility. 2022-04-23 09:53:45 +02:00