summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2023-05-24Use `is_some_and`/`is_ok_and` in less obvious spotsMaybe Waffle-1/+1
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-1/+1
2023-05-17Give a more useful location for where a span_bug was delayedjyn-0/+1
Before: ``` = note: delayed at 0: <rustc_errors::HandlerInner>::emit_diagnostic at ./compiler/rustc_errors/src/lib.rs:1335:29 1: <rustc_errors::Handler>::emit_diagnostic at ./compiler/rustc_errors/src/lib.rs:1124:9 ... ``` After: ``` = note: delayed at compiler/rustc_parse/src/parser/diagnostics.rs:2158:28 0: <rustc_errors::HandlerInner>::emit_diagnostic at ./compiler/rustc_errors/src/lib.rs:1335:29 1: <rustc_errors::Handler>::emit_diagnostic at ./compiler/rustc_errors/src/lib.rs:1124:9 ``` This both makes the relevant frame easier to find without having to dig through diagnostic internals, and avoids the weird-looking formatting for the first frame.
2023-05-09move sugg to derive session diagnosticyukang-9/+5
2023-05-08code refactor and fix wrong suggestionyukang-23/+29
2023-05-08fix ice in suggestingyukang-7/+14
2023-05-08cleanupyukang-2/+1
2023-05-08Suggest let for possible binding with tyyukang-0/+17
2023-05-04Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obkDylan DPC-1/+1
Implement negative bounds for internal testing purposes Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature. Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-14/+14
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-05-02Implement negative boundsMichael Goulet-1/+1
2023-05-01soften the wording for removing type ascriptionyukang-8/+1
2023-05-01fix testsyukang-1/+0
2023-05-01clean up debug codeyukang-10/+1
2023-05-01Rip it outNilstrieb-75/+44
My type ascription Oh rip it out Ah If you think we live too much then You can sacrifice diagnostics Don't mix your garbage Into my syntax So many weird hacks keep diagnostics alive Yet I don't even step outside So many bad diagnostics keep tyasc alive Yet tyasc doesn't even bother to survive!
2023-04-27Tweak await spanMichael Goulet-1/+1
2023-04-15remove redundant clonesMatthias Krüger-5/+3
2023-04-07fix: fix regression in #109203Ezra Shaw-2/+2
2023-03-28Add `(..)` syntax for RTNMichael Goulet-2/+1
2023-03-20feat: implement error recovery in `expected_ident_found`Ezra Shaw-26/+58
2023-03-19refactor: improve "ident starts with number" errorEzra Shaw-10/+24
2023-03-19refactor: refactor identifier parsing somewhatEzra Shaw-4/+13
2023-03-09feat/refactor: improve errors in case of ident with number at startEzra Shaw-14/+27
2023-03-03Remove unclosed_delims from parseryukang-113/+3
2023-03-01Auto merge of #108587 - matthiaskrgr:rollup-rw6po59, r=matthiaskrgrbors-2/+14
Rollup of 10 pull requests Successful merges: - #108376 (compiler/rustc_session: fix sysroot detection logic) - #108400 (add llvm cgu instructions stats to perf) - #108496 (fix #108495, postfix decrement and prefix decrement has no warning) - #108505 (Further unify validity intrinsics) - #108520 (Small cleanup to `one_bound_for_assoc_type`) - #108560 (Some `infer/mod.rs` cleanups) - #108563 (Make mailmap more correct) - #108564 (Fix `x clean` with specific paths) - #108571 (Add contains_key to SortedIndexMultiMap) - #108578 (Update Fuchsia platform team members) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-03-01Rollup merge of #108496 - nx2k3:issue-108495-dec, r=WaffleLapkinMatthias Krüger-2/+14
fix #108495, postfix decrement and prefix decrement has no warning Fixes #108495
2023-03-01Rollup merge of #108297 - chenyukang:yukang/delim-error-exit, r=petrochenkovMatthias Krüger-3/+3
Exit when there are unmatched delims to avoid noisy diagnostics From https://github.com/rust-lang/rust/pull/104012#issuecomment-1311764832 r? ``@petrochenkov``
2023-02-28micro fmt changesMaybe Waffle-0/+1
2023-02-28refactor parse_token_trees to not return unmatched_delimsyukang-2/+2
2023-02-28rename unmatched_braces to unmatched_delimsyukang-4/+4
2023-02-27handle only postfix decrementnx2k3-10/+0
2023-02-26fix some commentsnx2k3-4/+2
2023-02-26fix #108495, postfix decrement and prefix decrement has no warningnx2k3-3/+26
2023-02-24Replace parse_[sth]_expr with parse_expr_[sth] function namesest31-2/+2
This resolves an inconsistency in naming style for functions on the parser, between functions parsing specific kinds of items and those for expressions, favoring the parse_item_[sth] style used by functions for items. There are multiple advantages of that style: * functions of both categories are collected in the same place in the rustdoc output. * it helps with autocompletion, as you can narrow down your search for a function to those about expressions. * it mirrors rust's path syntax where less specific things come first, then it gets more specific, i.e. std::collections::hash_map::Entry The disadvantage is that it doesn't "read like a sentence" any more, but I think the advantages weigh more greatly. This change was mostly application of this command: sed -i -E 's/(fn |\.)parse_([[:alnum:]_]+)_expr/\1parse_expr_\2/' compiler/rustc_parse/src/parser/*.rs Plus very minor fixes outside of rustc_parse, and an invocation of x fmt.
2023-02-22errors: generate typed identifiers in each crateDavid Wood-3/+3
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-21Use `ThinVec` in `ast::AngleBracketedArgs`.Nicholas Nethercote-1/+1
2023-02-21Use `ThinVec` in `ast::Block`.Nicholas Nethercote-1/+1
2023-02-21Use `ThinVec` in various AST types.Nicholas Nethercote-1/+1
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
2023-02-14Rollup merge of #103478 - SpanishPear:spanishpear/issue_103366_fix, r=TaKO8KiMatthias Krüger-2/+56
Suggest fix for misplaced generic params on fn item #103366 fixes #103366 This still has some work to go, but works for 2/3 of the initial base cases described in #1033366 simple fn: ``` error: expected identifier, found `<` --> shreys/test_1.rs:1:3 | 1 | fn<T> id(x: T) -> T { x } | ^ expected identifier | help: help: place the generic parameter list after the function name: | 1 | fn id<T>(x: T) -> T { x } | ~~~~ ``` Complicated bounds ``` error: expected identifier, found `<` --> spanishpear/test_2.rs:1:3 | 1 | fn<'a, B: 'a + std::ops::Add<Output = u32>> f(_x: B) { } | ^ expected identifier | help: help: place the generic parameter list after the function name: | 1 | fn f<'a, B: 'a + std::ops::Add<Output = u32>>(_x: B) { } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` Opening a draft PR for comments on approach, particularly I have the following questions: - [x] Is it okay to be using `err.span_suggestion` over struct derives? I struggled to get the initial implementation (particularly the correct suggestion message) on struct derives, although I think given what I've learned since starting, I could attempt re-doing it with that approach. - [x] in the case where the snippet cannot be obtained from a span, is the `help` but no suggestion okay? I think yes (also, when does this case occur?) - [x] are there any red flags for the generalisation of this work for relevant item kinds (i.e. `struct`, `enum`, `trait`, and `union`). My basic testing indicates it does work for those types except the help tip is currently hardcoded to `after the function name` - which should change dependent on the item. - [x] I am planning to not show the suggestion if there is already a `<` after the item identifier, (i.e. if there are already generics, as after a function name per the original issue). Any major objections? - [x] Is the style of error okay? I wasn't sure if there was a way to make it display nicer, or if thats handled by span_suggestion These aren't blocking questions, and I will keep working on: - check if there is a `<` after the ident (and if so, not showing the suggestion) - generalize the help message - figuring out how to write/run/etc ui tests (including reading the docs for them) - logic cleanups
2023-02-02Parse and recover from type ascription in patternsEsteban Küber-12/+39
2023-02-02Revert "Teach parser to understand fake anonymous enum syntax" and related ↵Michael Goulet-39/+13
commits Revert "review comment: Remove AST AnonTy" This reverts commit 020cca8d36cb678e3ddc2ead41364be314d19e93. Revert "Ensure macros are not affected" This reverts commit 12d18e403139eeeeb339e8611b2bed4910864edb. Revert "Emit fewer errors on patterns with possible type ascription" This reverts commit c847a01a3b1f620c4fdb98c75805033e768975d1. Revert "Teach parser to understand fake anonymous enum syntax" This reverts commit 2d824206655bfb26cb5eed43490ee396542b153e.
2023-02-01Convert rustc_parse::parser::pat::Expected to enumXiretza-2/+2
This is required in order to support translatable diagnostics.
2023-02-01fix formatting + test syntaxSpanishPear-1/+1
2023-01-31move to multipart spansSpanishPear-5/+6
2023-01-28Rollup merge of #107190 - fmease:fix-81698, r=compiler-errorsMatthias Krüger-0/+22
Recover from more const arguments that are not wrapped in curly braces Recover from some array, borrow, tuple & arithmetic expressions in const argument positions that lack curly braces and provide a suggestion to fix the issue continuing where #92884 left off. Examples of such expressions: `[]`, `[0]`, `[1, 2]`, `[0; 0xff]`, `&9`, `("", 0)` and `(1 + 2) * 3` (we previously did not recover from them). I am not entirely happy with my current solution because the code that recovers from `[0]` (coinciding with a malformed slice type) and `[0; 0]` (coinciding with a malformed array type) is quite fragile as the aforementioned snippets are actually successfully parsed as types by `parse_ty` since it itself already recovers from them (returning `[⟨error⟩]` and `[⟨error⟩; 0]` respectively) meaning I have to manually look for `TyKind::Err`s and construct a separate diagnostic for the suggestion to attach to (thereby emitting two diagnostics in total). Fixes #81698. `@rustbot` label A-diagnostics r? diagnostics
2023-01-27recover more unbraced const argsLeón Orell Valerian Liehr-0/+22
2023-01-22revert to previous spanSpanishPear-3/+4
2023-01-22Attempt to address review comments via github web...Shrey Sudhir-3/+2
2023-01-22Apply automatic suggestions from code reviewShrey Sudhir-3/+3
Co-authored-by: Takayuki Maeda <takoyaki0316@gmail.com>
2023-01-22--wip-- [skip ci]SpanishPear-2/+55
--wip-- [skip ci] get the generic text and put it int he suggestion, but suggestion not working on derive subdiagnostic refactor away from derives and use span_suggestion() instead. Show's the correct(?) generic contents, but overwrites the fn name :( x fmt drop commented code and s/todo/fixme get the correct diagnostic for functions, at least x fmt remove some debugs remove format remove debugs remove useless change remove useless change remove legacy approach correct lookahead + error message contains the ident name fmt refactor code tests add tests remoev debug remove comment