Skip to content
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

Allow using bool instead of Option<()> in diagnostics #108402

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

clubby789
Copy link
Contributor

@clubby789 clubby789 commented Feb 23, 2023

Disallow the unit type for #[help], #[note] etc, instead using bool to express optional annotations without a span which I believe is more intuitive.

Test output ordering has changed in a few places, where a field was of type () and the annotation has been moved to the struct itself. If any of these changes are an issue, this can be restricted to allowing specifically (), and not Option<()>

Actual changes here: https://github.com/rust-lang/rust/pull/108402/files#diff-815b1d8debfc564112bd51093791d7c3f2ee288a37a8f5c0e89c11d1f609b4c0

Allows using bool in derive diagnostics to indicate an optional subdiagnostic without a span, where previously Option<()> had to be used

@rustbot label +A-diagnostics

@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2023

r? @TaKO8Ki

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic 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 Feb 23, 2023
@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2023

Some changes occured in rustc_ty_utils::consts.rs

cc @BoxyUwU

rustc_macros::diagnostics was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 23, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Feb 23, 2023

Hm... I actually quite like () and Option<()>. They are good ways of indicating that the note will not be applied to a span, forming a parallel to Span and Option<Span>, and the overhead isn't that big when constructing them imo (for the latter, just appending .then_some(()))?

@clubby789
Copy link
Contributor Author

What do you think about reducing this PR to just allowing bool, and not changing existing diagnostics?

@WaffleLapkin
Copy link
Member

I was mildly annoyed by Option<()>s too (actually replacing them with bools was on my todo-list...), hm. Maybe we can add a special enum at least? Something like

pub enum ShowAnnotation { Show, Hide }

@davidtwco
Copy link
Member

What do you think about reducing this PR to just allowing bool, and not changing existing diagnostics?

I think this is probably a good step to take. I don't have particularly strong feelings about this change. I liked the symmetry between ()/Option<()> and Span/Option<Span>, but appreciate that writing Some(()) when constructing a error type doesn't necessarily communicate intent very well.

@bors

This comment was marked as resolved.

@clubby789 clubby789 changed the title Use bool instead of Option<()> in diagnostics Allow using bool instead of Option<()> in diagnostics Feb 27, 2023
@davidtwco
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 6, 2023

📌 Commit ef434f0 has been approved by davidtwco

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 Mar 6, 2023
@bors
Copy link
Contributor

bors commented Mar 6, 2023

⌛ Testing commit ef434f0 with merge f63ccaf...

@bors
Copy link
Contributor

bors commented Mar 6, 2023

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing f63ccaf to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 6, 2023
@bors bors merged commit f63ccaf into rust-lang:master Mar 6, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 6, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f63ccaf): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-2.4%, -2.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.4% [-2.4%, -2.4%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.2% [2.2%, 2.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic merged-by-bors This PR was explicitly merged by bors. 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.

8 participants