Skip to content

Remove G generic param from Diag<'_, G> - #163083

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
nnethercote:rm-Diag-G
Sep 21, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
nnethercote:rm-Diag-G

Conversation

@nnethercote

@nnethercote nnethercote commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in #162630 (comment)

It encodes the `emit` behaviour, one of:
- `BugAbort`: Abort as a bug.
- `FatalAbort`: Abort as a fatal error.
- `ErrorGuaranteed`: Return an `ErrorGuaranteed` (the default).
- `()`: return `()`.

This is useful but `Diag` is very widely used and it's arguably not
useful enough to be worth the generic parameter. This commit removes it.

Benefits:
- Many fewer generic parameters, including many functions where the
  genericity is entirely uninteresting. This includes every
  `Diagnostic::into_diag` and `Subdiagnostic::add_to_diag`. Removes the
  need for the comment about `<G>` on `trait Diagnostic`.
- No `PhantomData` in `Diag`.
- Makes bootstrapping a bit faster.

The downside is there is no longer a single `emit` method.
- Getting a `!` return type requires calling `emit_bug` or `emit_fatal`.
  This only affects a few call sites.
- Getting an `ErrorGuaranteed` return type requires calling `emit_err`.
  This affects a lot of call sites. (It arguably makes call sites more
  self-documenting.)
- Using the wrong `emit_*` on a diagnostic causes a runtime abort, which
  previously couldn't occur. Seems unlikely, but it's not impossible.
- Note: If no particular return type is needed, `emit` can be used for
  any diagnostic. (Bug/fatal diagnostics will still trigger abort.)
@rustbot

rustbot commented Sep 20, 2026

Copy link
Copy Markdown
Collaborator

The rustc-dev-guide subtree was changed. If your future PRs only touch the subtree, consider submitting them directly to rust-lang/rustc-dev-guide, which is where the document is primarily maintained (and has faster CI).

cc @BoxyUwU, @tshepang

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

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred to constck

cc @fee1-dead

HIR ty lowering was modified

cc @fmease

rustc_macros::diagnostics was changed

cc @TaKO8Ki, @JonathanBrouwer

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-rustc-dev-guide Area: rustc-dev-guide 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-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Sep 20, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 20, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 20, 2026
Remove `G` generic param from `Diag<'_, G>`
@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 282876a (282876a4efd9e5ce0c9e41d5663a524acdc572a0)
Base parent: bba5310 (bba531001d4de6d7f49693e0836a2668ca063282)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (282876a): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.1%, 0.4%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.4% [-0.8%, -0.3%] 8
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.2%, secondary -3.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

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

Cycles

Results (primary 3.2%, secondary 1.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.2% [3.2%, 3.2%] 1
Regressions ❌
(secondary)
3.9% [2.7%, 5.0%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) 3.2% [3.2%, 3.2%] 1

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 496.585s -> 488.23s (-1.68%)
Artifact size: 408.87 MiB -> 406.49 MiB (-0.58%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 21, 2026

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 30b8dfc has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Sep 21, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors rollup=iffy
Perf changes are small enough

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 21, 2026
Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in rust-lang#162630 (comment)
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #163083 (Remove `G` generic param from `Diag<'_, G>`)
 - #160679 (Staticlib rename internal symbols: add COFF support)
 - #162007 (Preserve parentheses in raw borrow suggestions)
 - #163057 (Use span context for enclosing item(s) of unmet bound)
 - #163070 (label the path segment that is not an associated item of the trait)
 - #163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
@rust-bors

rust-bors Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Testing commit 30b8dfc with merge 929d979...

Workflow: https://github.com/rust-lang/rust/actions/runs/35604359904

rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in #162630 (comment)
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #163111.

rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #163083 (Remove `G` generic param from `Diag<'_, G>`)
 - #160679 (Staticlib rename internal symbols: add COFF support)
 - #160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - #162007 (Preserve parentheses in raw borrow suggestions)
 - #162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - #163057 (Use span context for enclosing item(s) of unmet bound)
 - #163070 (label the path segment that is not an associated item of the trait)
 - #163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - #163107 (Implement Allocator for Pin unstably)
 - #163108 (remove old solver use of `SolverRelating`)
@rust-bors

rust-bors Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

⌛ Testing commit 30b8dfc with merge e4f44de...

Workflow: https://github.com/rust-lang/rust/actions/runs/35605678728

rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in #162630 (comment)
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors yield
Yielding to enclosing rollup

@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Auto build was cancelled. Cancelled workflows:

The next pull request likely to be tested is #163111.

rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #163083 (Remove `G` generic param from `Diag<'_, G>`)
 - #160679 (Staticlib rename internal symbols: add COFF support)
 - #160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - #162007 (Preserve parentheses in raw borrow suggestions)
 - #162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - #163057 (Use span context for enclosing item(s) of unmet bound)
 - #163070 (label the path segment that is not an associated item of the trait)
 - #163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - #163107 (Implement Allocator for Pin unstably)
 - #163108 (remove old solver use of `SolverRelating`)
@rust-bors
rust-bors Bot merged commit a7be294 into rust-lang:main Sep 21, 2026
14 of 15 checks passed
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
Rollup merge of #163083 - nnethercote:rm-Diag-G, r=oli-obk

Remove `G` generic param from `Diag<'_, G>`

The benefits are outweighed by the costs. Details in invidual commits.

some minor earlier discussion about this change in #162630 (comment)
@rustbot rustbot added this to the 1.100.0 milestone Sep 21, 2026
github-actions Bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Sep 21, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
@nnethercote
nnethercote deleted the rm-Diag-G branch September 21, 2026 21:48
bjorn3 pushed a commit to rust-lang/rustc_codegen_cranelift that referenced this pull request Sep 22, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Sep 22, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#163083 (Remove `G` generic param from `Diag<'_, G>`)
 - rust-lang/rust#160679 (Staticlib rename internal symbols: add COFF support)
 - rust-lang/rust#160859 (`core::num::f16b` Rust's 16bit Brain Float)
 - rust-lang/rust#162007 (Preserve parentheses in raw borrow suggestions)
 - rust-lang/rust#162821 (Avoid suggesting closures when captures cross associated item boundaries)
 - rust-lang/rust#163057 (Use span context for enclosing item(s) of unmet bound)
 - rust-lang/rust#163070 (label the path segment that is not an associated item of the trait)
 - rust-lang/rust#163078 ( Add a README in tests/rustdoc-html to explain what each folder content is for)
 - rust-lang/rust#163107 (Implement Allocator for Pin unstably)
 - rust-lang/rust#163108 (remove old solver use of `SolverRelating`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-rustc-dev-guide Area: rustc-dev-guide A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants