Commit Graph

578 Commits

Author SHA1 Message Date
Vadim Petrochenkov
37a72a2e3e rustc_ast: Merge impls and reorder methods for attributes and meta items 2023-02-11 23:23:17 +04:00
Dylan DPC
815dc9c480
Rollup merge of #107544 - nnethercote:improve-TokenCursor, r=petrochenkov
Improve `TokenCursor`.

Some small improvements, for things that were bugging me.

Best reviewed one commit at a time.

r? ``@petrochenkov``
2023-02-03 23:04:51 +05:30
bors
a94b9fd0ac Auto merge of #107569 - petrochenkov:optattr, r=nnethercote
ast: Optimize list and value extraction primitives for attributes

It's not necessary to convert the whole attribute into a meta item to extract something specific.
2023-02-03 11:19:03 +00:00
Nicholas Nethercote
a86fc727fa Rename Cursor/CursorRef as TokenTreeCursor/RefTokenTreeCursor.
This makes it clear they return token trees, and makes for a nice
comparison against `TokenCursor` which returns tokens.
2023-02-03 10:06:52 +11:00
Nicholas Nethercote
b23f272db0 Make clear that TokenTree::Token shouldn't contain a delimiter. 2023-02-03 10:06:52 +11:00
Nicholas Nethercote
af1d16e82d Improve doc comment desugaring.
Sometimes the parser needs to desugar a doc comment into `#[doc =
r"foo"]`. Currently it does this in a hacky way: by pushing a "fake" new
frame (one without a delimiter) onto the `TokenCursor` stack.

This commit changes things so that the token stream itself is modified
in place. The nice thing about this is that it means
`TokenCursorFrame::delim_sp` is now only `None` for the outermost frame.
2023-02-03 10:06:52 +11:00
Michael Goulet
e4b2936983 Revert "Teach parser to understand fake anonymous enum syntax" and related commits
Revert "review comment: Remove AST AnonTy"

This reverts commit 020cca8d36.

Revert "Ensure macros are not affected"

This reverts commit 12d18e4031.

Revert "Emit fewer errors on patterns with possible type ascription"

This reverts commit c847a01a3b.

Revert "Teach parser to understand fake anonymous enum syntax"

This reverts commit 2d82420665.
2023-02-02 05:54:35 +00:00
Vadim Petrochenkov
a9c8a5c025 ast: Optimize list and value extraction primitives for attributes
It's not necessary to convert the whole attribute into a meta item to extract something specific
2023-02-01 22:35:02 +04:00
Maybe Waffle
fd649a3cc5 Replace enum ==s with matches where it makes sense 2023-01-30 12:26:26 +00:00
Yuki Okushi
bed113de49
Rollup merge of #107194 - xfix:remove-slice-internals-dependency-in-rustc-ast, r=Nilstrieb
Remove dependency on slice_internals feature in rustc_ast

This reduces dependency on unstable features by the compiler.
2023-01-28 00:23:12 +09:00
Mara Bos
0abf8a0617 Replace format flags u32 by enums and bools. 2023-01-27 08:53:39 +01:00
bors
3e97763872 Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Move format_args!() into AST (and expand it during AST lowering)

Implements https://github.com/rust-lang/compiler-team/issues/541

This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier.

This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`.

This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
2023-01-26 12:44:47 +00:00
Matthias Krüger
ba928ba041
Rollup merge of #106960 - estebank:parse-anon-enums, r=cjgillot
Teach parser to understand fake anonymous enum syntax

Parse `Ty | OtherTy` in function argument and return types.
Parse type ascription in top level patterns.

Minimally address #100741.
2023-01-26 06:15:24 +01:00
Mara Bos
db731e42b3 Work around issue 106930. 2023-01-24 16:44:00 +01:00
Esteban Küber
020cca8d36 review comment: Remove AST AnonTy 2023-01-23 18:21:08 +00:00
Konrad Borowski
f72e17f8fb Remove dependency on slice_internals feature in rustc_ast 2023-01-22 13:05:47 +01:00
Matthias Krüger
68f12338af
Rollup merge of #104505 - WaffleLapkin:no-double-spaces-in-comments, r=jackh726
Remove double spaces after dots in comments

Most of the comments do not have double spaces, so I assume these are typos.
2023-01-17 20:21:25 +01:00
Maybe Waffle
6a28fb42a8 Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
Esteban Küber
2d82420665 Teach parser to understand fake anonymous enum syntax
Parse `-> Ty | OtherTy`.
Parse type ascription in top level patterns.
2023-01-17 01:58:32 +00:00
Ezra Shaw
e590b93499
make error emitted on impl &Trait nicer 2023-01-15 12:23:46 +13:00
Deadbeef
4fb10c0ce4 parse const closures 2023-01-12 02:28:37 +00:00
Mara Bos
a4dbcb525b Expand format_args!() in rust_ast_lowering. 2023-01-12 00:25:45 +01: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
Matthias Krüger
11020b93b6
Rollup merge of #106361 - clubby789:int-literal-too-large, r=estebank
Note maximum integer literal for `IntLiteralTooLarge`

Closes #105908

`@rustbot` label +A-diagnostics
2023-01-04 07:28:56 +01:00
Michael Goulet
d4cf00f03d
Rollup merge of #106383 - Manishearth:ast-docs, r=compiler-errors
Document some of the AST nodes

Someone was confused about some of this on Zulip, added some docs

We probably should make sure every last field/variant in the AST/HIR is documented at some point

`@bors` rollup
2023-01-02 15:39:19 -08:00
Manish Goregaokar
157211ff2f Document rustc_ast::FnHeader fields 2023-01-02 14:42:27 -08:00
Manish Goregaokar
3c7c694e73 Document rustc_ast::Extern variants 2023-01-02 14:42:27 -08:00
clubby789
537c7f4fa9 Print correct base for too-large literals
Also update tests
2023-01-02 11:43:07 +00: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
bors
300aa907a6 Auto merge of #105701 - RedDocMD:bug-105634, r=cjgillot
Allow .. to be parsed as let initializer

.. and ..= are valid expressions, however when used in a let statement
it is not parsed.
Fixes #105634
2022-12-25 14:42:49 +00:00
Jeremy Stucki
3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01: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
88d5f7f4ce Make #[custom_encodable] an attribute for newtype_index
Makes the syntax a little more rusty.
2022-12-18 21:02:14 +01:00
Deep Majumder
4af9e6a1c2 Little fixes 2022-12-16 18:41:08 +05:30
Matthias Krüger
de59844c98 more clippy::complexity fixes 2022-12-15 00:09:10 +01:00
Deep Majumder
c4d0c91161 Allow .. to be parsed as let initializer
.. and ..= are valid expressions, however when used in a let statement
it is not parsed.
2022-12-14 19:12:30 +05:30
Matthias Krüger
4069792d73
Rollup merge of #105620 - TaKO8Ki:remove-unnecessary-uses-of-clone, r=compiler-errors
Remove unnecessary uses of `clone`
2022-12-13 01:17:10 +01:00
Takayuki Maeda
ee40a67cd9 remove unnecessary uses of clone 2022-12-13 02:06:24 +09: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
KaDiWa
9bc69925cb
compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01: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
Nicholas Nethercote
568e647047 Remove three uses of LitKind::synthesize_token_lit. 2022-12-05 16:33:20 +11:00
Nicholas Nethercote
4ae956f600 Remove ExtCtxt::expr_lit. 2022-12-05 14:20:38 +11:00
Nicholas Nethercote
7d30472180 Remove mk_name_value_item{,_str}.
There are better ways to create the meta items.
- In the rustdoc tests, the commit adds `dummy_meta_item_name_value`,
  which matches the existing `dummy_meta_item_word` function and
  `dummy_meta_item_list` macro.
- In `types.rs` the commit clones the existing meta item and then
  modifies the clone.
2022-12-05 11:24:48 +11:00
Matthias Krüger
3c4a430900
Rollup merge of #105142 - nbdd0121:inline_const, r=petrochenkov
Make inline const block `ExprWithBlock`

Fix https://github.com/rust-lang/rust/pull/104087#issuecomment-1324190817

`@rustbot` label: +T-lang +F-inline_const
2022-12-04 11:38:51 +01:00
Matthias Krüger
1a2f79b82c
Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514
Remove useless borrows and derefs

They are nothing more than noise.
<sub>These are not all of them, but my clippy started crashing (stack overflow), so rip :(</sub>
2022-12-03 17:37:42 +01: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
d5526ff40d Reorder StrLit fields.
To better match `MetaItemLit`.
2022-12-02 13:50:00 +11:00
Nicholas Nethercote
2fd364acff Remove token::Lit from ast::MetaItemLit.
`token::Lit` contains a `kind` field that indicates what kind of literal
it is. `ast::MetaItemLit` currently wraps a `token::Lit` but also has
its own `kind` field. This means that `ast::MetaItemLit` encodes the
literal kind in two different ways.

This commit changes `ast::MetaItemLit` so it no longer wraps
`token::Lit`. It now contains the `symbol` and `suffix` fields from
`token::Lit`, but not the `kind` field, eliminating the redundancy.
2022-12-02 13:49:19 +11:00