about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/errors.rs
AgeCommit message (Collapse)AuthorLines
2025-08-05Added checks for attribute in type caseKivooeo-0/+28
2025-07-17parse `const trait Trait`Deadbeef-0/+8
2025-06-30Remove let_chains featureCameron Steffen-0/+7
2025-06-13Rework how the disallowed qualifier lints are generatedJonathan Brouwer-4/+4
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-05-27move asm parsing code into `rustc_parse`Folkert de Vries-0/+70
2025-05-14Improve ternary operator recoveryJamie-1/+19
2025-05-07Rollup merge of #140671 - xizheyin:issue-140169, r=petrochenkovGuillaume Gomez-0/+24
Parser: Recover error from named params while parse_path Fixes #140169 I added test to the first commit and the second added the code and changes to test. r? `@petrochenkov`
2025-05-07Use `parse_param_general` when parsing `(T, U)->R` in `parse_path_segment`xizheyin-0/+24
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn> Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2025-05-05Implement RFC 3503: frontmattersDeadbeef-0/+55
Supercedes #137193
2025-04-25resolved conflictKivooeo-0/+7
2025-04-23rc and cr more clear error messageKivooeo-0/+7
2025-04-17Auto merge of #139949 - matthiaskrgr:rollup-pxc5tsx, r=matthiaskrgrbors-7/+2
Rollup of 8 pull requests Successful merges: - #138632 (Stabilize `cfg_boolean_literals`) - #139416 (unstable book; document `macro_metavar_expr_concat`) - #139782 (Consistent with treating Ctor Call as Struct in liveness analysis) - #139885 (document RUSTC_BOOTSTRAP, RUSTC_OVERRIDE_VERSION_STRING, and -Z allow-features in the unstable book) - #139904 (Explicitly annotate edition for `unpretty=expanded` and `unpretty=hir` tests) - #139932 (transmutability: Refactor tests for simplicity) - #139944 (Move eager translation to a method on Diag) - #139948 (git: ignore `60600a6fa403216bfd66e04f948b1822f6450af7` for blame purposes) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-17Auto merge of #139940 - matthiaskrgr:rollup-rd4d3fn, r=matthiaskrgrbors-1/+2
Rollup of 9 pull requests Successful merges: - #135340 (Add `explicit_extern_abis` Feature and Enforce Explicit ABIs) - #139440 (rustc_target: RISC-V: feature addition batch 2) - #139667 (cfi: Remove #[no_sanitize(cfi)] for extern weak functions) - #139828 (Don't require rigid alias's trait to hold) - #139854 (Improve parse errors for stray lifetimes in type position) - #139889 (Clean UI tests 3 of n) - #139894 (Fix `opt-dist` CLI flag and make it work without LLD) - #139900 (stepping into impls for normalization is unproductive) - #139915 (replace some #[rustc_intrinsic] usage with use of the libcore declarations) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-16Move eager translation to a method on `Diag`Jake Goulding-7/+2
This will allow us to eagerly translate messages on a top-level diagnostic, such as a `LintDiagnostic`. As a bonus, we can remove the awkward closure passed into Subdiagnostic and make better use of `Into`.
2025-04-16Remove old diagnostic notes for type ascription syntaxZalathar-6/+0
Type ascription syntax was removed in 2023.
2025-04-15Improve diagnostic for E0178 (bad `+` in type)León Orell Valerian Liehr-1/+0
Namely, use a more sensical primary span. Don't pretty-print AST nodes for the diagnostic message. Why: * It's lossy (e.g., it doesn't replicate trailing `+`s in trait objects. * It's prone to leak error nodes (printed as `(/*ERROR*/)`) since the LHS can easily represent recovered code (e.g., `fn(i32?) + T`).
2025-04-15Improve parse errors for lifetimes in type positionLeón Orell Valerian Liehr-0/+2
2025-04-02Remove `NtExpr` and `NtLiteral`.Nicholas Nethercote-2/+2
Notes about tests: - tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs: some messages are now duplicated due to repeated parsing. - tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs: ditto. - `tests/ui/proc-macro/macro-rules-derive-cfg.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group around a metavar. - `tests/ui/attributes/nonterminal-expansion.rs`: a slight span degradation, somehow related to the recent massive attr parsing rewrite (#135726). I couldn't work out exactly what is going wrong, but I don't think it's worth holding things up for a single slightly suboptimal error message.
2025-04-01Auto merge of #138492 - lcnr:rm-inline_const_pat, r=oli-obkbors-11/+0
remove `feature(inline_const_pat)` Summarizing https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/remove.20feature.28inline_const_pat.29.20and.20shared.20borrowck. With https://github.com/rust-lang/types-team/issues/129 we will start to borrowck items together with their typeck parent. This is necessary to correctly support opaque types, blocking the new solver and TAIT/ATPIT stabilization with the old one. This means that we cannot really support `inline_const_pat` as they are implemented right now: - we want to typeck inline consts together with their parent body to allow inference to flow both ways and to allow the const to refer to local regions of its parent.This means we also need to borrowck the inline const together with its parent as that's necessary to properly support opaque types - we want the inline const pattern to participate in exhaustiveness checking - to participate in exhaustiveness checking we need to evaluate it, which requires borrowck, which now relies on borrowck of the typeck root, which ends up checking exhaustiveness again. **This is a query cycle**. There are 4 possible ways to handle this: - stop typechecking inline const patterns together with their parent - causes inline const patterns to be different than inline const exprs - prevents bidirectional inference, we need to either fail to compile `if let const { 1 } = 1u32` or `if let const { 1u32 } = 1` - region inference for inline consts will be harder, it feels non-trivial to support inline consts referencing local regions from the parent fn - inline consts no longer participate in exhaustiveness checking. Treat them like `pat if pat == const { .. }` instead. We then only evaluate them after borrowck - difference between `const { 1 }` and `const FOO: usize = 1; match x { FOO => () }`. This is confusing - do they carry their weight if they are now just equivalent to using an if-guard - delay exhaustiveness checking until after borrowck - should be possible in theory, but is a quite involved change and may have some unexpected challenges - remove this feature for now I believe we should either delay exhaustiveness checking or remove the feature entirely. As moving exhaustiveness checking to after borrow checking is quite complex I think the right course of action is to fully remove the feature for now and to add it again once/if we've got that implementation figured out. `const { .. }`-expressions remain stable. These seem to have been the main motivation for https://github.com/rust-lang/rfcs/issues/2920. r? types cc `@rust-lang/types` `@rust-lang/lang` #76001
2025-03-31Rollup merge of #138749 - compiler-errors:closure-recovery, r=fmeaseMatthias Krüger-3/+3
Fix closure recovery for missing block when return type is specified Firstly, fix the `is_array_like_block` condition to make sure we're actually recovering a mistyped *block* rather than some other delimited expression. This fixes #138748. Secondly, split out the recovery of missing braces on a closure body into a separate recovery. Right now, the suggestion `"you might have meant to write this as part of a block"` originates from `suggest_fixes_misparsed_for_loop_head`, which feels kinda brittle and coincidental since AFAICT that recovery wasn't ever really intended to fix this. We also can make this `MachineApplicable` in this case. Fixes #138748 r? `@fmease` or reassign if you're busy/don't wanna review this
2025-03-25Remove now unreachable parse recovery codeLeón Orell Valerian Liehr-18/+0
StructLiteralNeedingParens is no longer reachable always giving precedence to StructLiteralNotAllowedHere. As an aside: The former error struct shouldn't've existed in the first place. We should've just used the latter in this branch.
2025-03-21remove `feature(inline_const_pat)`lcnr-11/+0
2025-03-20Fix diagnostic struct typo, make sure is_array_like_block checks that it's a ↵Michael Goulet-3/+3
block
2025-03-06Give a better error message on async use in edition 2015Santiago Pastorino-0/+7
2025-03-06Use closure parse codeSantiago Pastorino-0/+8
2025-03-06Implement .use keyword as an alias of cloneSantiago Pastorino-0/+13
2025-03-01Rollup merge of #137824 - estebank:rtn-sugg, r=compiler-errorsMatthias Krüger-1/+2
Tweak invalid RTN errors Make suggestions verbose. When encountering `method(type)` bound, suggest `method(..)` instead of `method()`. ``` error: argument types not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:9:23 | LL | fn foo<T: Trait<method(i32): Send>>() {} | ^^^^^ | help: remove the input types | LL - fn foo<T: Trait<method(i32): Send>>() {} LL + fn foo<T: Trait<method(..): Send>>() {} | ``` When encountering both return type and arg list that isn't `..`, suggest replacing both. ``` error: return type not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:12:25 | LL | fn bar<T: Trait<method() -> (): Send>>() {} | ^^^^^^ | help: use the right argument notation and remove the return type | LL - fn bar<T: Trait<method() -> (): Send>>() {} LL + fn bar<T: Trait<method(..): Send>>() {} | ``` When encountering a return type, suggest removing it including the leading whitespace. ``` error: return type not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:24:45 | LL | fn bay_path<T: Trait>() where T::method(..) -> (): Send {} | ^^^^^ | help: remove the return type | LL - fn bay_path<T: Trait>() where T::method(..) -> (): Send {} LL + fn bay_path<T: Trait>() where T::method(..): Send {} | ``` r? ``@compiler-errors``
2025-02-28Tweak invalid RTN errorsEsteban Küber-1/+2
Make suggestions verbose. When encountering `method(type)` bound, suggest `method(..)` instead of `method()`. ``` error: argument types not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:9:23 | LL | fn foo<T: Trait<method(i32): Send>>() {} | ^^^^^ | help: remove the input types | LL - fn foo<T: Trait<method(i32): Send>>() {} LL + fn foo<T: Trait<method(..): Send>>() {} | ``` When encountering both return type and arg list that isn't `..`, suggest replacing both. ``` error: return type not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:12:25 | LL | fn bar<T: Trait<method() -> (): Send>>() {} | ^^^^^^ | help: use the right argument notation and remove the return type | LL - fn bar<T: Trait<method() -> (): Send>>() {} LL + fn bar<T: Trait<method(..): Send>>() {} | ``` When encountering a return type, suggest removing it including the leading whitespace. ``` error: return type not allowed with return type notation --> $DIR/bad-inputs-and-output.rs:24:45 | LL | fn bay_path<T: Trait>() where T::method(..) -> (): Send {} | ^^^^^ | help: remove the return type | LL - fn bay_path<T: Trait>() where T::method(..) -> (): Send {} LL + fn bay_path<T: Trait>() where T::method(..): Send {} | ```
2025-02-28Remove `NtMeta`.Nicholas Nethercote-1/+1
Note: there was an existing code path involving `Interpolated` in `MetaItem::from_tokens` that was dead. This commit transfers that to the new form, but puts an `unreachable!` call inside it.
2025-02-25Teach structured errors to display short `Ty`Esteban Küber-1/+0
Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to. ``` error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)`` --> long.rs:7:5 | 6 | fn foo(x: D) { //~ `x` has type `(... | - `x` has type `((..., ..., ..., ...), ..., ..., ...)` 7 | x(); //~ ERROR expected function, found `(... | ^-- | | | call expression requires function | = note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt' = note: consider using `--verbose` to print the full type name to the console ```
2025-02-15Try to recover from path sep error in parseryukang-8/+0
2025-02-08Rustfmtbjorn3-32/+44
2025-01-28Rollup merge of #133151 - tyrone-wu:trim-fn-ptr-whitespace, r=compiler-errorsMatthias Krüger-2/+4
Trim extra whitespace in fn ptr suggestion span Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type. Fixes: #133083 --- I made a comment about the format of the diagnostic error message in https://github.com/rust-lang/rust/issues/133083#issuecomment-2480047875. I think the `.label` may be a little redundant if the diagnostic only highlights the bad qualifier instead of the entire `TyKind::BareFn` span. If it makes sense, I can include it in this PR.
2025-01-27Trim extra whitespace in fn ptr suggestion spanTyrone Wu-2/+4
Trim extra whitespace when suggesting removal of invalid qualifiers when parsing function pointer type. Fixes: #133083 Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
2025-01-27Use identifiers in diagnostics more oftenMichael Goulet-1/+1
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-09Introduce `default_field_values` featureEsteban Küber-8/+0
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-04Fix suggestion when shorthand self has erroneous typeMichael Goulet-0/+19
2024-11-30Eliminate magic numbers from expression precedenceDavid Tolnay-1/+2
2024-11-28Rollup merge of #133560 - clubby789:mut-mut-space, r=jieyouxuGuillaume Gomez-1/+2
Trim extra space in 'repeated `mut`' diagnostic Trim an extra space when removing repeated `mut`. Also an extra test for even more repeated `mut`s
2024-11-28Trim extra space in 'repeated `mut`' diagnosticclubby789-1/+2
2024-11-25fix confusing diagnostic for reserved `##`Peter Jaszkowiak-0/+9
2024-11-21Add metavariables to `TokenDescription`.Nicholas Nethercote-2/+26
Pasted metavariables are wrapped in invisible delimiters, which pretty-print as empty strings, and changing that can break some proc macros. But error messages saying "expected identifer, found ``" are bad. So this commit adds support for metavariables in `TokenDescription` so they print as "metavariable" in error messages, instead of "``". It's not used meaningfully yet, but will be needed to get rid of interpolated tokens.
2024-11-15Trim whitespace in RemoveLet primary spanTyrone Wu-1/+2
Separate `RemoveLet` span into primary span for `let` and removal suggestion span for `let `, so that primary span does not include whitespace. Fixes: #133031 Signed-off-by: Tyrone Wu <wudevelops@gmail.com>
2024-10-30Enforce that raw lifetime identifiers must be valid raw identifiersMichael Goulet-0/+8
2024-10-12Rollup merge of #130870 - surechen:fix_130791, r=compiler-errorsTrevor Gross-0/+8
Add suggestion for removing invalid path sep `::` in fn def Add suggestion for removing invalid path separator `::` in function definition. for example: `fn invalid_path_separator::<T>() {}` fixes #130791
2024-10-08Reserve guarded string literals (RFC 3593)Peter Jaszkowiak-0/+18
2024-10-06On function and method calls in patterns, link to the bookEsteban Küber-0/+1
``` error: expected a pattern, found an expression --> f889.rs:3:13 | 3 | let (x, y.drop()) = (1, 2); //~ ERROR | ^^^^^^^^ not a pattern | = note: arbitrary expressions are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> error[E0532]: expected a pattern, found a function call --> f889.rs:2:13 | 2 | let (x, drop(y)) = (1, 2); //~ ERROR | ^^^^ not a tuple struct or tuple variant | = note: function calls are not allowed in patterns: <https://doc.rust-lang.org/book/ch18-00-patterns.html> ``` Fix #97200.
2024-10-02Rollup merge of #130725 - GrigorenkoPV:@-in-struct-patterns, r=NadrierilJubilee-0/+19
Parser: better error messages for `@` in struct patterns
2024-09-27Add suggestion for removing invalid path separator `::` in function definition.surechen-0/+8
for example: `fn invalid_path_separator::<T>() {}` fixes: #130791