about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2022-09-02Refactor and re-use BindingAnnotationCameron Steffen-22/+55
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+3
by module
2022-09-01Auto merge of #100869 - nnethercote:replace-ThinVec, r=spastorinobors-4/+4
Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec` `rustc_data_structures::thin_vec::ThinVec` looks like this: ``` pub struct ThinVec<T>(Option<Box<Vec<T>>>); ``` It's just a zero word if the vector is empty, but requires two allocations if it is non-empty. So it's only usable in cases where the vector is empty most of the time. This commit removes it in favour of `thin_vec::ThinVec`, which is also word-sized, but stores the length and capacity in the same allocation as the elements. It's good in a wider variety of situation, e.g. in enum variants where the vector is usually/always non-empty. The commit also: - Sorts some `Cargo.toml` dependency lists, to make additions easier. - Sorts some `use` item lists, to make additions easier. - Changes `clean_trait_ref_with_bindings` to take a `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this avoid some unnecessary allocations. r? `@spastorino`
2022-08-31Rollup merge of #101165 - ldm0:drain_to_iter, r=cjgillotMatthias Krüger-1/+1
Use more `into_iter` rather than `drain(..)` Clearer semantic.
2022-08-30Use more `into_iter` rather than `drain(..)`Donough Liu-1/+1
2022-08-29Revert let_chains stabilizationNilstrieb-0/+1
This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538.
2022-08-29Inline `attrs`.Nicholas Nethercote-0/+1
2022-08-29Replace `rustc_data_structures::thin_vec::ThinVec` with `thin_vec::ThinVec`.Nicholas Nethercote-4/+3
`rustc_data_structures::thin_vec::ThinVec` looks like this: ``` pub struct ThinVec<T>(Option<Box<Vec<T>>>); ``` It's just a zero word if the vector is empty, but requires two allocations if it is non-empty. So it's only usable in cases where the vector is empty most of the time. This commit removes it in favour of `thin_vec::ThinVec`, which is also word-sized, but stores the length and capacity in the same allocation as the elements. It's good in a wider variety of situation, e.g. in enum variants where the vector is usually/always non-empty. The commit also: - Sorts some `Cargo.toml` dependency lists, to make additions easier. - Sorts some `use` item lists, to make additions easier. - Changes `clean_trait_ref_with_bindings` to take a `ThinVec<TypeBinding>` rather than a `&[TypeBinding]`, because this avoid some unnecessary allocations.
2022-08-29Expand the HIR (and AST) size assertions.Nicholas Nethercote-0/+3
2022-08-26Rollup merge of #100978 - nnethercote:fix-100948, r=petrochenkovYuki Okushi-1/+3
Handle `Err` in `ast::LitKind::to_token_lit`. Fixes #100948. r? ``@petrochenkov``
2022-08-25Handle `Err` in `ast::LitKind::to_token_lit`.Nicholas Nethercote-1/+3
Fixes #100948.
2022-08-25Rollup merge of #99332 - jyn514:stabilize-label-break-value, r=petrochenkovYuki Okushi-1/+1
Stabilize `#![feature(label_break_value)]` See the stabilization report in https://github.com/rust-lang/rust/issues/48594#issuecomment-1186213313.
2022-08-23Stabilize `#![feature(label_break_value)]`Joshua Nelson-1/+1
# Stabilization proposal The feature was implemented in https://github.com/rust-lang/rust/pull/50045 by est31 and has been in nightly since 2018-05-16 (over 4 years now). There are [no open issues][issue-label] other than the tracking issue. There is a strong consensus that `break` is the right keyword and we should not use `return`. There have been several concerns raised about this feature on the tracking issue (other than the one about tests, which has been fixed, and an interaction with try blocks, which has been fixed). 1. nrc's original comment about cost-benefit analysis: https://github.com/rust-lang/rust/issues/48594#issuecomment-422235234 2. joshtriplett's comments about seeing use cases: https://github.com/rust-lang/rust/issues/48594#issuecomment-422281176 3. withoutboats's comments that Rust does not need more control flow constructs: https://github.com/rust-lang/rust/issues/48594#issuecomment-450050630 Many different examples of code that's simpler using this feature have been provided: - A lexer by rpjohnst which must repeat code without label-break-value: https://github.com/rust-lang/rust/issues/48594#issuecomment-422502014 - A snippet by SergioBenitez which avoids using a new function and adding several new return points to a function: https://github.com/rust-lang/rust/issues/48594#issuecomment-427628251. This particular case would also work if `try` blocks were stabilized (at the cost of making the code harder to optimize). - Several examples by JohnBSmith: https://github.com/rust-lang/rust/issues/48594#issuecomment-434651395 - Several examples by Centril: https://github.com/rust-lang/rust/issues/48594#issuecomment-440154733 - An example by petrochenkov where this is used in the compiler itself to avoid duplicating error checking code: https://github.com/rust-lang/rust/issues/48594#issuecomment-443557569 - Amanieu recently provided another example related to complex conditions, where try blocks would not have helped: https://github.com/rust-lang/rust/issues/48594#issuecomment-1184213006 Additionally, petrochenkov notes that this is strictly more powerful than labelled loops due to macros which accidentally exit a loop instead of being consumed by the macro matchers: https://github.com/rust-lang/rust/issues/48594#issuecomment-450246249 nrc later resolved their concern, mostly because of the aforementioned macro problems. joshtriplett suggested that macros could be able to generate IR directly (https://github.com/rust-lang/rust/issues/48594#issuecomment-451685983) but there are no open RFCs, and the design space seems rather speculative. joshtriplett later resolved his concerns, due to a symmetry between this feature and existing labelled break: https://github.com/rust-lang/rust/issues/48594#issuecomment-632960804 withoutboats has regrettably left the language team. joshtriplett later posted that the lang team would consider starting an FCP given a stabilization report: https://github.com/rust-lang/rust/issues/48594#issuecomment-1111269353 [issue-label]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AF-label_break_value+ ## Report + Feature gate: - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/src/test/ui/feature-gates/feature-gate-label_break_value.rs + Diagnostics: - https://github.com/rust-lang/rust/blob/6b2d3d5f3cd1e553d87b5496632132565b6779d3/compiler/rustc_parse/src/parser/diagnostics.rs#L2629 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L749 - https://github.com/rust-lang/rust/blob/f65bf0b2bb1a99f73095c01a118f3c37d3ee614c/compiler/rustc_resolve/src/diagnostics.rs#L1001 - https://github.com/rust-lang/rust/blob/111df9e6eda1d752233482c1309d00d20a4bbf98/compiler/rustc_passes/src/loops.rs#L254 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L2079 - https://github.com/rust-lang/rust/blob/d695a497bbf4b20d2580b75075faa80230d41667/compiler/rustc_parse/src/parser/expr.rs#L1569 + Tests: - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_continue.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_unlabeled_break.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/label/label_break_value_illegal_uses.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/lint/unused_labels.rs - https://github.com/rust-lang/rust/blob/master/src/test/ui/run-pass/for-loop-while/label_break_value.rs ## Interactions with other features Labels follow the hygiene of local variables. label-break-value is permitted within `try` blocks: ```rust let _: Result<(), ()> = try { 'foo: { Err(())?; break 'foo; } }; ``` label-break-value is disallowed within closures, generators, and async blocks: ```rust 'a: { || break 'a //~^ ERROR use of unreachable label `'a` //~| ERROR `break` inside of a closure } ``` label-break-value is disallowed on [_BlockExpression_]; it can only occur as a [_LoopExpression_]: ```rust fn labeled_match() { match false 'b: { //~ ERROR block label not supported here _ => {} } } macro_rules! m { ($b:block) => { 'lab: $b; //~ ERROR cannot use a `block` macro fragment here unsafe $b; //~ ERROR cannot use a `block` macro fragment here |x: u8| -> () $b; //~ ERROR cannot use a `block` macro fragment here } } fn foo() { m!({}); } ``` [_BlockExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/block-expr.html [_LoopExpression_]: https://doc.rust-lang.org/nightly/reference/expressions/loop-expr.html
2022-08-23Rollup merge of #100909 - nnethercote:minor-ast-LitKind-improvement, ↵Dylan DPC-6/+8
r=petrochenkov Minor `ast::LitKind` improvements r? `@petrochenkov`
2022-08-23Remove the symbol from `ast::LitKind::Err`.Nicholas Nethercote-4/+4
Because it's never used meaningfully.
2022-08-23Add some useful comments to `LitKind`.Nicholas Nethercote-2/+4
2022-08-23Rollup merge of #100565 - ↵Matthias Krüger-0/+24
TaKO8Ki:suggest-adding-missing-semicolon-before-item, r=compiler-errors Suggest adding a missing semicolon before an item fixes #100533
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-68/+28
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-20Auto merge of #100564 - nnethercote:box-ast-MacCall, r=spastorinobors-11/+11
Box the `MacCall` in various types. r? `@spastorino`
2022-08-19use <[u8]>::escape_ascii instead of core::ascii::escape_defaultKaDiWa-6/+1
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-08-17Rollup merge of #100018 - nnethercote:clean-up-LitKind, r=petrochenkovMatthias Krüger-18/+12
Clean up `LitKind` r? ``@petrochenkov``
2022-08-17Box the `MacCall` in various types.Nicholas Nethercote-11/+11
2022-08-16Rollup merge of #100610 - nnethercote:ast-and-parser-tweaks, r=spastorinoDylan DPC-3/+6
Ast and parser tweaks r? `@spastorino`
2022-08-16Rename some things related to literals.Nicholas Nethercote-11/+11
- 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-16Add some more AST node size assertions.Nicholas Nethercote-0/+5
There is some redundancy here, but the extra assertions make it easier to keep track of relative things, e.g. `ExprKind` is the biggest part of `Expr`.
2022-08-16Remove `{ast,hir}::WhereEqPredicate::id`.Nicholas Nethercote-3/+1
These fields are unused.
2022-08-16Avoid code duplication in `{MetaItem,MetaItemKind}::value_str`.Nicholas Nethercote-7/+1
The two methods are almost identical.
2022-08-16Shrink `ast::Attribute`.Nicholas Nethercote-25/+42
2022-08-15suggest adding a missing semicolon before an itemTakayuki Maeda-0/+24
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-08-11Rollup merge of #100392 - nnethercote:simplify-visitors, r=cjgillotMatthias Krüger-23/+9
Simplify visitors By removing some unused arguments. r? `@cjgillot`
2022-08-11Rollup merge of #100350 - jhpratt:stringify-vis, r=cjgillotMatthias Krüger-3/+3
Stringify non-shorthand visibility correctly This makes `stringify!(pub(in crate))` evaluate to `pub(in crate)` rather than `pub(crate)`, matching the behavior before the `crate` shorthand was removed. Further, this changes `stringify!(pub(in super))` to evaluate to `pub(in super)` rather than the current `pub(super)`. If the latter is not desired (it is _technically_ breaking), it can be undone. Fixes #99981 `@rustbot` label +C-bug +regression-from-stable-to-beta +T-compiler
2022-08-11Rollup merge of #100391 - nnethercote:improve-size-assertions, r=lqdDylan DPC-17/+20
Improve size assertions r? `@lqd`
2022-08-11Simplify `rustc_ast::visit::Visitor::visit_poly_trait_ref`.Nicholas Nethercote-8/+5
It is passed an argument that is never used.
2022-08-11Simplify `rustc_ast::visit::Visitor::visit_enum_def`.Nicholas Nethercote-15/+4
It's passed three arguments that are never used.
2022-08-10Do not consider method call receiver as an argument in AST.Camille GILLOT-10/+11
2022-08-09Stringify non-shorthand visibility correctlyJacob Pratt-3/+3
2022-08-10Add a couple more AST node size assertions.Nicholas Nethercote-0/+2
2022-08-10Avoid repeating qualifiers on `static_assert_size` calls.Nicholas Nethercote-17/+18
Some of these don't need a `use` statement because there is already a `#[macro_use] extern crate rustc_data_structures` item in the crate.
2022-08-04Move LifetimeCollectVisitor to rustc_ast_loweringSantiago Pastorino-59/+0
2022-08-04Explicitly gather lifetimes and definitions in RPITSantiago Pastorino-1/+60
2022-08-01Auto merge of #100024 - matthiaskrgr:rollup-36ab4wx, r=matthiaskrgrbors-13/+24
Rollup of 8 pull requests Successful merges: - #99340 (Fix ICE in Definitions::create_def) - #99629 (Improve `cannot move out of` error message) - #99864 (bootstrap: don't emit warn about duplicated deps with same/different features if some of sets actually empty) - #99911 (Remove some uses of `guess_head_span`) - #99976 (Make Rustdoc exit with correct error code when scraping examples from invalid files) - #100003 (Improve size assertions.) - #100012 (Avoid `Ty` to `String` conversions) - #100020 (better error when python is not found in x - issue #99648) Failed merges: - #99994 (Replace `guess_head_span` with `opt_span`) r? `@ghost` `@rustbot` modify labels: rollup
2022-08-01Improve size assertions.Nicholas Nethercote-13/+24
- For any file with four or more size assertions, move them into a separate module (as is already done for `hir.rs`). - Add some more for AST nodes and THIR nodes. - Put the `hir.rs` ones in alphabetical order.
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-07-30Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkovbors-115/+112
Remove `TreeAndSpacing`. A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`. r? `@petrochenkov`
2022-07-29Remove `TreeAndSpacing`.Nicholas Nethercote-115/+112
A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`.
2022-07-29Remove `visit_name` from the AST visitor.Nicholas Nethercote-16/+3
Because the default is empty and it's never overridden. This means `walk_ident` can also be removed, because it does nothing.
2022-07-16Stabilize `let_chains`Caio-1/+1
2022-07-12Add back expr size checksMaybe Waffle-2/+2