Skip to content

chore: Improve how the other suggestions message gets rendered #143661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2025

Conversation

Muscraft
Copy link
Member

@Muscraft Muscraft commented Jul 9, 2025

Note: This change is part of my ongoing work to use annotate-snippets as rustc's emitter

This change started as a way to remove some specialty code paths from annotate-snippets, by making the "and {} other candidates" message get rendered like a secondary message with no level, but turned into a fix for the message's Unicode output. Before this change, when using the Unicode output, the other suggestions message would get rendered outside of the main suggestion block, making it feel disconnected from what it was referring to. This change makes it so that the message is on the last line of the block, aligning its rendering with other secondary messages, and making it clear what the message is referring to.

Before:

error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   ╰╴
     and 9 other candidates

After:

error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   │
   ╰ and 9 other candidates

@rustbot
Copy link
Collaborator

rustbot commented Jul 9, 2025

r? @compiler-errors

rustbot has assigned @compiler-errors.
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. labels Jul 9, 2025
Comment on lines 1 to 2
//@ revisions: ascii unicode
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode
Copy link
Member

@jieyouxu jieyouxu Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: maybe use e.g. a copy of this test for diagnostics emitter testing? This const-generics test AFAICT is a regression test (for a previous ICE), I feel like it probably shouldn't be dual-serving as diagnostics emitter testing, as there are two different test intentions? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a very good point. I had not considered why a test exists when choosing one. I agree that it shouldn't serve the role of a regression test and a diagnostic emitter test. Looking at the other available tests, tests/ui/suggestions/too-many-field-suggestions.stderr looks to be the best candidate, but I would be happy to create a dedicated test if that is better.

Copy link
Member

@jieyouxu jieyouxu Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a dedicated test for this specific purpose is probably best, even if superficially it looks like an exact copy of another test, because even that test looks like it has a different test intention (of suggestions for field suggestions). But a test comment would clarify that so.

In that, for the intentions of this PR, the actual "error" doesn't matter as much as the suggestion format itself :)

@Muscraft Muscraft force-pushed the other-suggestion-message branch 2 times, most recently from 2230273 to 0043854 Compare July 9, 2025 13:14
@Muscraft Muscraft force-pushed the other-suggestion-message branch from 0043854 to d67bf60 Compare July 10, 2025 14:00
Comment on lines +1 to +10
error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
╭▸ $DIR/multi-suggestion.rs:17:13
LL │ let _ = std::collections::HashMap();
│ ━━━━━━━━━━━━━━━━━━━━━━━━━━━
╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
╰ note: `std::collections::HashMap` defined here
╰╴
help: you might have meant to use an associated function to build this type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. This seems to be a mild render bug for the unicode output.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this should have been

error[E0423]: expected function, tuple struct or tuple variant, found struct `std::collections::HashMap`
   ╭▸ $DIR/multi-suggestion.rs:17:13
   │
LL │     let _ = std::collections::HashMap();
   ╰╴            ━━━━━━━━━━━━━━━━━━━━━━━━━━━
   ╭▸ $SRC_DIR/std/src/collections/hash/map.rs:LL:COL
   │
   ╰ note: `std::collections::HashMap` defined here
help: you might have meant to use an associated function to build this type

Pre-existing. The logic for "couldn't find span" predates the unicode output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct that the logic for "couldn't find span" is the cause of the odd output here. I have a commit locally that changes how it is rendered to resemble what you expected it to be.

@estebank
Copy link
Contributor

r? @estebank
@bors r+

@bors
Copy link
Collaborator

bors commented Jul 11, 2025

📌 Commit d67bf60 has been approved by estebank

It is now in the queue for this repository.

@rustbot rustbot assigned estebank and unassigned compiler-errors Jul 11, 2025
@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 Jul 11, 2025
bors added a commit that referenced this pull request Jul 11, 2025
Rollup of 8 pull requests

Successful merges:

 - #142391 (rust: library: Add `setsid` method to `CommandExt` trait)
 - #143302 (`tests/ui`: A New Order [27/N])
 - #143303 (`tests/ui`: A New Order [28/28] FINAL PART)
 - #143568 (std: sys: net: uefi: tcp4: Add timeout support)
 - #143611 (Mention more APIs in `ParseIntError` docs)
 - #143661 (chore: Improve how the other suggestions message gets rendered)
 - #143708 (fix: Include frontmatter in -Zunpretty output )
 - #143718 (Make UB transmutes really UB in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 11, 2025
Rollup of 8 pull requests

Successful merges:

 - #142391 (rust: library: Add `setsid` method to `CommandExt` trait)
 - #143302 (`tests/ui`: A New Order [27/N])
 - #143303 (`tests/ui`: A New Order [28/28] FINAL PART)
 - #143568 (std: sys: net: uefi: tcp4: Add timeout support)
 - #143611 (Mention more APIs in `ParseIntError` docs)
 - #143661 (chore: Improve how the other suggestions message gets rendered)
 - #143708 (fix: Include frontmatter in -Zunpretty output )
 - #143718 (Make UB transmutes really UB in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 11, 2025
Rollup of 8 pull requests

Successful merges:

 - #142391 (rust: library: Add `setsid` method to `CommandExt` trait)
 - #143302 (`tests/ui`: A New Order [27/N])
 - #143303 (`tests/ui`: A New Order [28/28] FINAL PART)
 - #143568 (std: sys: net: uefi: tcp4: Add timeout support)
 - #143611 (Mention more APIs in `ParseIntError` docs)
 - #143661 (chore: Improve how the other suggestions message gets rendered)
 - #143708 (fix: Include frontmatter in -Zunpretty output )
 - #143718 (Make UB transmutes really UB in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: i686-gnu-nopt-1
try-job: test-various
bors added a commit that referenced this pull request Jul 11, 2025
Rollup of 8 pull requests

Successful merges:

 - #142391 (rust: library: Add `setsid` method to `CommandExt` trait)
 - #143302 (`tests/ui`: A New Order [27/N])
 - #143303 (`tests/ui`: A New Order [28/28] FINAL PART)
 - #143568 (std: sys: net: uefi: tcp4: Add timeout support)
 - #143611 (Mention more APIs in `ParseIntError` docs)
 - #143661 (chore: Improve how the other suggestions message gets rendered)
 - #143708 (fix: Include frontmatter in -Zunpretty output )
 - #143718 (Make UB transmutes really UB in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: i686-gnu-nopt-1
try-job: test-various
bors added a commit that referenced this pull request Jul 12, 2025
Rollup of 8 pull requests

Successful merges:

 - #142391 (rust: library: Add `setsid` method to `CommandExt` trait)
 - #143302 (`tests/ui`: A New Order [27/N])
 - #143303 (`tests/ui`: A New Order [28/28] FINAL PART)
 - #143568 (std: sys: net: uefi: tcp4: Add timeout support)
 - #143611 (Mention more APIs in `ParseIntError` docs)
 - #143661 (chore: Improve how the other suggestions message gets rendered)
 - #143708 (fix: Include frontmatter in -Zunpretty output )
 - #143718 (Make UB transmutes really UB in LLVM)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: i686-gnu-nopt-1
try-job: test-various
@bors bors merged commit 140f2fa into rust-lang:master Jul 12, 2025
11 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 12, 2025
rust-timer added a commit that referenced this pull request Jul 12, 2025
Rollup merge of #143661 - Muscraft:other-suggestion-message, r=estebank

chore: Improve how the other suggestions message gets rendered

Note: This change is part of my ongoing work to use `annotate-snippets` as `rustc`'s emitter

This change started as a way to remove some specialty code paths from `annotate-snippets`, by making the "and {} other candidates" message get rendered like a secondary message with no level, but turned into a fix for the message's Unicode output. Before this change, when using the Unicode output, the other suggestions message would get rendered outside of the main suggestion block, making it feel disconnected from what it was referring to. This change makes it so that the message is on the last line of the block, aligning its rendering with other secondary messages, and making it clear what the message is referring to.

Before:
```
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   ╰╴
     and 9 other candidates
```

After:
```
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   │
   ╰ and 9 other candidates
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants