about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/item.rs
AgeCommit message (Collapse)AuthorLines
2022-11-11Auto merge of #99918 - WaffleLapkin:fnFnfun, r=estebankbors-31/+60
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-08Parser: Recover from using colon as path separator in importsBruno A. Muciño-0/+17
2022-10-18Fix the bug of next_point in spanyukang-1/+1
2022-10-11Fix let removal suggestion in structMichael Goulet-6/+11
2022-10-10`let` is not allowed in struct field definitionsgimbles-1/+17
Co-authored-by: jyn514 <jyn514@gmail.com> Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
2022-10-01Replace some `bool` params with an enumMaybe Waffle-29/+34
2022-10-01Recover wrong cased keywords starting functionsMaybe Waffle-37/+42
2022-10-01recover wrong-cased `use`s (`Use`, `USE`, etc)Maybe Waffle-3/+22
2022-09-30Rollup merge of #102350 - TaKO8Ki:incomplete-fn-in-struct-definition, ↵Matthias Krüger-11/+17
r=fee1-dead Improve errors for incomplete functions in struct definitions Given the following code: ```rust fn main() {} struct Foo { fn } ``` [playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=29139f870511f6918324be5ddc26c345) The current output is: ``` Compiling playground v0.0.1 (/playground) error: functions are not allowed in struct definitions --> src/main.rs:4:5 | 4 | fn | ^^ | = help: unlike in C++, Java, and C#, functions are declared in `impl` blocks = help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information error: could not compile `playground` due to previous error ``` In this case, rustc should suggest escaping `fn` to use it as an identifier.
2022-09-29improve E0585 helpRageking8-2/+2
2022-09-27Migrate more rustc_parse diagnostics to diagnostic structsXiretza-12/+10
2022-09-27Move rustc_parse diagnostic structs to separate moduleXiretza-1/+3
2022-09-28improve errors for incomplete functions in struct definitionsTakayuki Maeda-11/+17
2022-09-27add a label to struct/enum/union ident nameTakayuki Maeda-10/+26
2022-09-27create a new local varTakayuki Maeda-5/+3
2022-09-26Rollup merge of #102286 - compiler-errors:recover-semi-in-block-item, ↵Matthias Krüger-7/+22
r=davidtwco Recover some items that expect braces and don't take semicolons Fixes #102262
2022-09-25Recover some items that expect braces and don't take semicolonsMichael Goulet-7/+22
2022-09-22recover from struct nested in structRageking8-0/+17
2022-09-16tweak suggestionyukang-1/+1
2022-09-15fix #101797: Suggest associated const for incorrect use of let in traitsyukang-4/+15
2022-09-06Rollup merge of #101457 - ChayimFriedman2:struct-field-semi, r=fee1-deadGuillaume Gomez-0/+11
Recover from using `;` as separator between fields Partially fixes #101440 (only for record structs). Doing that for tuple structs is harder as their parsing passes through a bunch of helper functions. I don't know how to do that. But [their error message is better anyway](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cc6ee8bb2593596c0cea89d49e79bcb4) and suggests using a comma, even if it doesn't suggest replacing the semicolon with it.
2022-09-05Recover from using `;` as separator between fieldsChayim Refael Friedman-0/+11
2022-09-02Refactor and re-use BindingAnnotationCameron Steffen-2/+2
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-32/+25
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-17Box the `MacCall` in various types.Nicholas Nethercote-1/+1
2022-08-15Rollup merge of #100458 - compiler-errors:fn-argument-span, r=estebankMatthias Krüger-1/+1
Adjust span of fn argument declaration Span of a fn argument declaration goes from: ``` fn foo(i : i32 , ...) ^^^^^^^^ ``` to: ``` fn foo(i : i32 , ...) ^^^^^^^ ``` That is, we don't include the extra spacing up to the trailing comma, which I think is more correct. cc https://github.com/rust-lang/rust/pull/99646#discussion_r944568074 r? ``@estebank`` --- The two tests that had dramatic changes in their rendering I think actually are improved, though they are kinda poor spans both before and after the changes. :shrug: Thoughts?
2022-08-15Rollup merge of #100566 - TaKO8Ki:use-create-snapshot-for-diagnostic, r=cjgillotMatthias Krüger-2/+2
Use `create_snapshot_for_diagnostic` instead of `clone` for `Parser` follow-up to #98020
2022-08-15use `create_snapshot_for_diagnostic` instead of `clone` for `Parser`Takayuki Maeda-2/+2
2022-08-14Rollup merge of #100115 - obeis:issue-99910, r=cjgillotDylan DPC-0/+10
Suggest removing `let` if `const let` or `let const` is used Closes #99910
2022-08-13Rollup merge of #100446 - ↵Michael Goulet-4/+34
TaKO8Ki:suggest-removing-semicolon-after-impl-trait-items, r=compiler-errors Suggest removing a semicolon after impl/trait items fixes #99822
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-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 span of fn argumentsMichael Goulet-1/+1
2022-08-12suggest removing a semicolon after impl/trait itemsTakayuki Maeda-4/+34
2022-08-11suggest const or static for global variablechenyukang-1/+6
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-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-07-30Auto merge of #99887 - nnethercote:rm-TreeAndSpacing, r=petrochenkovbors-2/+2
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 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-29Remove `TreeAndSpacing`.Nicholas Nethercote-2/+2
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-06-28Use pre-interned symbols in import recoverybjorn3-2/+1
2022-06-16Do not suggest adding semicolon/changing delimiters for macros in item ↵Chayim Refael Friedman-21/+25
position that originates in macros
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-23/+18