about summary refs log tree commit diff
path: root/tests/ui/parser
AgeCommit message (Collapse)AuthorLines
2024-01-11Silence follow up errors if astconv already erroredOli Scherer-15/+3
2024-01-09Avoid silencing relevant follow-up errorsOli Scherer-3/+21
2024-01-08Emit suggestion when trying to write exclusive ranges as `..<`sjwang05-0/+89
2024-01-05Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkinbors-7/+7
Merge `unused_tuple_struct_fields` into `dead_code` This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group. [Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-04Rollup merge of #119397 - ShE3py:pat-range-paren-recovery, r=fmeaseMatthias Krüger-0/+69
Recover parentheses in range patterns Before: ```rs match n { (0).. => (), _ => () } ``` ``` error: expected one of `=>`, `if`, or `|`, found `..` --> src/lib.rs:3:12 | 3 | (0).. => (), | ^^ expected one of `=>`, `if`, or `|` ``` After: ``` error: range pattern bounds cannot have parentheses --> main.rs:3:5 | 3 | (0).. => (), | ^ ^ | help: remove these parentheses | 3 - (0).. => (), 3 + 0.. => (), | ``` This sets the groundwork for #118625, which will extend the recovery to expressions like `(0 + 1)..` where users may tend to add parentheses to avoid dealing with precedence. --- ```@rustbot``` label +A-parser +A-patterns +A-diagnostics
2024-01-04macro_rules: Less hacky heuristic for using `tt` metavariable spansVadim Petrochenkov-6/+6
2024-01-03Rollup merge of #119505 - fmease:no-host-param-for-trait-fns, r=fee1-deadLeón Orell Valerian Liehr-8/+20
Don't synthesize host effect params for trait associated functions marked const Fixes #113378. r? fee1-dead or compiler
2024-01-03Rollup merge of #119494 - fmease:deny-hr-param-defaults, r=compiler-errorsLeón Orell Valerian Liehr-7/+10
Deny defaults for higher-ranked generic parameters Fixes #119489 (incl. https://github.com/rust-lang/rust/issues/119489#issuecomment-1873399208). Partially reverts #119042. cc ```@bvanjoi``` r? ```@compiler-errors``` or compiler
2024-01-03Recover parentheses in range patternsLieselotte-0/+69
Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-01-02Adjust compiler tests for unused_tuple_struct_fields -> dead_codeJake Goulding-7/+7
2024-01-02E0379: Provide suggestionsLeón Orell Valerian Liehr-4/+16
2024-01-02E0379: Make diagnostic more preciseLeón Orell Valerian Liehr-6/+6
2024-01-01Deny defaults for higher-ranked generic parametersLeón Orell Valerian Liehr-7/+10
2023-12-28Don't expect bodyless arms if the pattern can never be a never patternLieselotte-19/+19
2023-12-27Auto merge of #119099 - fmease:always-const-trait-bounds, r=fee1-deadbors-4/+27
Introduce `const Trait` (always-const trait bounds) Feature `const_trait_impl` currently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (\*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to the `effects` backbone. Not sure if this needs t-lang sign-off though. (\*): ```rs #![feature(const_trait_impl, effects, generic_const_exprs)] fn compute<T: const Trait>() -> Type<{ T::generate() }> { /*…*/ } struct Store<T: const Trait> where Type<{ T::generate() }>:, { field: Type<{ T::generate() }>, } ``` Lastly, “always const” trait bounds are a perfect fit for `generic_const_items`. ```rs #![feature(const_trait_impl, effects, generic_const_items)] const DEFAULT<T: const Default>: T = T::default(); ``` Previously, we (oli, fee1-dead and I) wanted to reinterpret `~const Trait` as `const Trait` in generic const items which would've been quite surprising and not very generalizable. Supersedes #117530. --- cc `@oli-obk` As discussed r? fee1-dead (or compiler)
2023-12-27Auto merge of #117303 - sjwang05:issue-117245, r=estebankbors-0/+196
Suggest `=>` --> `>=` in comparisons Fixes #117245
2023-12-27Introduce `const Trait` (always-const trait bounds)León Orell Valerian Liehr-4/+27
2023-12-26Suggest `=>` --> `>=` in conditionssjwang05-0/+196
2023-12-26fallback `default` to `None` during ast-loweing for lifetime binderbohan-0/+7
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