Skip to content

Improve diagnostics for suggestions of unstable items - #161943

Open
KevinA-cpu wants to merge 7 commits into
rust-lang:mainfrom
KevinA-cpu:rustc-diagnostics-unstable-and-intrinsics-suggestions
Open

KevinA-cpu wants to merge 7 commits into
rust-lang:mainfrom
KevinA-cpu:rustc-diagnostics-unstable-and-intrinsics-suggestions

Conversation

@KevinA-cpu

@KevinA-cpu KevinA-cpu commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

  • Add a note for unstable suggestions
  • Only suggest intrinsics when the core_intrinsics feature is enabled

r? @JonathanBrouwer

Related:
Started from issue #78130
Created PR #161540 for regression tests
Then move to this PR for improvement points

@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 Aug 28, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors try jobs=x86_64-gnu-stable

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 31, 2026
…rinsics-suggestions, r=<try>

Improve rustc diagnostics


try-job: x86_64-gnu-stable
LL | let _: BorrowedBuf;
| ^^^^^^^^^^^ not found in this scope
|
= note: 'std::io::BorrowedBuf' is unstable in nightly Rust and is only available with the `#![feature(core_io_borrowed_buf)]` attribute

@JonathanBrouwer JonathanBrouwer Aug 31, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you place the note below the help: consider importing this struct? That improves the reading order

View changes since the review

@KevinA-cpu KevinA-cpu Sep 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I want to clarify @JonathanBrouwer, do you want to reorder so that the note is below the help universally, or do you only want this particular new note we're adding to be below the help?

Below is an example where a note above the help might be more useful:

= note: 'std::convert::TryFrom' is included in the prelude starting in Edition 2021
help: consider importing this trait

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean I want the note to be under the help universally.
The idea being that we first tell the user "you might have meant x" then "by the way, x is unstable". If you start with "x is unstable" its not obvious why the compiler is telling us that until you read the next sentence

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The note is still above the help.

That is, I want

error[E0425]: cannot find type `BorrowedBuf` in this scope
  --> $DIR/import-suggestion-unstable-feature-note.rs:9:12
   |
LL |     let _: BorrowedBuf;
   |            ^^^^^^^^^^^ not found in this scope
   |
   = note: 'std::io::BorrowedBuf' is unstable, add `#![feature(core_io_borrowed_buf)]` to the crate attributes to enable
help: consider importing this struct
   |
LL + use std::io::BorrowedBuf;
   |

To change to (approximately)

error[E0425]: cannot find type `BorrowedBuf` in this scope
  --> $DIR/import-suggestion-unstable-feature-note.rs:9:12
   |
LL |     let _: BorrowedBuf;
   |            ^^^^^^^^^^^ not found in this scope
   |
help: consider importing this struct
   |
LL + use std::io::BorrowedBuf;
   |
note: 'std::io::BorrowedBuf' is unstable, add `#![feature(core_io_borrowed_buf)]` to the crate attributes to enable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I noticed you implemented this universally, for all suggestions. I intended to limit this to only this specific diagnostic, this seems like quite a big change for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yep, I got confused by

I mean I want the note to be under the help universally.

I will revert most of the changes, LOL

@JonathanBrouwer JonathanBrouwer Nov 2, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I'm sorry, the way I answered that is indeed confusing, I misunderstood your question. I meant for all places where this diagnostic is emitted

@KevinA-cpu KevinA-cpu Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So from my efforts and investigate, it looks like it won't be a small change to try and make the note of this diagnostics to be below the help.

The emitter in compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs always prints every child (note/help added with err.note etc.) before every suggestion. So to achieve the order you're looking for it would require new mechanism and thus change alot of ui tests. (or making this help not a suggestion)

Unless, do you have any suggestions (pun intended)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll take a look sometime in the next few days, thanks for trying!

@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 Aug 31, 2026
@rustbot

rustbot commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@JonathanBrouwer JonathanBrouwer changed the title Improve rustc diagnostics Improve diagnostics for suggestions of unstable items Aug 31, 2026
@rust-bors

rust-bors Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: c00b75b (c00b75bd88d2b929fd91c696b206b37c632003e0)
Base parent: 0dfb098 (0dfb098f3aeecbe38c2566ca090193280e7349e7)

@JonathanBrouwer

Copy link
Copy Markdown
Member

@rustbot ready

@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 Oct 6, 2026
@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 Oct 7, 2026
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@KevinA-cpu
KevinA-cpu force-pushed the rustc-diagnostics-unstable-and-intrinsics-suggestions branch from a7202d8 to df6364a Compare October 12, 2026 09:21
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Member

Fyi I'm on holidays (at Eurorust) this week I'll get to any review next week

@KevinA-cpu

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 14, 2026
@KevinA-cpu
KevinA-cpu force-pushed the rustc-diagnostics-unstable-and-intrinsics-suggestions branch from 1029dfb to 12923c0 Compare November 1, 2026 07:59
@rustbot

rustbot commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

rustc_errors::annotate_snippet_emitter_writer was changed

cc @Muscraft

@rustbot

This comment has been minimized.

@KevinA-cpu
KevinA-cpu force-pushed the rustc-diagnostics-unstable-and-intrinsics-suggestions branch from 12923c0 to 23c5065 Compare November 1, 2026 09:14
@rustbot

This comment has been minimized.

@rustbot

rustbot commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Nov 1, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@KevinA-cpu
KevinA-cpu force-pushed the rustc-diagnostics-unstable-and-intrinsics-suggestions branch from bc001e2 to e0719a1 Compare November 2, 2026 02:39
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@KevinA-cpu
KevinA-cpu force-pushed the rustc-diagnostics-unstable-and-intrinsics-suggestions branch from 870fc09 to e43ff05 Compare November 2, 2026 07:30
@rustbot

rustbot commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

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.

@rust-log-analyzer

This comment has been minimized.

@KevinA-cpu
KevinA-cpu force-pushed the rustc-diagnostics-unstable-and-intrinsics-suggestions branch from 086bf56 to 63763a9 Compare November 2, 2026 11:26
@JonathanBrouwer

Copy link
Copy Markdown
Member

@rustbot ready

@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 Nov 7, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. 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.

4 participants