Commit Graph

818 Commits

Author SHA1 Message Date
Nicholas Nethercote d84d8d2604 Rework ast::BinOpKind::to_string and ast::UnOp::to_string.
- Rename them both `as_str`, which is the typical name for a function
  that returns a `&str`. (`to_string` is appropriate for functions
  returning `String` or maybe `Cow<'a, str>`.)
- Change `UnOp::as_str` from an associated function (weird!) to a
  method.
- Avoid needless `self` dereferences.
2023-11-28 09:42:07 +11:00
Dinu Blanovschi 494560cb57 fixes for rustfmt + ast visitor 2023-11-04 20:39:15 +01:00
Oli Scherer a3be235fcc Add gen blocks to ast and do some broken ast lowering 2023-10-27 13:05:48 +00:00
Caleb Cartwright 04bd7201a9 Merge commit '81fe905ca83cffe84322f27ca43950b617861ff7' into rustfmt-sync 2023-10-22 20:21:44 -05:00
Matthew Jasper e0d90ccd45 Update tools and fulldeps tests 2023-09-11 15:51:19 +00:00
Nilstrieb aca22c73fd 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
Nicholas Nethercote 14101ed5a5 Remove MacDelimiter.
It's the same as `Delimiter`, minus the `Invisible` variant. I'm
generally in favour of using types to make impossible states
unrepresentable, but this one feels very low-value, and the conversions
between the two types are annoying and confusing.

Look at the change in `src/tools/rustfmt/src/expr.rs` for an example:
the old code converted from `MacDelimiter` to `Delimiter` and back
again, for no good reason. This suggests the author was confused about
the types.
2023-08-03 09:03:30 +10:00
Caleb Cartwright 78331eefaf Merge commit 'dca1cf90ad6b8e45afbed2061803befbb2d159e9' into sync-rustfmt 2023-07-01 02:49:12 -05:00
Nilstrieb 80bf3ea542 Rollup merge of #112790 - WaffleLapkin:syntactically, r=Nilstrieb
Syntactically accept `become` expressions (explicit tail calls experiment)

This adds `ast::ExprKind::Become`, implements parsing and properly gates the feature.

cc `@scottmcm`
2023-06-21 07:37:02 +02:00
Caleb Cartwright ed3e96e3d1 Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-sync 2023-06-19 23:13:56 -05:00
Maybe Waffle dc7dc3e74c Implement become expression formatting in rustfmt 2023-06-19 12:54:34 +00:00
Michael Goulet 6b9c151686 Tweak await span 2023-04-27 17:18:11 +00:00
DrMeepster f4c9b4c26f rustfmt fmt 2023-04-21 08:59:30 -07:00
DrMeepster ecfdec44df minor tweaks 2023-04-21 02:14:04 -07:00
DrMeepster 84385bff42 offset_of 2023-04-21 02:14:02 -07:00
Arpad Borsos 3ef194c14c Remove the NodeId of ast::ExprKind::Async 2023-03-19 19:01:31 +01:00
clubby789 4e658cc01e Remove box_syntax from AST and use in tools 2023-03-12 13:19:46 +00:00
bors 6d133152f8 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
Caleb Cartwright 094b7f599c Merge commit '1d8491b120223272b13451fc81265aa64f7f4d5b' into sync-from-rustfmt 2023-01-24 14:16:03 -06:00
Deadbeef 19c2286d5c parse const closures 2023-01-12 02:28:37 +00:00
Mara Bos 80d196d789 Update rustfmt for ast::ExprKind::FormatArgs.
Rustfmt doesn't expand macros, so that's easy: FormatArgs nodes do not
occur in the unexpanded AST.
2023-01-12 00:25:46 +01:00
Esteban Küber 3d44530eb0 Fix rustfmt 2022-11-23 12:17:47 -08:00
Nicholas Nethercote 1343ffd564 Split MacArgs in two.
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's
used in two ways:
- For representing attribute macro arguments (e.g. in `AttrItem`), where all
  three variants are used.
- For representing function-like macros (e.g. in `MacCall` and `MacroDef`),
  where only the `Delimited` variant is used.

In other words, `MacArgs` is used in two quite different places due to them
having partial overlap. I find this makes the code hard to read. It also leads
to various unreachable code paths, and allows invalid values (such as
accidentally using `MacArgs::Empty` in a `MacCall`).

This commit splits `MacArgs` in two:
- `DelimArgs` is a new struct just for the "delimited arguments" case. It is
  now used in `MacCall` and `MacroDef`.
- `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro
  case. Its `Delimited` variant now contains a `DelimArgs`.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and
disallows the invalid values.
2022-11-22 09:04:15 +11:00
Nicholas Nethercote 4a4addc598 Box ExprKind::{Closure,MethodCall}, and QSelf in expressions, types, and patterns. 2022-11-17 13:45:59 +11:00
Nicholas Nethercote 826fb78beb Use token::Lit in ast::ExprKind::Lit.
Instead of `ast::Lit`.

Literal lowering now happens at two different times. Expression literals
are lowered when HIR is crated. Attribute literals are lowered during
parsing.

This commit changes the language very slightly. Some programs that used
to not compile now will compile. This is because some invalid literals
that are removed by `cfg` or attribute macros will no longer trigger
errors. See this comment for more details:
https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-11-16 09:41:28 +11:00
clubby789 660e53512f Introduce ExprKind::IncludedBytes 2022-11-11 16:31:32 +00:00
Nicholas Nethercote e5b5f56d43 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
Maybe Waffle 2964d0a533 implement rustfmt formatting for for<> closure binders 2022-07-12 21:00:13 +04:00
Caleb Cartwright ac595dd57a Merge commit 'c4416f20dcaec5d93077f72470e83e150fb923b1' into sync-rustfmt 2022-06-22 22:14:32 -05:00
Caleb Cartwright d03a547cad Merge commit '7b73b60faca71d01d900e49831fcb84553e93019' into sync-rustfmt 2022-06-12 22:03:05 -05:00
Scott McMurray 050978ba43 Fix the rustfmt build 2022-04-30 17:40:29 -07:00
Vadim Petrochenkov 70067e31ed rustc_ast: Harmonize delimiter naming with proc_macro::Delimiter 2022-04-28 10:04:29 +03:00
Nicholas Nethercote e08df2dd6b Avoid producing NoDelim values in MacArgs::delim(). 2022-04-27 08:15:12 +10:00
Mark Rousskov de1ac375f0 Enable rustc_pass_by_value for Span 2022-02-25 08:00:53 -05:00
Tomasz Miąsko 04670a1404 Remove LLVM-style inline assembly from rustfmt 2022-01-12 21:43:35 +01:00
Caleb Cartwright 6db6bafc61 Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into sync-rustfmt-subtree 2021-12-29 20:49:39 -06:00
Caleb Cartwright 0167c5303f Merge commit '8da837185714cefbb261e93e9846afb11c1dc60e' into sync-rustfmt-subtree 2021-12-02 21:35:30 -06:00
Caleb Cartwright f99e3582bd Merge commit 'ea199bacef07213dbe008841b89c450e3bf0c638' into rustfmt-sync 2021-11-07 20:37:34 -06:00
Caleb Cartwright 2b41b6d022 Merge commit 'efa8f5521d3813cc897ba29ea0ef98c7aef66bb6' into rustfmt-subtree 2021-10-20 00:11:59 -05:00
Caio 64bf8dfa33 Introduce hir::ExprKind::Let - Take 2 2021-08-15 16:18:26 -03:00
Caleb Cartwright e4b8714c09 Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-rustfmt 2021-07-25 22:57:19 -05:00
Ryan Levick 58c63cf8de Add support for using qualified paths with structs in expression and pattern
position.
2021-06-10 13:18:41 +02:00
Caleb Cartwright 1bcc1f8df5 refactor: apply heuristic config changes in lib 2021-04-21 21:27:50 -05:00
Caleb Cartwright c32f2ec015 chore: fmt and cleanup 2021-04-02 23:21:06 -05:00
Caleb Cartwright 4948911608 deps: apply rustc-ap-* v712 changes 2021-04-02 23:21:06 -05:00
David Bar-On 432e09e89f Add the use of rewrite_assign_rhs_with_comments to 1.x 2021-02-17 20:47:20 -06:00
Caleb Cartwright b8f318c303 fix: don't insert trailing comma on struct lit rest in mac def 2021-01-28 22:01:50 -06:00
Caleb Cartwright c13d2452c0 chore: backport some empty block check fixes 2021-01-27 20:58:42 -06:00
Caleb Cartwright bd4dc36c4e refactor: cleanup block check for statements 2021-01-27 20:58:42 -06:00
Caleb Cartwright 48d30a4f71 chore: run rustfmt against source 2020-11-28 17:41:21 -06:00