Repository navigation
Trigger "C array" parse error recovery in far fewer cases - #162705
Conversation
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
I'm personally of the opinion that more tests are always better than fewer tests, I'm wondering what your reasoning is there. r=me with a regression test |
|
This PR was the result of a side quest of a side quest of a side quest while I was on a cleanup spree in the parser axing things left & right, so I just didn't feel like adding any code / creating patches where lines added >= lines removed :D |
eb2d4a7 to
8a0a23d
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Test cases added to the existing test file. @bors r=JonathanBrouwer rollup |
Previously we would trigger on
1. `unsafe { 1, 2, 3 }` and suggest `[ { 1, 2, 3 ]` (sic!)
2. `'label: { 1, 2, 3 }` and suggest `[: { 1, 2, 3 ]` (sic!)
3. `X::<{ 1, 2, 3 }>` and suggest `X::<[ 1, 2, 3]>` (wrong)
4. `|| -> i32 { 1, 2, 3 }` and suggest `|| -> i32 [ 1, 2, 3 ]` (wrong)
5. `await { 1, 2, 3 }` and suggest `await [ 1, 2, 3 ]` (wrong)
Moreover, stop looking for identifiers after the `{` as that case can no
longer be reached anyway as `maybe_recover_bad_struct_literal_path`
will always snatch it first.
…nBrouwer
Trigger "C array" parse error recovery in far fewer cases
Previously we would trigger on
1. `unsafe { 1, 2, 3 }` and suggest `[ { 1, 2, 3 ]` (sic!)
2. `'label: { 1, 2, 3 }` and suggest `[: { 1, 2, 3 ]` (sic!)
3. `X::<{ 1, 2, 3 }>` and suggest `X::<[ 1, 2, 3]>` (wrong)
4. `|| -> i32 { 1, 2, 3 }` and suggest `|| -> i32 [ 1, 2, 3 ]` (wrong)
5. `await { 1, 2, 3 }` and suggest `await [ 1, 2, 3 ]` (wrong)
Moreover, stop looking for identifiers after the `{` as that case can no longer be reached anyway as `maybe_recover_bad_struct_literal_path` will always snatch it first.
I haven't added any regression tests as I don't think it'd be worth it / proportionate (it's a niche parse error recovery gone awry in very odd cases). Let me know if you think otherwise.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
Rollup of 6 pull requests Successful merges: - #162228 (tests: Run more pauth tests in CI and make them pass) - #162990 (post GH comment on types nominations) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162988 (recover `true` and `false` in type position as `bool`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone)
…nBrouwer
Trigger "C array" parse error recovery in far fewer cases
Previously we would trigger on
1. `unsafe { 1, 2, 3 }` and suggest `[ { 1, 2, 3 ]` (sic!)
2. `'label: { 1, 2, 3 }` and suggest `[: { 1, 2, 3 ]` (sic!)
3. `X::<{ 1, 2, 3 }>` and suggest `X::<[ 1, 2, 3]>` (wrong)
4. `|| -> i32 { 1, 2, 3 }` and suggest `|| -> i32 [ 1, 2, 3 ]` (wrong)
5. `await { 1, 2, 3 }` and suggest `await [ 1, 2, 3 ]` (wrong)
Moreover, stop looking for identifiers after the `{` as that case can no longer be reached anyway as `maybe_recover_bad_struct_literal_path` will always snatch it first.
I haven't added any regression tests as I don't think it'd be worth it / proportionate (it's a niche parse error recovery gone awry in very odd cases). Let me know if you think otherwise.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
Rollup of 13 pull requests Successful merges: - #158515 (Make let-else respect macro_rules expr metavariable grouping) - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor) - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner) - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes) - #162990 (post GH comment on types nominations) - #154665 (add safety section for mem::zeroed) - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162988 (recover `true` and `false` in type position as `bool`) - #162995 (Constify `impl FromStr for NonZero<T>`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone)
…nBrouwer
Trigger "C array" parse error recovery in far fewer cases
Previously we would trigger on
1. `unsafe { 1, 2, 3 }` and suggest `[ { 1, 2, 3 ]` (sic!)
2. `'label: { 1, 2, 3 }` and suggest `[: { 1, 2, 3 ]` (sic!)
3. `X::<{ 1, 2, 3 }>` and suggest `X::<[ 1, 2, 3]>` (wrong)
4. `|| -> i32 { 1, 2, 3 }` and suggest `|| -> i32 [ 1, 2, 3 ]` (wrong)
5. `await { 1, 2, 3 }` and suggest `await [ 1, 2, 3 ]` (wrong)
Moreover, stop looking for identifiers after the `{` as that case can no longer be reached anyway as `maybe_recover_bad_struct_literal_path` will always snatch it first.
I haven't added any regression tests as I don't think it'd be worth it / proportionate (it's a niche parse error recovery gone awry in very odd cases). Let me know if you think otherwise.
<sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
…uwer Rollup of 15 pull requests Successful merges: - #158515 (Make let-else respect macro_rules expr metavariable grouping) - #162726 (std: fix unix socket address panic on a full sun_path) - #160028 (Better account for `Self` that might be a typo of `self`) - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor) - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner) - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes) - #162990 (post GH comment on types nominations) - #154665 (add safety section for mem::zeroed) - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162988 (recover `true` and `false` in type position as `bool`) - #162995 (Constify `impl FromStr for NonZero<T>`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone)
Rollup of 17 pull requests Successful merges: - #158515 (Make let-else respect macro_rules expr metavariable grouping) - #160028 (Better account for `Self` that might be a typo of `self`) - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor) - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner) - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes) - #162990 (post GH comment on types nominations) - #153662 (Suggest fully qualified path on method name collision) - #154665 (add safety section for mem::zeroed) - #159787 (Prefer ModId in more places) - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162988 (recover `true` and `false` in type position as `bool`) - #162995 (Constify `impl FromStr for NonZero<T>`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone) - #163039 (Use verbose suggestion for parenthetical `Fn` notation and fully-qualified path on ambiguous assoc item)
Rollup of 17 pull requests Successful merges: - #158515 (Make let-else respect macro_rules expr metavariable grouping) - #160028 (Better account for `Self` that might be a typo of `self`) - #160097 (fix const_item_mutation lint to use needs_drop instead of has_dtor) - #161435 (Provide a `supertrait_def_ids()` function in rustc_type_ir's interner) - #161894 (Do not suppress the fn item uniqueness note for late bound lifetimes) - #162990 (post GH comment on types nominations) - #153662 (Suggest fully qualified path on method name collision) - #154665 (add safety section for mem::zeroed) - #159787 (Prefer ModId in more places) - #162700 ( Remove incorrect parse error recovery code that mistakes `as` casts for the long removed type ascription) - #162705 (Trigger "C array" parse error recovery in far fewer cases) - #162875 (Add .seek_read_exact(), .seek_write_all() to std::os::windows::fs::FileExt) - #162988 (recover `true` and `false` in type position as `bool`) - #162995 (Constify `impl FromStr for NonZero<T>`) - #163006 (Use `end_point` for trailing brace in `let...else` diagnostics) - #163007 (add Dir::try_clone) - #163039 (Use verbose suggestion for parenthetical `Fn` notation and fully-qualified path on ambiguous assoc item)
Rollup merge of #162705 - fmease:fix-c-array-diag, r=JonathanBrouwer Trigger "C array" parse error recovery in far fewer cases Previously we would trigger on 1. `unsafe { 1, 2, 3 }` and suggest `[ { 1, 2, 3 ]` (sic!) 2. `'label: { 1, 2, 3 }` and suggest `[: { 1, 2, 3 ]` (sic!) 3. `X::<{ 1, 2, 3 }>` and suggest `X::<[ 1, 2, 3]>` (wrong) 4. `|| -> i32 { 1, 2, 3 }` and suggest `|| -> i32 [ 1, 2, 3 ]` (wrong) 5. `await { 1, 2, 3 }` and suggest `await [ 1, 2, 3 ]` (wrong) Moreover, stop looking for identifiers after the `{` as that case can no longer be reached anyway as `maybe_recover_bad_struct_literal_path` will always snatch it first. I haven't added any regression tests as I don't think it'd be worth it / proportionate (it's a niche parse error recovery gone awry in very odd cases). Let me know if you think otherwise. <sub>(No LLM was or will be used by me during the entire creation process of this PR)</sub>
Previously we would trigger on
unsafe { 1, 2, 3 }and suggest[ { 1, 2, 3 ](sic!)'label: { 1, 2, 3 }and suggest[: { 1, 2, 3 ](sic!)X::<{ 1, 2, 3 }>and suggestX::<[ 1, 2, 3]>(wrong)|| -> i32 { 1, 2, 3 }and suggest|| -> i32 [ 1, 2, 3 ](wrong)await { 1, 2, 3 }and suggestawait [ 1, 2, 3 ](wrong)Moreover, stop looking for identifiers after the
{as that case can no longer be reached anyway asmaybe_recover_bad_struct_literal_pathwill always snatch it first.I haven't added any regression tests as I don't think it'd be worth it / proportionate (it's a niche parse error recovery gone awry in very odd cases). Let me know if you think otherwise.
(No LLM was or will be used by me during the entire creation process of this PR)