about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-3/+0
2022-12-10fix #105366, suggest impl in the scenario of typo with fnyukang-2/+26
2022-12-07fix #105226, Detect spurious ; before assoc fn bodyyukang-3/+9
2022-12-06Rollup merge of #105098 - lyming2007:issue-103869-fix, r=eholkMatthias Krüger-1/+8
propagate the error from parsing enum variant to the parser and emit out While parsing enum variant, the error message always disappear Because the error message that emit out is from main error of parser The information of enum variant disappears while parsing enum variant with error We only check the syntax of expecting token, i.e, in case https://github.com/rust-lang/rust/issues/103869 It will error it without telling the message that this error is from pasring enum variant. Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err Check the sub-error before emitting the main error of parser and attach it. Fix https://github.com/rust-lang/rust/issues/103869
2022-12-05Rollup merge of #105223 - lukas-code:(ExprWithBlock), r=petrochenkovMatthias Krüger-14/+5
suggest parenthesis around ExprWithBlock BinOp ExprWithBlock fix https://github.com/rust-lang/rust/issues/105179 fix https://github.com/rust-lang/rust/issues/102171
2022-12-05Parameterise `Parser::{recover_unclosed_char,handle_missing_lit}`.Nicholas Nethercote-30/+49
These two methods both produce a `MetaItemLit`, and then some of the call sites convert the `MetaItemLit` to a `token::Lit` with `as_token_lit`. This commit parameterises these two methods with a `mk_lit_char` closure, which can be used to produce either `MetaItemLit` or `token::Lit` directly as necessary.
2022-12-04Rollup merge of #105141 - ohno418:fix-ice-on-invalid-var-decl-in-macro-call, ↵Matthias Krüger-19/+24
r=compiler-errors Fix ICE on invalid variable declarations in macro calls This fixes ICE that happens with invalid variable declarations in macro calls like: ```rust macro_rules! m { ($s:stmt) => {} } m! { var x } m! { auto x } m! { mut x } ``` Found this is because of not collecting tokens on recovery, so I changed to force collect them. Fixes https://github.com/rust-lang/rust/issues/103529.
2022-12-03more commentsLukas Markeffsky-3/+4
2022-12-03suggest parenthesis around ExprWithBlock BinOp ExprWithBlockLukas Markeffsky-12/+2
2022-12-03Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillotMatthias Krüger-3/+7
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-03parser: refactoring on recovery from invalid variable declarationsYutaro Ohno-16/+21
Previously, the `recover_local_after_let` function was called from the body of the `recover_stmt_local` function. Unifying these two functions make it more simple and more readable.
2022-12-03parser: fix ICE with invalid variable declaration in macro callYutaro Ohno-4/+4
Fix ICE on parsing an invalid variable declaration as a statement like: ``` macro_rules! m { ($s:stmt) => {} } m! { var x } ```
2022-12-01While parsing enum variant, the error message always disappearYiming Lei-1/+8
Because the error message that emit out is from main error of parser The information of enum variant disappears while parsing enum variant with error We only check the syntax of expecting token, i.e, in case #103869 It will error it without telling the message that this error is from pasring enum variant. Propagate the sub-error from parsing enum variant to the main error of parser by chaining it with map_err Check the sub-error before emitting the main error of parser and attach it. Fix #103869
2022-12-02Remove `token::Lit` from `ast::MetaItemLit`.Nicholas Nethercote-6/+7
`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-01rustc_ast_lowering: Stop lowering imports into multiple itemsVadim Petrochenkov-1/+1
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 unnecessary `MetaItem`/`Attribute` conversions.Nicholas Nethercote-17/+26
`check_builtin_attribute` calls `parse_meta` to convert an `Attribute` to a `MetaItem`, which it then checks. However, many callers of `check_builtin_attribute` start with a `MetaItem`, and then convert it to an `Attribute` by calling `cx.attribute(meta_item)`. This `MetaItem` to `Attribute` to `MetaItem` conversion is silly. This commit adds a new function `check_builtin_meta_item`, which can be called instead from these call sites. `check_builtin_attribute` also now calls it. The commit also renames `check_meta` as `check_attr` to better match its arguments.
2022-11-28Keep track of the start of the argument block of a closureSarthak Singh-3/+7
2022-11-28Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote-1/+1
We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
2022-11-28Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote-18/+22
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-6/+6
2022-11-26will not suggest for postfix operator when can not handle precedences wellyukang-1/+5
2022-11-26add start_stmt to handle postfix incrementyukang-30/+26
2022-11-25fix #104867, Properly handle postfix inc/dec in standalone and subexpr scenariosyukang-42/+25
2022-11-24Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errorsMatthias Krüger-2/+3
Suggest `.clone()` or `ref binding` on E0382
2022-11-24Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiserbors-1/+1
Use `as_deref` in compiler (but only where it makes sense) This simplifies some code :3 (there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
2022-11-23Suggest `.clone()` or `ref binding` on E0382Esteban Küber-2/+3
2022-11-23Auto merge of #104410 - WaffleLapkin:unregress, r=estebankbors-10/+22
Fix perf regression by correctly matching keywords This should (hopefully) fix regression from #99918 r? `@estebank`
2022-11-22`rustc_parse`: remove `ref` patternsMaybe Waffle-39/+39
2022-11-22Rollup merge of #104559 - nnethercote:split-MacArgs, r=petrochenkovMatthias Krüger-62/+61
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. r? `@petrochenkov`
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-62/+61
`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-21Match crate and slug namesmejrs-127/+121
2022-11-19Cleanup macro matching recoveryNilstrieb-5/+0
The retry has been implemented already.
2022-11-19Rollup merge of #104566 - matthiaskrgr:clippy_perf_nov18, r=oli-obkDylan DPC-2/+2
couple of clippy::perf fixes
2022-11-18Auto merge of #104573 - matthiaskrgr:rollup-k36ybtp, r=matthiaskrgrbors-2/+21
Rollup of 8 pull requests Successful merges: - #101162 (Migrate rustc_resolve to use SessionDiagnostic, part # 1) - #103386 (Don't allow `CoerceUnsized` into `dyn*` (except for trait upcasting)) - #103405 (Detect incorrect chaining of if and if let conditions and recover) - #103594 (Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets) - #104006 (Add variant_name function to `LangItem`) - #104494 (Migrate GUI test to use functions) - #104516 (rustdoc: clean up sidebar width CSS) - #104550 (fix a typo) Failed merges: - #104554 (Use `ErrorGuaranteed::unchecked_claim_error_was_emitted` less) r? `@ghost` `@rustbot` modify labels: rollup
2022-11-18Rollup merge of #103405 - chenyukang:yukang/fix-103381-and-if, r=compiler-errorsMatthias Krüger-2/+21
Detect incorrect chaining of if and if let conditions and recover Fixes #103381
2022-11-18couple of clippy::perf fixesMatthias Krüger-2/+2
2022-11-17Use `ThinVec` in `ast::Path`.Nicholas Nethercote-18/+24
2022-11-17Box `ExprKind::{Closure,MethodCall}`, and `QSelf` in expressions, types, and ↵Nicholas Nethercote-26/+38
patterns.
2022-11-16Auto merge of #102944 - nnethercote:ast-Lit-third-time-lucky, r=petrochenkovbors-244/+119
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. r? `@petrochenkov`
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-1/+1
2022-11-16Fix perf regression by correctly matching keywordsMaybe Waffle-10/+22
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-244/+119
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-15Only do parser recovery on retried macro matchingNilstrieb-2/+2
This prevents issues with eager parser recovery during macro matching.
2022-11-15comment feedbackyukang-2/+1
2022-11-15fix #104088, Slightly improve error message for invalid identifieryukang-2/+23
2022-11-15fix #103381, Detect incorrect chaining of if and if let conditionsyukang-2/+21
2022-11-14Rollup merge of #104223 - fmease:recover-fn-ptr-with-generics, r=estebankMatthias Krüger-3/+77
Recover from function pointer types with generic parameter list Give a more helpful error when encountering function pointer types with a generic parameter list like `fn<'a>(&'a str) -> bool` or `fn<T>(T) -> T` and suggest moving lifetime parameters to a `for<>` parameter list. I've added a bunch of extra code to properly handle (unlikely?) corner cases like `for<'a> fn<'b>()` (where there already exists a `for<>` parameter list) correctly suggesting `for<'a, 'b> fn()` (merging the lists). If you deem this useless, I can simplify the code by suggesting nothing at all in this case. I am quite open to suggestions regarding the wording of the diagnostic messages. Fixes #103487. ``@rustbot`` label A-diagnostics r? diagnostics
2022-11-13Add `delay_span_bug` to `AttrWrapper::take_for_recovery`Maybe Waffle-13/+26
2022-11-12Auto merge of #103812 - clubby789:improve-include-bytes, r=petrochenkovbors-1/+3
Delay `include_bytes` to AST lowering Hopefully addresses #65818. This PR introduces a new `ExprKind::IncludedBytes` which stores the path and bytes of a file included with `include_bytes!()`. We can then create a literal from the bytes during AST lowering, which means we don't need to escape the bytes into valid UTF8 which is the cause of most of the overhead of embedding large binary blobs.
2022-11-11Rollup merge of #103468 - chenyukang:yukang/fix-103435-extra-parentheses, ↵Manish Goregaokar-7/+23
r=estebank Fix unused lint and parser caring about spaces to won't produce invalid code Fixes #103435