about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/item.rs
AgeCommit message (Collapse)AuthorLines
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
2022-06-07recover `import` instead of `use` in itemMichael Goulet-20/+49
2022-05-30Rollup merge of #97172 - SparrowLii:unsafe_extern, r=compiler-errorsMichael Goulet-26/+15
Optimize the diagnostic generation for `extern unsafe` This PR does the following about diagnostic generation when parsing foreign mod: 1. Fixes the FIXME about avoiding depending on the error message text. 2. Continue parsing when `unsafe` is followed by `{` (just like `unsafe extern {...}`). 3. Add test case.
2022-05-30Optimize the diagnostic generation for `extern unsafe`SparrowLii-26/+15
2022-05-21Remove feature: `crate` visibility modifierJacob Pratt-2/+1
2022-05-07Auto merge of #96094 - Elliot-Roberts:fix_doctests, r=compiler-errorsbors-5/+5
Begin fixing all the broken doctests in `compiler/` Begins to fix #95994. All of them pass now but 24 of them I've marked with `ignore HELP (<explanation>)` (asking for help) as I'm unsure how to get them to work / if we should leave them as they are. There are also a few that I marked `ignore` that could maybe be made to work but seem less important. Each `ignore` has a rough "reason" for ignoring after it parentheses, with - `(pseudo-rust)` meaning "mostly rust-like but contains foreign syntax" - `(illustrative)` a somewhat catchall for either a fragment of rust that doesn't stand on its own (like a lone type), or abbreviated rust with ellipses and undeclared types that would get too cluttered if made compile-worthy. - `(not-rust)` stuff that isn't rust but benefits from the syntax highlighting, like MIR. - `(internal)` uses `rustc_*` code which would be difficult to make work with the testing setup. Those reason notes are a bit inconsistently applied and messy though. If that's important I can go through them again and try a more principled approach. When I run `rg '```ignore \(' .` on the repo, there look to be lots of different conventions other people have used for this sort of thing. I could try unifying them all if that would be helpful. I'm not sure if there was a better existing way to do this but I wrote my own script to help me run all the doctests and wade through the output. If that would be useful to anyone else, I put it here: https://github.com/Elliot-Roberts/rust_doctest_fixing_tool
2022-05-02fix most compiler/ doctestsElliot Roberts-5/+5
2022-05-02Fix invalid keyword order for function declarationsKen Matsui-2/+2
2022-04-29errors: `span_suggestion` takes `impl ToString`David Wood-5/+5
Change `span_suggestion` (and variants) to take `impl ToString` rather than `String` for the suggested code, as this simplifies the requirements on the diagnostic derive. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-42/+43
2022-04-12use `to_string` instead of `format!`Takayuki Maeda-1/+1
2022-04-05errors: implement fallback diagnostic translationDavid Wood-1/+1
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
2022-04-05errors: introduce `DiagnosticMessage`David Wood-1/+2
Introduce a `DiagnosticMessage` type that will enable diagnostic messages to be simple strings or Fluent identifiers. `DiagnosticMessage` is now used in the implementation of the standard `DiagnosticBuilder` APIs. Signed-off-by: David Wood <david.wood@huawei.com>
2022-03-20fix a not emitted unmatched angle bracket errorTakayuki Maeda-1/+1
2022-03-17Rollup merge of #94960 - codehorseman:master, r=oli-obkDylan DPC-1/+1
Fix many spelling mistakes Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-17Rollup merge of #93222 - mark-i-m:errorreported, r=oli-obkDylan DPC-3/+3
Make ErrorReported impossible to construct outside `rustc_errors` There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name. cc #69426 `@varkor` `@eddyb` `@estebank` I actually didn't see that I was assigned to this issue until now...
2022-03-17Rollup merge of #91133 - terrarier2111:unsafe-diagnostic, r=jackh726Dylan DPC-3/+25
Improve `unsafe` diagnostic This fixes: https://github.com/rust-lang/rust/issues/90880 I didn't use the exact proposed messages though.
2022-03-16rustc_error: make ErrorReported impossible to constructmark-3/+3
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
2022-03-16resolve the conflict in compiler/rustc_session/src/parse.rscodehorseman-1/+1
Signed-off-by: codehorseman <cricis@yeah.net>
2022-03-15use `format_args_capture` in some parts of rustc_parseTakayuki Maeda-27/+26
2022-03-15Auto merge of #94584 - pnkfelix:inject-use-suggestion-sites, r=ekuberbors-4/+7
More robust fallback for `use` suggestion Our old way to suggest where to add `use`s would first look for pre-existing `use`s in the relevant crate/module, and if there are *no* uses, it would fallback on trying to use another item as the basis for the suggestion. But this was fragile, as illustrated in issue #87613 This PR instead identifies span of the first token after any inner attributes, and uses *that* as the fallback for the `use` suggestion. Fix #87613
2022-03-11Rollup merge of #94839 - ↵Dylan DPC-0/+10
TaKO8Ki:suggest-using-double-colon-for-struct-field-type, r=cjgillot Suggest using double colon when a struct field type include single colon #92685
2022-03-11fix a suggestion messageTakayuki Maeda-1/+1
2022-03-11suggest using double colon when using single colon in struct field type pathTakayuki Maeda-0/+10
2022-03-07diagnostics: only talk about `Cargo.toml` if running under CargoMichael Howell-3/+2
Fixes #94646
2022-03-06Auto merge of #90076 - jackh726:wherethewhere, r=nikomatsakisbors-53/+29
Change location of where clause on GATs Closes #89122 ~Blocked on lang FCP~ r? `@nikomatsakis`
2022-03-05Change syntax for TyAlias where clausesJack Huey-53/+29
2022-03-06suggest removing a semicolon after derive attributesTakayuki Maeda-0/+10
use current token span
2022-03-03Adjusted diagnostic output so that if there is no `use` in a item sequence,Felix S. Klock II-1/+4
then we just suggest the first legal position where you could inject a use. To do this, I added `inject_use_span` field to `ModSpans`, and populate it in parser (it is the span of the first token found after inner attributes, if any). Then I rewrote the use-suggestion code to utilize it, and threw out some stuff that is now unnecessary with this in place. (I think the result is easier to understand.) Then I added a test of issue 87613.
2022-03-03Associate multiple with a crate too.Felix S. Klock II-2/+1
2022-03-03refactor: prepare to associate multiple spans with a module.Felix S. Klock II-3/+4
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-02-284 - Make more use of `let_chains`Caio-7/+5
Continuation of #94376. cc #53667
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-2/+2
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-5/+7
2022-02-19Adopt let else in more placesest31-3/+2
2022-02-02better suggestion for duplicated `where`Michael Goulet-7/+22