about summary refs log tree commit diff
path: root/tests/ui/parser
AgeCommit message (Collapse)AuthorLines
2023-12-21Simple modification of diagnostic informationsurechen-2/+2
fixes #119067
2023-12-18Auto merge of #117818 - fmease:properly-reject-defaultness-on-free-consts, ↵bors-8/+36
r=cjgillot Properly reject `default` on free const items Fixes #117791. Technically speaking, this is a breaking change but I doubt it will lead to any real-world regressions (maybe in some macro-trickery crates?). Doing a crater run probably isn't worth it.
2023-12-14Change expr_trailing_brace to an exhaustive match to force new expression ↵GearsDatapacks-0/+396
kinds to specify whether they contain a brace Add inline const and other possible curly brace expressions to expr_trailing_brace Add tests for `}` before `else` in `let...else` error Change to explicit cases for expressions with optional values when being checked for trailing braces Add tests for more complex cases of `}` before `else` in `let..else` statement Move other possible `}` cases into separate arm and add FIXME for future reference
2023-12-12Rollup merge of #118868 - Nadrieril:correctly-gate-never_patterns-parsing, ↵Matthias Krüger-13/+5
r=petrochenkov Correctly gate the parsing of match arms without body https://github.com/rust-lang/rust/pull/118527 accidentally allowed the following to parse on stable: ```rust match Some(0) { None => { foo(); } #[cfg(FALSE)] Some(_) } ``` This fixes that oversight. The way I choose which error to emit is the best I could think of, I'm open if you know a better way. r? `@petrochenkov` since you're the one who noticed
2023-12-12Correctly gate the parsing of match arms without bodyNadrieril-13/+5
2023-12-12Improve an error involving attribute values.Nicholas Nethercote-12/+28
Attribute values must be literals. The error you get when that doesn't hold is pretty bad, e.g.: ``` unexpected expression: 1 + 1 ``` You also get the same error if the attribute value is a literal, but an invalid literal, e.g.: ``` unexpected expression: "foo"suffix ``` This commit does two things. - Changes the error message to "attribute value must be a literal", which gives a better idea of what the problem is and how to fix it. It also no longer prints the invalid expression, because the carets below highlight it anyway. - Separates the "not a literal" case from the "invalid literal" case. Which means invalid literals now get the specific error at the literal level, rather than at the attribute level.
2023-12-08Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errorsbors-22/+229
never_patterns: Parse match arms with no body Never patterns are meant to signal unreachable cases, and thus don't take bodies: ```rust let ptr: *const Option<!> = ...; match *ptr { None => { foo(); } Some(!), } ``` This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser). ~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit r? `@compiler-errors`
2023-12-05Rollup merge of #118585 - sjwang05:issue-118564, r=compiler-errorsMichael Goulet-1/+11
Fix parser ICE when recovering `dyn`/`impl` after `for<...>` Fixes #118564
2023-12-05Rollup merge of #117922 - estebank:unclosed-generics, r=b-naberMatthias Krüger-6/+4
Tweak unclosed generics errors Remove unnecessary span label for parse errors that already have a suggestion. Provide structured suggestion to close generics in more cases.
2023-12-04Fix parser ICE when recovering `dyn`/`impl` after `for<...>`sjwang05-1/+11
2023-12-03Disallow an arm without a body (except for never patterns)Nadrieril-7/+86
Parsing now accepts a match arm without a body, so we must make sure to only accept that if the pattern is a never pattern.
2023-12-03Detect attempts to expand a macro to a match arm againNadrieril-0/+2
Because a macro invocation can expand to a never pattern, we can't rule out a `arm!(),` arm at parse time. Instead we detect that case at expansion time, if the macro tries to output a pattern followed by `=>`.
2023-12-03Parse a pattern with no armNadrieril-103/+39
2023-12-03Auto merge of #118542 - chenyukang:yukang-fix-parser-ice-118531, r=cjgillotbors-0/+106
Fix parser ICE from attrs Fixes #118531, Fixes #118530.
2023-12-02Fix parser ICE from attrsyukang-0/+106
2023-12-02Add testsNadrieril-0/+190
2023-12-01Tweak unclosed generics errorsEsteban Küber-6/+4
Remove unnecessary span label for parse errors that already have a suggestion. Provide structured suggestion to close generics in more cases.
2023-11-29Always emit help when failing to parse enum variantEsteban Küber-0/+4
2023-11-29Fix tidyEsteban Küber-2/+15
2023-11-29Fix test and move to more appropriate directoryEsteban Küber-37/+63
2023-11-29Change how `for (x in foo) {}` is handledEsteban Küber-11/+62
Use the same approach used for match arm patterns.
2023-11-29Account for `(pat if expr) => {}`Esteban Küber-8/+25
When encountering match arm (pat if expr) => {}, recover and suggest removing parentheses. Fix #100825.
2023-11-29Change enum parse recoveryEsteban Küber-13/+9
2023-11-29Bubble parse error when expecting `)`Esteban Küber-37/+20
2023-11-29More accurate span for unnecessary parens suggestionEsteban Küber-1/+1
2023-11-29When parsing patterns, bubble all errors except reserved idents that aren't ↵Esteban Küber-2/+40
likely to appear in for head or match arm
2023-11-29Make `parse_pat_ident` not recover bad nameEsteban Küber-104/+7
2023-11-24Show number in error message even for one errorNilstrieb-386/+386
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-19Rollup merge of #117988 - estebank:issue-106020, r=cjgillotMichael Goulet-0/+73
Handle attempts to have multiple `cfg`d tail expressions When encountering code that seems like it might be trying to have multiple tail expressions depending on `cfg` information, suggest alternatives that will success to parse. ```rust fn foo() -> String { #[cfg(feature = "validation")] [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() #[cfg(not(feature = "validation"))] String::new() } ``` ``` error: expected `;`, found `#` --> $DIR/multiple-tail-expr-behind-cfg.rs:5:64 | LL | #[cfg(feature = "validation")] | ------------------------------ only `;` terminated statements or tail expressions are allowed after this attribute LL | [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() | ^ expected `;` here LL | #[cfg(not(feature = "validation"))] | - unexpected token | help: add `;` here | LL | [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>(); | + help: alternatively, consider surrounding the expression with a block | LL | { [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() } | + + help: it seems like you are trying to provide different expressions depending on `cfg`, consider using `if cfg!(..)` | LL ~ if cfg!(feature = "validation") { LL ~ [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() LL ~ } else if cfg!(not(feature = "validation")) { LL ~ String::new() LL + } | ``` Fix #106020. r? `@oli-obk`
2023-11-19Rollup merge of #117891 - compiler-errors:recover-for-dyn, r=davidtwcoMichael Goulet-0/+35
Recover `dyn` and `impl` after `for<...>` Recover `dyn` and `impl` after `for<...>` in types. Reuses the logic for parsing bare trait objects, so it doesn't fix cases like `for<'a> dyn Trait + dyn Trait` or anything, but that seems somewhat of a different issue. Parsing recovery logic is a bit involved, but I couldn't find a way to simplify it. Fixes #117882
2023-11-19Don't sort `span_suggestions`, leave that to callerEsteban Küber-4/+4
2023-11-19Rollup merge of #117110 - estebank:deref-field-suggestion, r=b-naberTakayuki Maeda-3/+3
Suggest field typo through derefs Take into account implicit dereferences when suggesting fields. ``` error[E0609]: no field `longname` on type `Arc<S>` --> $DIR/suggest-field-through-deref.rs:10:15 | LL | let _ = x.longname; | ^^^^^^^^ help: a field with a similar name exists: `long_name` ``` CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-17Auto merge of #118023 - matthiaskrgr:rollup-i9skwic, r=matthiaskrgrbors-1/+0
Rollup of 7 pull requests Successful merges: - #117338 (Remove asmjs) - #117549 (Use `copied` instead of manual `map`) - #117745 (Emit smir) - #117964 (When using existing fn as module, don't claim it doesn't exist) - #118006 (clarify `fn discriminant` guarantees: only free lifetimes may get erased) - #118016 (Add stable mir members to triagebot config) - #118022 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-17Rollup merge of #117338 - workingjubilee:asmjs-meets-thanatos, r=b-naberMatthias Krüger-1/+0
Remove asmjs Fulfills [MCP 668](https://github.com/rust-lang/compiler-team/issues/668). `asmjs-unknown-emscripten` does not work as-specified, and lacks essential upstream support for generating asm.js, so it should not exist at all.
2023-11-17Auto merge of #114292 - estebank:issue-71039, r=b-naberbors-4/+4
More detail when expecting expression but encountering bad macro argument On nested macro invocations where the same macro fragment changes fragment type from one to the next, point at the chain of invocations and at the macro fragment definition place, explaining that the change has occurred. Fix #71039. ``` error: expected expression, found pattern `1 + 1` --> $DIR/trace_faulty_macros.rs:49:37 | LL | (let $p:pat = $e:expr) => {test!(($p,$e))}; | ------- -- this is interpreted as expression, but it is expected to be pattern | | | this macro fragment matcher is expression ... LL | (($p:pat, $e:pat)) => {let $p = $e;}; | ------ ^^ expected expression | | | this macro fragment matcher is pattern ... LL | test!(let x = 1+1); | ------------------ | | | | | this is expected to be expression | in this macro invocation | = note: when forwarding a matched fragment to another macro-by-example, matchers in the second macro will see an opaque AST of the fragment type, not the underlying tokens = note: this error originates in the macro `test` (in Nightly builds, run with -Z macro-backtrace for more info) ```
2023-11-17Rollup merge of #117990 - estebank:issue-100825-part-deux, r=NilstriebMatthias Krüger-5/+68
Tweak error and move tests r? `@Nilstrieb` Split off #117565.
2023-11-16Fix code indentationEsteban Küber-1/+1
2023-11-16Handle attempts to have multiple `cfg`d tail expressionsEsteban Küber-0/+73
When encountering code that seems like it might be trying to have multiple tail expressions depending on `cfg` information, suggest alternatives that will success to parse. ```rust fn foo() -> String { #[cfg(feature = "validation")] [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() #[cfg(not(feature = "validation"))] String::new() } ``` ``` error: expected `;`, found `#` --> $DIR/multiple-tail-expr-behind-cfg.rs:5:64 | LL | #[cfg(feature = "validation")] | ------------------------------ only `;` terminated statements or tail expressions are allowed after this attribute LL | [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() | ^ expected `;` here LL | #[cfg(not(feature = "validation"))] | - unexpected token | help: add `;` here | LL | [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>(); | + help: alternatively, consider surrounding the expression with a block | LL | { [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() } | + + help: it seems like you are trying to provide different expressions depending on `cfg`, consider using `if cfg!(..)` | LL ~ if cfg!(feature = "validation") { LL ~ [1, 2, 3].iter().map(|c| c.to_string()).collect::<String>() LL ~ } else if cfg!(not(feature = "validation")) { LL ~ String::new() LL + } | ``` Fix #106020.
2023-11-16recover primary span labelEsteban Küber-11/+11
2023-11-16Suggest field typo through derefsEsteban Küber-8/+8
Take into account implicit dereferences when suggesting fields. ``` error[E0609]: no field `longname` on type `Arc<S>` --> $DIR/suggest-field-through-deref.rs:10:15 | LL | let _ = x.longname; | ^^^^^^^^ help: a field with a similar name exists: `long_name` ``` CC https://github.com/rust-lang/rust/issues/78374#issuecomment-719564114
2023-11-16Add test for parens around match arm pattern and conditionEsteban Küber-0/+63
2023-11-16Smaller span for unnessary `mut` suggestionEsteban Küber-5/+5
2023-11-16Move tests to subdirectoryEsteban Küber-0/+0
2023-11-16More detail when expecting expression but encountering bad macro argumentEsteban Küber-4/+4
Partially address #71039.
2023-11-14Detect more `=>` typosEsteban Küber-0/+39
Handle and recover `match expr { pat >= { arm } }`.
2023-11-14Recover `dyn` and `impl` after `for<...>`Michael Goulet-0/+35
2023-11-13Auto merge of #117770 - sjwang05:issue-117766, r=estebank,TaKO8Kibors-0/+123
Catch stray `{` in let-chains Fixes #117766
2023-11-11Move unclosed delim errors to separate functionsjwang05-10/+4
2023-11-11Reject defaultness on free constsLeón Orell Valerian Liehr-8/+36
2023-11-10Correctly handle while-let-chainssjwang05-2/+49