about summary refs log tree commit diff
path: root/compiler/rustc_parse
AgeCommit message (Collapse)AuthorLines
2022-08-13Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-label, ↵Michael Goulet-1/+1
r=estebank Only point out a single function parameter if we have a single arg incompatibility Fixes #99635
2022-08-13Rollup merge of #100475 - chenyukang:fix-100461, r=fee1-deadMichael Goulet-2/+6
Give a helpful diagnostic when the next struct field has an attribute Fixes #100461
2022-08-13avoid cloning and then iteratingKaDiWa-5/+5
2022-08-13use `span_suggestion` instead of `span_suggestion_verbose`Takayuki Maeda-1/+1
2022-08-13give a helpful diagnostic even when the next struct field has an attributeyukang-2/+6
2022-08-12Adjust cfgsMark Rousskov-1/+0
2022-08-12Adjust span of fn argumentsMichael Goulet-1/+1
2022-08-12Adjust span of closure paramMichael Goulet-1/+1
2022-08-12Rollup merge of #100396 - chenyukang:fix-100394, r=petrochenkovDylan DPC-1/+6
Suggest const and static for global variable Fixing #100394
2022-08-12suggest removing a semicolon after impl/trait itemsTakayuki Maeda-4/+34
2022-08-11Rollup merge of #100350 - jhpratt:stringify-vis, r=cjgillotMatthias Krüger-2/+10
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 #100351 - compiler-errors:diagnostic-convention, r=fee1-deadDylan DPC-5/+5
Use `&mut Diagnostic` instead of `&mut DiagnosticBuilder` unless needed This seems to be the established convention (02ff9e0) when `DiagnosticBuilder` was first added. I am guilty of introducing some of these.
2022-08-11suggest const or static for global variablechenyukang-1/+6
2022-08-10Do not consider method call receiver as an argument in AST.Camille GILLOT-5/+7
2022-08-10Use &mut Diagnostic instead of &mut DiagnosticBuilder unless neededMichael Goulet-5/+5
2022-08-09Stringify non-shorthand visibility correctlyJacob Pratt-2/+10
2022-08-10suggest a missing semicolon before an arrayTakayuki Maeda-0/+42
2022-08-09Recover from mutable variable declaration where `mut` is placed before `let`Obei Sideg-0/+13
2022-08-06Rollup merge of #100167 - chenyukang:require-suggestion, r=estebankMatthias Krüger-1/+4
Recover `require`, `include` instead of `use` in item Fix #100140
2022-08-05Rollup merge of #100168 - ↵Dylan DPC-11/+19
WaffleLapkin:improve_diagnostics_for_missing_type_in_a_const_item, r=compiler-errors Improve diagnostics for `const a: = expr;` Adds a suggestion to write a type when there is a colon, but the type is not present. I've also shrunk spans a little, so the suggestions are a little nicer. Resolves #100146 r? `@compiler-errors`
2022-08-05Improve diagnostics for `const a: = expr;`Maybe Waffle-11/+19
2022-08-05recover require,include instead of use in itemyukang-1/+4
2022-08-04Rollup merge of #98796 - compiler-errors:no-semi-if-comma, r=estebankMatthias Krüger-1/+2
Do not exclusively suggest `;` when `,` is also a choice Fixes #96791
2022-08-04Suggest removing `let` if `let const` is usedObei Sideg-0/+16
2022-08-03Rollup merge of #99786 - obeis:issue-99625, r=compiler-errorsMatthias Krüger-0/+19
Recover from C++ style `enum struct` Closes #99625
2022-08-03Suggest removing `let` if `const let` is usedObei Sideg-0/+10
2022-08-02Rollup merge of #100011 - compiler-errors:let-chain-restriction, r=fee1-deadMatthias Krüger-44/+19
Use Parser's `restrictions` instead of `let_expr_allowed` This also means that the `ALLOW_LET` flag is reset properly for subexpressions, so we can properly deny things like `a && (b && let c = d)`. Also the parser is a tiny bit smaller now. It doesn't reject _all_ bad `let` expr usages, just a bit more. cc `@c410-f3r`
2022-08-01Use expr parse restrictions for let expr parsingMichael Goulet-44/+19
2022-08-01Shrink `Token`.Nicholas Nethercote-23/+29
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-08-01Add a size assertion for `Token`.Nicholas Nethercote-0/+7
2022-08-01Inline `TokenStreamBuilder::push`.Nicholas Nethercote-0/+1
Because it's small and hot.
2022-08-01Avoid an unnecessary `return`.Nicholas Nethercote-2/+2
2022-08-01Remove `StringReader::end_src_index`.Nicholas Nethercote-5/+2
It not needed, always being set to the end of the text.
2022-08-01Improve shebang handling.Nicholas Nethercote-8/+5
Avoid doing stuff until it's necessary.
2022-07-30Auto merge of #99948 - Dylan-DPC:rollup-ed5136t, r=Dylan-DPCbors-6/+18
Rollup of 5 pull requests Successful merges: - #99311 (change maybe_body_owned_by to take local def id) - #99862 (Improve type mismatch w/ function signatures) - #99895 (don't call type ascription "cast") - #99900 (remove some manual hash stable impls) - #99903 (Add diagnostic when using public instead of pub) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-07-30Rollup merge of #99903 - gimbles:pub, r=davidtwcoDylan DPC-0/+11
Add diagnostic when using public instead of pub Forwarding from https://github.com/rust-lang/rust/pull/99706 I accidentally broke something(??) in git and the commits in that PR are absolutely not what I did in that branch Anyways, this is the PR for this now. Adding tests again in a minute. cc `@davidtwco`
2022-07-30Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkovbors-36/+36
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-29Recover keywords in boundsMaybe Waffle-1/+7
For example, this fixes a error for `impl fn()` (notice the capitalization)
2022-07-29Add diagnostic when using public instead of pubGimgim-0/+11
2022-07-29Recover from c++ style `enum struct`Obei Sideg-0/+19
new error message: `enum` and `struct` are mutually exclusive new suggestion: replace `enum struct` with `enum`
2022-07-29dont call type ascription 'cast'Michael Goulet-6/+7
2022-07-29Remove `TreeAndSpacing`.Nicholas Nethercote-36/+36
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-28remove an unnecessary line breakTakayuki Maeda-1/+0
2022-07-25Remove let-chain close brace check.Eric Huss-4/+1
2022-07-24Update doc comments that refer to config parameterDaniel Bevenius-2/+2
This commit updates the source_file_to_parser and the maybe_source_file_to_parse function's doc comments which currently refer to a config parameter. The doc comments have been updated to refer to the 'session' parameter similar to the doc comment for try_file_to_source_file, which also takes a &Session parameter.
2022-07-23Do not suggest adding `;` when `,` is also a choiceMichael Goulet-1/+2
2022-07-16Stabilize `let_chains`Caio-24/+8
2022-07-14Rollup merge of #98705 - WaffleLapkin:closure_binder, r=cjgillotDylan DPC-26/+22
Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](https://github.com/rust-lang/rust/issues/97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
2022-07-13Rollup merge of #99030 - rust-lang:notriddle/field-recovery, r=petrochenkovDylan DPC-0/+18
diagnostics: error messages when struct literals fail to parse If an expression is supplied where a field is expected, the parser can become convinced that it's a shorthand field syntax when it's not. This PR addresses it by explicitly recording the permitted `:` token immediately after the identifier, and also adds a suggestion to insert the name of the field if it looks like a complex expression. Fixes #98917
2022-07-12Update compiler/rustc_parse/src/parser/expr.rsMichael Howell-1/+1
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>