about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/util
AgeCommit message (Collapse)AuthorLines
2022-12-02Remove `token::Lit` from `ast::MetaItemLit`.Nicholas Nethercote-2/+25
`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-02Add `StrStyle` to `ast::LitKind::ByteStr`.Nicholas Nethercote-5/+11
This is required to distinguish between cooked and raw byte string literals in an `ast::LitKind`, without referring to an adjacent `token::Lit`. It's a prerequisite for the next commit.
2022-12-02Rename `LitKind::to_token_lit` as `LitKind::synthesize_token_lit`.Nicholas Nethercote-2/+2
This makes it clearer that it's not a lossless conversion, which I find helpful.
2022-12-01Make inline const block `ExprWithBlock`Gary Guo-0/+1
2022-12-01Remove useless borrows and derefsMaybe Waffle-11/+11
2022-11-29Avoid more `MetaItem`-to-`Attribute` conversions.Nicholas Nethercote-9/+0
There is code for converting `Attribute` (syntactic) to `MetaItem` (semantic). There is also code for the reverse direction. The reverse direction isn't really necessary; it's currently only used when generating attributes, e.g. in `derive` code. This commit adds some new functions for creating `Attributes`s directly, without involving `MetaItem`s: `mk_attr_word`, `mk_attr_name_value_str`, `mk_attr_nested_word`, and `ExtCtxt::attr_{word,name_value_str,nested_word}`. These new methods replace the old functions for creating `Attribute`s: `mk_attr_inner`, `mk_attr_outer`, and `ExtCtxt::attribute`. Those functions took `MetaItem`s as input, and relied on many other functions that created `MetaItems`, which are also removed: `mk_name_value_item`, `mk_list_item`, `mk_word_item`, `mk_nested_word_item`, `{MetaItem,MetaItemKind,NestedMetaItem}::token_trees`, `MetaItemKind::attr_args`, `MetaItemLit::{from_lit_kind,to_token}`, `ExtCtxt::meta_word`. Overall this cuts more than 100 lines of code and makes thing simpler.
2022-11-29Inline and remove `MetaItemLit::from_lit_kind`.Nicholas Nethercote-7/+0
It has a single call site.
2022-11-28Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote-12/+12
2022-11-28Remove `Lit::from_included_bytes`.Nicholas Nethercote-8/+0
`Lit::from_included_bytes` calls `Lit::from_lit_kind`, but the two call sites only need the resulting `token::Lit`, not the full `ast::Lit`. This commit changes those call sites to use `LitKind::to_token_lit`, which means `from_included_bytes` can be removed.
2022-11-21Remove `ref` patterns from `rustc_ast`Maybe Waffle-11/+11
Also use if let chains in one case.
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-2/+4
patterns.
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-22/+5
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-11Introduce `ExprKind::IncludedBytes`clubby789-0/+8
2022-11-11Auto merge of #99918 - WaffleLapkin:fnFnfun, r=estebankbors-0/+6
Recover wrong-cased keywords that start items (_this pr was inspired by [this tweet](https://twitter.com/Azumanga/status/1552982326409367561)_) r? `@estebank` We've talked a bit about this recovery, but I just wanted to make sure that this is the right approach :) For now I've only added the case insensitive recovery to `use`s, since most other items like `impl` blocks, modules, functions can start with multiple keywords which complicates the matter.
2022-11-05Remove `unescape_byte_literal`.Nicholas Nethercote-18/+11
It's easy to just use `unescape_literal` + `byte_from_char`.
2022-10-01Replace some `bool` params with an enumMaybe Waffle-0/+6
2022-09-16more simple formattingRageking8-34/+34
2022-09-12Rollup merge of #100767 - kadiwa4:escape_ascii, r=jackh726Dylan DPC-6/+1
Remove manual <[u8]>::escape_ascii `@rustbot` label: +C-cleanup
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-25Handle `Err` in `ast::LitKind::to_token_lit`.Nicholas Nethercote-1/+3
Fixes #100948.
2022-08-23Remove the symbol from `ast::LitKind::Err`.Nicholas Nethercote-2/+2
Because it's never used meaningfully.
2022-08-19use <[u8]>::escape_ascii instead of core::ascii::escape_defaultKaDiWa-6/+1
2022-08-16Rename some things related to literals.Nicholas Nethercote-9/+9
- 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-10Do not consider method call receiver as an argument in AST.Camille GILLOT-2/+2
2022-08-01Shrink `Token`.Nicholas Nethercote-4/+6
From 72 bytes to 12 bytes (on x86-64). There are two parts to this: - Changing various source code offsets from 64-bit to 32-bit. This is not a problem because the rest of rustc also uses 32-bit source code offsets. This means `Token` is no longer `Copy` but this causes no problems. - Removing the `RawStrError` from `LiteralKind`. Raw string literal invalidity is now indicated by a `None` value within `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be used to re-lex an invalid raw string literal to get the `RawStrError`. There is one very small change in behaviour. Previously, if a raw string literal matched both the `InvalidStarter` and `TooManyHashes` cases, the latter would override the former. This has now changed, because `raw_double_quoted_string` now uses `?` and so returns immediately upon detecting the `InvalidStarter` case. I think this is a slight improvement to report the earlier-detected error, and it explains the change in the `test_too_many_hashes` test. The commit also removes a couple of comments that refer to #77629 and say that the size of these types don't affect performance. These comments are wrong, though the performance effect is small.
2022-04-30Add `do yeet` expressions to allow experimentation in nightlyScott McMurray-1/+3
Using an obviously-placeholder syntax. An RFC would still be needed before this could have any chance at stabilization, and it might be removed at any point. But I'd really like to have it in nightly at least to ensure it works well with try_trait_v2, especially as we refactor the traits.
2022-04-19rustc_metadata: Store a flag telling whether an item may have doc links in ↵Vadim Petrochenkov-0/+8
its attributes This should be cheap on rustc side, but it's significant optimization for rustdoc that won't need to decode and process attributes unnecessarily
2022-04-08Fix invalid array access in `beautify_doc_string`Guillaume Gomez-1/+4
2022-03-09Implement macro meta-variable expressionsCaio-1/+1
2022-02-262 - Make more use of let_chainsCaio-4/+4
Continuation of #94376. cc #53667
2022-02-24Inline a hot closure in `from_lit_token`.Nicholas Nethercote-17/+22
The change looks big because `rustfmt` rearranges things, but the only real change is the inlining annotation.
2022-02-07Add test for block doc comments horizontal trimGuillaume Gomez-14/+6
2022-02-07Fix horizontal trim for block doc commentsGuillaume Gomez-6/+38
2022-01-19Correctly handle starts in block doc commentsGuillaume Gomez-11/+32
2021-12-28Fix invalid removal of backlines from doc commentsGuillaume Gomez-7/+0
2021-12-15Remove unnecessary sigils around `Symbol::as_str()` calls.Nicholas Nethercote-2/+2
2021-12-09Remove redundant [..]sest31-1/+1
2021-11-10Rollup merge of #90742 - est31:add_assign, r=davidtwcoMatthias Krüger-1/+1
Use AddAssign impl
2021-11-09Use AddAssign implest31-1/+1
2021-11-08Rollup merge of #90657 - GuillaumeGomez:one-char-last-line-removed, r=jyn514Guillaume Gomez-1/+1
Fix bug with `#[doc]` string single-character last lines Fixes #90618. This is because `.iter().all(|c| c == '*')` returns `true` if there is no character checked. And in case the last line has only one character, it simply returns `true`, making the last line behind removed.
2021-11-06Rollup merge of #90642 - matthiaskrgr:clippy_matches, r=cjgillotMatthias Krüger-4/+4
use matches!() macro in more places
2021-11-06Fix last doc code comment being removed if it only had one characterGuillaume Gomez-1/+1
2021-11-06use matches!() macro in more placesMatthias Krüger-4/+4
2021-11-05Use one match instead of a staggered match.Hans Kratz-11/+2
2021-11-04Optimize literal, doc comment lint as well, extract function.Hans Kratz-0/+44
2021-10-17Some "parenthesis" and "parentheses" fixesr00ster91-2/+2
2021-08-30Handle let-else initializer edge case errorsCameron Steffen-0/+27
2021-07-30Add warning when whitespace is not skipped after an escaped newline.Anton Golov-4/+20
2021-07-08Rework SESSION_GLOBALS API to prevent overwriting itGuillaume Gomez-5/+5
2021-01-16Remove unnecessary manual shrink_to_fit callsDániel Buga-3/+0