about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2024-05-07compiler: add `Parser::debug_lookahead`Jubilee Young-0/+42
I tried debugging a parser-related issue but found it annoying to not be able to easily peek into the Parser's token stream. Add a convenience fn that offers an opinionated view into the parser, but one that is useful for answering basic questions about parser state.
2024-05-07compiler: derive Debug in parserJubilee Young-8/+11
It's annoying to debug the parser if you have to stop every five seconds to add a Debug impl.
2024-05-07narrow down visibilities in `rustc_parse::lexer`Lin Yihai-6/+6
2024-05-05compiler: Privatize `Parser::current_closure`Jubilee Young-1/+1
This was added as pub in 2021 and remains only privately used in 2024!
2024-05-06Move some tests from `rustc_expand` to `rustc_parse`.Nicholas Nethercote-0/+1619
There are some test cases involving `parse` and `tokenstream` and `mut_visit` that are located in `rustc_expand`. Because it used to be the case that constructing a `ParseSess` required the involvement of `rustc_expand`. However, since #64197 merged (a long time ago) `rust_expand` no longer needs to be involved. This commit moves the tests into `rustc_parse`. This is the optimal place for the `parse` tests. It's not ideal for the `tokenstream` and `mut_visit` tests -- they would be better in `rustc_ast` -- but they still rely on parsing, which is not available in `rustc_ast`. But `rustc_parse` is lower down in the crate graph and closer to `rustc_ast` than `rust_expand`, so it's still an improvement for them. The exact renaming is as follows: - rustc_expand/src/mut_visit/tests.rs -> rustc_parse/src/parser/mut_visit/tests.rs - rustc_expand/src/tokenstream/tests.rs -> rustc_parse/src/parser/tokenstream/tests.rs - rustc_expand/src/tests.rs + rustc_expand/src/parse/tests.rs -> compiler/rustc_parse/src/parser/tests.rs The latter two test files are combined because there's no need for them to be separate, and having a `rustc_parse::parser::parse` module would be weird. This also means some `pub(crate)`s can be removed.
2024-04-29Add StaticForeignItem and use it on ForeignItemKindSantiago Pastorino-1/+5
2024-04-24Auto merge of #104087 - nbdd0121:const, r=scottmcmbors-2/+0
Stabilise inline_const # Stabilisation Report ## Summary This PR will stabilise `inline_const` feature in expression position. `inline_const_pat` is still unstable and will *not* be stabilised. The feature will allow code like this: ```rust foo(const { 1 + 1 }) ``` which is roughly desugared into ```rust struct Foo; impl Foo { const FOO: i32 = 1 + 1; } foo(Foo::FOO) ``` This feature is from https://github.com/rust-lang/rfcs/pull/2920 and is tracked in #76001 (the tracking issue should *not* be closed as it needs to track inline const in pattern position). The initial implementation is done in #77124. ## Difference from RFC There are two major differences (enhancements) as implemented from the RFC. First thing is that the RFC says that the type of an inline const block inferred from the content *within* it, but we currently can infer the type using the information from outside the const block as well. This is a frequently requested feature to the initial implementation (e.g. #89964). The inference is implemented in #89561 and is done by treating inline const similar to a closure and therefore share inference context with its parent body. This allows code like: ```rust let v: Vec<i32> = const { Vec::new() }; ``` Another enhancement that differs from the RFC is that we currently allow inline consts to reference generic parameters. This is implemented in #96557. This allows code like: ```rust fn create_none_array<T, const N: usize>() -> [Option<T>; N] { [const { None::<T> }; N] } ``` This enhancement also makes inline const usable as static asserts: ```rust fn require_zst<T>() { const { assert!(std::mem::size_of::<T>() == 0) } } ``` ## Documentation Reference: rust-lang/reference#1295 ## Unresolved issues We still have a few issues that are not resolved, but I don't think it necessarily has to block stabilisation: * expr fragment specifier issue: #86730 * ~~`const {}` behaves similar to `async {}` but not to `{}` and `unsafe {}` (they are treated as `ExpressionWithoutBlock` rather than `ExpressionWithBlock`): https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/const.20blocks.20differ.20from.20normal.20and.20from.20unsafe.20blocks/near/290229453~~ ## Tests There are a few tests in https://github.com/rust-lang/rust/tree/master/src/test/ui/inline-const
2024-04-24Stabilise `inline_const`Gary Guo-2/+0
2024-04-24Auto merge of #122500 - petrochenkov:deleg, r=fmeasebors-5/+5
delegation: Support renaming, and async, const, extern "ABI" and C-variadic functions Also allow delegating to functions with opaque types (`impl Trait`). The delegation item will refer to the original opaque type from the callee, fresh opaque type won't be created, which seems like a reasonable behavior. (Such delegation items will cause query cycles when used in trait impls, but it can be fixed later.) Part of https://github.com/rust-lang/rust/issues/118212.
2024-04-23delegation: Support renamingVadim Petrochenkov-5/+5
2024-04-23Auto merge of #124302 - matthiaskrgr:rollup-2aya8n8, r=matthiaskrgrbors-0/+1
Rollup of 3 pull requests Successful merges: - #124003 (Dellvmize some intrinsics (use `u32` instead of `Self` in some integer intrinsics)) - #124169 (Don't fatal when calling `expect_one_of` when recovering arg in `parse_seq`) - #124286 (Subtree sync for rustc_codegen_cranelift) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-23Rollup merge of #124169 - compiler-errors:parser-fatal, r=oli-obkMatthias Krüger-0/+1
Don't fatal when calling `expect_one_of` when recovering arg in `parse_seq` In `parse_seq`, when parsing a sequence of token-separated items, if we don't see a separator, we try to parse another item eagerly in order to give a good diagnostic and recover from a missing separator: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/mod.rs#L900-L901 If parsing the item itself calls `expect_one_of`, then we will fatal because of #58903: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/mod.rs#L513-L516 For `precise_capturing` feature I implemented, we do end up calling `expected_one_of`: https://github.com/rust-lang/rust/blob/d1a0fa5ed3ffe52d72f761d3c95cbeb0a9cdfe66/compiler/rustc_parse/src/parser/ty.rs#L712-L714 This leads the compiler to fatal *before* having emitted the first error, leading to absolutely no useful information for the user about what happened in the parser. This PR makes it so that we stop doing that. Fixes #124195
2024-04-23Rollup merge of #124218 - Xiretza:subsubdiagnostics, r=davidtwcoLeón Orell Valerian Liehr-1/+1
Allow nesting subdiagnostics in #[derive(Subdiagnostic)]
2024-04-23Rollup merge of #124284 - klensy:no-reads, r=fmeaseMatthias Krüger-4/+0
parser: remove unused(no reads) max_angle_bracket_count field Isn't there (clippy) lint for variables with only writes? They should be marked as dead too, probably. Found only https://rust-lang.github.io/rust-clippy/master/index.html#/collection_is_never_read
2024-04-23Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, r=davidtwcoMatthias Krüger-13/+30
Disallow ambiguous attributes on expressions This implements the suggestion in [#15701](https://github.com/rust-lang/rust/issues/15701#issuecomment-2033124217) to disallow ambiguous outer attributes on expressions. This should resolve one of the concerns blocking the stabilization of `stmt_expr_attributes`.
2024-04-23parser: remove ununsed(no reads) max_angle_bracket_count fieldklensy-4/+0
2024-04-22Improve handling of expr->field errorsSasha Pourcelot-0/+19
The current message for "`->` used for field access" is the following: ```rust error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `->` --> src/main.rs:2:6 | 2 | a->b; | ^^ expected one of 8 possible tokens ``` (playground link[1]) This PR tries to address this by adding a dedicated error message and recovery. The proposed error message is: ``` error: `->` used for field access or method call --> ./tiny_test.rs:2:6 | 2 | a->b; | ^^ help: try using `.` instead | = help: the `.` operator will dereference the value if needed ``` (feel free to bikeshed it as much as necessary) [1]: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7f8b6f4433aa7866124123575456f54e Signed-off-by: Sasha Pourcelot <sasha.pourcelot@protonmail.com>
2024-04-21Pass translation closure to add_to_diag_with() as referenceXiretza-1/+1
2024-04-19Don't fatal when calling expect_one_of when recovering arg in parse_seqMichael Goulet-0/+1
2024-04-18Rollup merge of #123752 - estebank:emoji-prefix, r=wesleywiserJubilee-1/+4
Properly handle emojis as literal prefix in macros Do not accept the following ```rust macro_rules! lexes {($($_:tt)*) => {}} lexes!(🐛"foo"); ``` Before, invalid emoji identifiers were gated during parsing instead of lexing in all cases, but this didn't account for macro pre-expansion of literal prefixes. Fix #123696.
2024-04-18Disallow ambiguous attributes on expressionsDominik Stolz-13/+30
2024-04-18Auto merge of #124008 - nnethercote:simpler-static_assert_size, r=Nilstriebbors-3/+3
Simplify `static_assert_size`s. We want to run them on all 64-bit platforms. r? `@ghost`
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-3/+3
We want to run them on all 64-bit platforms.
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-18/+16
2024-04-17Rollup merge of #124051 - dtolnay:emptyset, r=compiler-errorsMatthias Krüger-1/+1
Fix empty-set symbol in comments The symbol in the original code is U+00D8 "LATIN CAPITAL LETTER O WITH STROKE" (https://en.wikipedia.org/wiki/%C3%98) which is an uppercase letter in Danish, Norwegian, Faroese, and Southern Sámi alphabets. The symbol that was intended is U+2205 "EMPTY SET" (https://en.wikipedia.org/wiki/Empty_set#Notation). | Before | After | |---|---| | ![Screenshot from 2024-04-16 18-25-01](https://github.com/rust-lang/rust/assets/1940490/9b8b0624-cfa5-4b89-84e5-4c2b39c2cb8f) | ![Screenshot from 2024-04-16 18-25-05](https://github.com/rust-lang/rust/assets/1940490/6f6b34c3-0e47-4ba0-856d-be1dc164c94c) |
2024-04-17Rollup merge of #122813 - nnethercote:nicer-quals, r=compiler-errorsMatthias Krüger-5/+2
Qualifier tweaking Adding and removing qualifiers in some cases that make things nicer. Details in individual commits. r? `@compiler-errors`
2024-04-16Fix empty-set symbol in commentsDavid Tolnay-1/+1
2024-04-16Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obkbors-8/+51
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`) Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587. We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list. We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future. We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future. r? `@oli-obk` Tracking issue: - https://github.com/rust-lang/rust/issues/123432
2024-04-16Avoid unnecessary `rustc_span::DUMMY_SP` usage.Nicholas Nethercote-5/+2
In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once.
2024-04-16Rollup merge of #123462 - fmease:rn-mod-sep-to-path-sep, r=nnethercoteLeón Orell Valerian Liehr-26/+26
Cleanup: Rename `ModSep` to `PathSep` `::` is usually referred to as the *path separator* (citation needed). The existing name `ModSep` for *module separator* is a bit misleading since it in fact separates the segments of arbitrary path segments, not only ones resolving to modules. Let me just give a shout-out to associated items (`T::Assoc`, `<Ty as Trait>::function`) and enum variants (`Option::None`). Motivation: Reduce friction for new contributors, prevent potential confusion. cc `@petrochenkov` r? nnethercote or compiler
2024-04-15More polishingMichael Goulet-1/+3
2024-04-15Use a path instead of an ident (and stop manually resolving)Michael Goulet-2/+5
2024-04-15Validation and other thingsMichael Goulet-1/+1
2024-04-15Implement resolution, parse use<Self>Michael Goulet-1/+7
2024-04-15Use dedicated PreciseCapturingArg for representing what goes in use<>Michael Goulet-7/+23
2024-04-15Parsing , pre-lowering support for precise capturesMichael Goulet-6/+22
2024-04-14store the span of the nested part of the use tree in the astPietro Albini-2/+6
2024-04-12Rollup merge of #123223 - estebank:issue-123079, r=pnkfelixMatthias Krüger-13/+7
Fix invalid silencing of parsing error Given ```rust macro_rules! a { ( ) => { impl<'b> c for d { e::<f'g> } }; } ``` ensure an error is emitted. Fix #123079.
2024-04-11remove some things that do not need to beMatthias Krüger-2/+1
2024-04-10Properly handle emojis as literal prefix in macrosEsteban Küber-1/+4
Do not accept the following ```rust macro_rules! lexes {($($_:tt)*) => {}} lexes!(🐛"foo"); ``` Before, invalid emoji identifiers were gated during parsing instead of lexing in all cases, but this didn't account for macro expansion of literal prefixes. Fix #123696.
2024-04-08parser: reduce visibility of unnecessary public `UnmatchedDelim`Yutaro Ohno-5/+2
`lexer::UnmatchedDelim` struct in `rustc_parse` is unnecessary public outside of the crate. This commit reduces the visibility to `pub(crate)`. Beside, this removes unnecessary field `expected_delim` that causes warnings after changing the visibility.
2024-04-07Fix invalid silencing of parsing errorEsteban Küber-13/+7
Given ```rust macro_rules! a { ( ) => { impl<'b> c for d { e::<f'g> } }; } ``` ensure an error is emitted. Fix #123079.
2024-04-04Rename ModSep to PathSepLeón Orell Valerian Liehr-26/+26
2024-04-03Rollup merge of #123401 - Zalathar:assert-size-aarch64, r=fmeaseJacob Pratt-3/+3
Check `x86_64` size assertions on `aarch64`, too (Context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Checking.20size.20assertions.20on.20aarch64.3F) Currently the compiler has around 30 sets of `static_assert_size!` for various size-critical data structures (e.g. various IR nodes), guarded by `#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]`. (Presumably this cfg avoids having to maintain separate size values for 32-bit targets and unusual 64-bit targets. Apparently it may have been necessary before the i128/u128 alignment changes, too.) This is slightly incovenient for people on aarch64 workstations (e.g. Macs), because the assertions normally aren't checked until we push to a PR. So this PR adds `aarch64` to the `#[cfg(..)]` guarding all of those assertions in the compiler. --- Implemented with a simple find/replace. Verified by manually inspecting each `static_assert_size!` in `compiler/`, and checking that either the replacement succeeded, or adding aarch64 wouldn't have been appropriate.
2024-04-03Check `x86_64` size assertions on `aarch64`, tooZalathar-3/+3
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to notice when these assertions have been violated.
2024-04-02Don't ICE for postfix match after asMichael Goulet-0/+1
2024-03-29Auto merge of #123080 - Jules-Bertholet:mut-ref-mut, r=Nadrierilbors-38/+32
Match ergonomics 2024: implement mutable by-reference bindings Implements the mutable by-reference bindings portion of match ergonomics 2024 (#123076), with the `mut ref`/`mut ref mut` syntax, under feature gate `mut_ref`. r? `@Nadrieril` `@rustbot` label A-patterns A-edition-2024
2024-03-27Feature gateJules Bertholet-0/+4
2024-03-27chore: fix some commentsxiaoxiangxianzi-1/+1
Signed-off-by: xiaoxiangxianzi <zhaoyizheng@outlook.com>
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-38/+28