summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2022-12-04Rollup merge of #105142 - nbdd0121:inline_const, r=petrochenkovMatthias Krüger-0/+1
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-03Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514Matthias Krüger-19/+18
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-03Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillotMatthias Krüger-1/+5
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-01Make inline const block `ExprWithBlock`Gary Guo-0/+1
2022-12-01Remove useless borrows and derefsMaybe Waffle-19/+18
2022-12-01rustc_ast_lowering: Stop lowering imports into multiple itemsVadim Petrochenkov-12/+5
Lower them into a single item with multiple resolutions instead. This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-11-29Avoid more `MetaItem`-to-`Attribute` conversions.Nicholas Nethercote-124/+52
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-9/+2
It has a single call site.
2022-11-29Reorder some types.Nicholas Nethercote-27/+27
So that `Attribute` and `MetaItem` are listed first, and then the component types are below them in a logical order.
2022-11-29Improve comments about attributes and meta items.Nicholas Nethercote-10/+14
I have found the distinction confusing.
2022-11-28Keep track of the start of the argument block of a closureSarthak Singh-1/+5
2022-11-28Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote-8/+8
We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
2022-11-28Adjust comments on `StrLit`.Nicholas Nethercote-2/+1
2022-11-28Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote-31/+32
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-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-31/+33
2022-11-26Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errorsGuillaume Gomez-2/+30
Use the power of adding helper function to simplify code w/ `Mutability` r? `@compiler-errors`
2022-11-23Add `Mutability::mutably_str`Maybe Waffle-0/+8
2022-11-23Don't accept `Mutability` by refMaybe Waffle-2/+2
2022-11-23Add `Mutability::{is_mut,is_not}`Maybe Waffle-0/+10
2022-11-23Suggest `.clone()` or `ref binding` on E0382Esteban Küber-3/+4
2022-11-23Add `Mutability::ref_prefix_str`, order `Mutability`, simplify codeMaybe Waffle-1/+11
2022-11-23Fix an ICE parsing a malformed attribute.Nicholas Nethercote-3/+6
Fixes #104620.
2022-11-22Auto merge of #103578 - petrochenkov:nofict, r=nagisabors-1/+1
Unreserve braced enum variants in value namespace With this PR braced enum variants (`enum E { V { /*...*/ } }`) no longer take a slot in value namespace, so the special case mentioned in the note in https://github.com/rust-lang/rfcs/blob/master/text/1506-adt-kinds.md#braced-structs is removed. Report - https://github.com/rust-lang/rust/pull/103578#issuecomment-1292594900.
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-90/+107
`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-21Unreserve braced enum variants in value namespaceVadim Petrochenkov-1/+1
2022-11-21Remove `ref` patterns from `rustc_ast`Maybe Waffle-224/+214
Also use if let chains in one case.
2022-11-17Use `ThinVec` in `ast::Path`.Nicholas Nethercote-16/+15
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-43/+82
patterns.
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-48/+65
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-15Rollup merge of #104391 - nnethercote:deriving-cleanups, r=jackh726Matthias Krüger-9/+7
Deriving cleanups Fixing some minor problems `@RalfJung` found in #99046. r? `@RalfJung`
2022-11-14Remove TraitDef::generics.Nicholas Nethercote-9/+7
Because it's always empty.
2022-11-14Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbinibors-1/+1
Bump bootstrap compiler to 1.66 This PR: - Bumps version placeholders to release - Bumps to latest beta - cfg-steps code r? `@pietroalbini`
2022-11-11Introduce `ExprKind::IncludedBytes`clubby789-3/+17
2022-11-11Auto merge of #99918 - WaffleLapkin:fnFnfun, r=estebankbors-0/+17
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-06cfg-step codeMark Rousskov-1/+1
2022-11-05Remove `unescape_byte_literal`.Nicholas Nethercote-18/+11
It's easy to just use `unescape_literal` + `byte_from_char`.
2022-10-26remove unused parser fnMichael Goulet-18/+0
2022-10-23Workaround unstable stmt_expr_attributes for method receiver expressions.Camille GILLOT-1/+18
2022-10-18Fix `TyKind::is_simple_path`.Nicholas Nethercote-2/+5
PR #98758 introduced code to avoid redundant assertions in derived code like this: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` But the predicate `is_simple_path` introduced as part of this failed to account for generic arguments. Therefore the deriving code erroneously considers types like `Option<bool>` and `Option<f32>` to be the same. This commit fixes `is_simple_path`. Fixes #103157.
2022-10-12Use `tidy-alphabetical` in the compilerNilstrieb-4/+7
2022-10-12Auto merge of #102692 - nnethercote:TokenStreamBuilder, r=Aaron1011bors-72/+45
Remove `TokenStreamBuilder` `TokenStreamBuilder` is used to combine multiple token streams. It can be removed, leaving the code a little simpler and a little faster. r? `@Aaron1011`
2022-10-10Rollup merge of #102868 - compiler-errors:rename-assoc-tyalias-to-ty, r=TaKO8KiDylan DPC-6/+6
Rename `AssocItemKind::TyAlias` to `AssocItemKind::Type` Thanks `@camsteffen` for catching this in ast too, cc https://github.com/rust-lang/rust/pull/102829#issuecomment-1272649247
2022-10-10Rename AssocItemKind::TyAlias to AssocItemKind::TypeMichael Goulet-6/+6
2022-10-09fixup lint nameMaybe Waffle-1/+1
2022-10-09allow or avoid for loops over option in compiler and testsMaybe Waffle-8/+6
2022-10-05Remove `TokenStreamBuilder`.Nicholas Nethercote-72/+45
`TokenStreamBuilder` exists to concatenate multiple `TokenStream`s together. This commit removes it, and moves the concatenation functionality directly into `TokenStream`, via two new methods `push_tree` and `push_stream`. This makes things both simpler and faster. `push_tree` is particularly important. `TokenStreamBuilder` only had a single `push` method, which pushed a stream. But in practice most of the time we push a single token tree rather than a stream, and `push_tree` avoids the need to build a token stream with a single entry (which requires two allocations, one for the `Lrc` and one for the `Vec`). The main `push_tree` use arises from a change to one of the `ToInternal` impls in `proc_macro_server.rs`. It now returns a `SmallVec` instead of a `TokenStream`. This return value is then iterated over by `concat_trees`, which does `push_tree` on each element. Furthermore, the use of `SmallVec` avoids more allocations, because there is always only one or two token trees. Note: the removed `TokenStreamBuilder::push` method had some code to deal with a quadratic blowup case from #57735. This commit removes the code. I tried and failed to reproduce the blowup from that PR, before and after this change. Various other changes have happened to `TokenStreamBuilder` in the meantime, so I suspect the original problem is no longer relevant, though I don't have proof of this. Generally speaking, repeatedly extending a `Vec` without pre-determining its capacity is *not* quadratic. It's also incredibly common, within rustc and many other Rust programs, so if there were performance problems there you'd think it would show up in other places, too.
2022-10-03Rewrite `Token::is_op`.Nicholas Nethercote-11/+8
An exhaustive match is more readable and more future-proof.
2022-10-03Add comments to `Spacing`.Nicholas Nethercote-0/+11
2022-10-01Replace some `bool` params with an enumMaybe Waffle-3/+11