Skip to content

Conversation

ShE3py
Copy link
Contributor

@ShE3py ShE3py commented Apr 25, 2024

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)

error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++

The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++

@rustbot label +A-suggestion-diagnostics

@rustbot
Copy link
Collaborator

rustbot commented Apr 25, 2024

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Apr 25, 2024
@fee1-dead
Copy link
Member

If two suggestions parts are side by side, the underline's offset: (WIP PR as an example, not yet pushed)

error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++

Please include this as an UI test.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 26, 2024
@ShE3py
Copy link
Contributor Author

ShE3py commented Apr 26, 2024

I'm still working on PR #123877 which makes this suggestion, here is the blessed UI tests after this PR: a580d10

The suggestion is emitted here:

err.subdiagnostic(&that.parser.dcx(), UnexpectedExpressionInPatternArmSugg::CreateGuard {
ident_span,
pat_hi: arm.pat.span.shrink_to_hi(),
ident,
expr: expr.clone(),
});

CreateGuard {
/// The span of the `PatKind:Err` to be transformed into a `PatKind::Ident`.
#[suggestion_part(code = "{ident}")]
ident_span: Span,
/// The end of the match arm's pattern.
#[suggestion_part(code = " if {ident} == {expr}")]
pat_hi: Span,
/// The suggested identifier.
ident: String,
/// `ident_span`'s snippet.
expr: String,
},

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 26, 2024
@fee1-dead
Copy link
Member

Alright, thanks!
@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Apr 27, 2024

📌 Commit b52e4bd has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 27, 2024
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 27, 2024
…=fee1-dead

Fix substitution parts having a shifted underline in some cases

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)
```
error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++
```
The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

```
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++
```

`@rustbot` label +A-suggestion-diagnostics
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
Rollup of 3 pull requests

Successful merges:

 - rust-lang#124370 (Fix substitution parts having a shifted underline in some cases)
 - rust-lang#124382 (ast: Generalize item kind visiting)
 - rust-lang#124387 (thread_local: be excruciatingly explicit in dtor code)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Collaborator

bors commented Apr 27, 2024

⌛ Testing commit b52e4bd with merge 35f5b73...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
…ee1-dead

Fix substitution parts having a shifted underline in some cases

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)
```
error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++
```
The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

```
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++
```

`@rustbot` label +A-suggestion-diagnostics
@bors
Copy link
Collaborator

bors commented Apr 27, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 27, 2024
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@fee1-dead
Copy link
Member

fee1-dead commented Apr 27, 2024

@bors retry: appears spurious

@fee1-dead
Copy link
Member

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 27, 2024
…=fee1-dead

Fix substitution parts having a shifted underline in some cases

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)
```
error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++
```
The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

```
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++
```

`@rustbot` label +A-suggestion-diagnostics
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#124370 (Fix substitution parts having a shifted underline in some cases)
 - rust-lang#124405 (miri core/alloc tests: do not test a 2nd target)
 - rust-lang#124425 (Do not ICE on invalid consts when walking mono-reachable blocks)
 - rust-lang#124435 (add more tests)
 - rust-lang#124437 (doc: Make the `mod.rs` in the comment point to the correct location)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#124370 (Fix substitution parts having a shifted underline in some cases)
 - rust-lang#124394 (Fix ICE on invalid const param types)
 - rust-lang#124425 (Do not ICE on invalid consts when walking mono-reachable blocks)
 - rust-lang#124434 (Remove lazycell and once_cell from compiletest dependencies)
 - rust-lang#124437 (doc: Make the `mod.rs` in the comment point to the correct location)
 - rust-lang#124443 (Elaborate in comment about `statx` probe)
 - rust-lang#124445 (bootstrap: Change `global(true)` to `global = true` for flags for consistency)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 52ce43e into rust-lang:master Apr 27, 2024
@rustbot rustbot added this to the 1.79.0 milestone Apr 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 27, 2024
Rollup merge of rust-lang#124370 - ShE3py:substitution-part-offset, r=fee1-dead

Fix substitution parts having a shifted underline in some cases

If two suggestions parts are side by side, the underline's offset:
(WIP PR as an example, not yet pushed)
```
error: expected a pattern, found an expression
 --> ./main.rs:4:9
  |
4 |         1 + 2 => 3
  |         ^^^^^ arbitrary expressions are not allowed in patterns
  |
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~     +++++++++++++
```
The emitter didn't take into account that the string had shrunk/grown if two substitution parts were side-by-side (surprisingly, there was only one case in the ui testsuite.)

```
help: check the value in an arm guard
  |
4 |         n if n == 1 + 2 => 3
  |         ~ +++++++++++++
```

``@rustbot`` label +A-suggestion-diagnostics
@ShE3py ShE3py deleted the substitution-part-offset branch May 3, 2025 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants