Skip to content

Add a diagnostic attribute for special casing const bound errors for non-const impls - #148641

Merged
bors merged 2 commits into
rust-lang:mainfrom
oli-obk:push-olzwqxsmnxmz
Nov 27, 2025
Merged

Add a diagnostic attribute for special casing const bound errors for non-const impls#148641
bors merged 2 commits into
rust-lang:mainfrom
oli-obk:push-olzwqxsmnxmz

Conversation

@oli-obk

@oli-obkoli-obk commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Somewhat of a follow-up to #144194

My plan is to resolve

https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913

but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a *const u32 does not implement [const] PartialEq errors.

@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbotrustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 7, 2025
@rustbot

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
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

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Comment on lines +529 to +539
/// Checks if `#[diagnostic::on_const]` is applied to a trait impl
fn check_diagnostic_on_const(&self, attr_span: Span, hir_id: HirId, target: Target) {
if !matches!(target, Target::Impl { of_trait: true }) {
self.tcx.emit_node_span_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
DiagnosticOnConstOnlyForTraitImpls,
);
}
}

@estebankestebankNov 7, 2025

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.

Should we also check that the impl is not const? Otherwise the annotation is fully inert in that case, right?

Comment threadtests/ui/feature-gates/feature-gate-diagnostic-on-const.rs
@rustbot

This comment has been minimized.

@rustbot

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.

@jackh726

Copy link
Copy Markdown
Member

r=me after rebase

@jackh726jackh726 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 Nov 26, 2025
@oli-obk

Copy link
Copy Markdown
ContributorAuthor

@bors r=jackh726

@bors

bors commented Nov 26, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 9218298 has been approved by jackh726

It is now in the queue for this repository.

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 26, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
Add a diagnostic attribute for special casing const bound errors for non-const impls
Somewhat of a follow-up to rust-lang#144194
My plan is to resolve
https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913
but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
Add a diagnostic attribute for special casing const bound errors for non-const impls
Somewhat of a follow-up to rust-lang#144194
My plan is to resolve
https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913
but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 26, 2025
Add a diagnostic attribute for special casing const bound errors for non-const impls
Somewhat of a follow-up to rust-lang#144194
My plan is to resolve
https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913
but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
@ZalatharZalathar mentioned this pull request Nov 26, 2025
bors added a commit that referenced this pull request Nov 26, 2025
Rollup of 19 pull requests
Successful merges:
- #148048 (Stabilize `maybe_uninit_write_slice`)
- #148641 (Add a diagnostic attribute for special casing const bound errors for non-const impls)
- #148765 (std: split up the `thread` module)
- #149074 (Add Command::get_env_clear)
- #149097 (num: Implement `uint_gather_scatter_bits` feature for unsigned integers)
- #149131 (optimize `slice::Iter::next_chunk`)
- #149190 (Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead))
- #149239 (clarify float min/max behavios for NaNs and signed zeros)
- #149243 (Fix typo and clarify bootstrap change tracker entry)
- #149270 (implement `Iterator::{exactly_one, collect_array}`)
- #149295 (Suggest _bytes versions of endian-converting methods)
- #149301 (Motor OS: make decode_error_kind more comprehensive)
- #149306 (bootstrap: Miri now handles jemalloc like everything else)
- #149325 (rustdoc: add regression test for #140968)
- #149332 (fix rustdoc search says “Consider searching for "null" instead.” #149324)
- #149349 (Fix typo in comment.)
- #149353 (Tidying up UI tests [3/N])
- #149355 (Document that `build.description` affects symbol mangling and crate IDs)
- #149360 (Enable CI download for windows-gnullvm)
r? `@ghost`
`@rustbot` modify labels: rollup
@ZalatharZalathar mentioned this pull request Nov 27, 2025
bors added a commit that referenced this pull request Nov 27, 2025
Rollup of 12 pull requests
Successful merges:
- #147115 (More robust stack protector testing)
- #148048 (Stabilize `maybe_uninit_write_slice`)
- #148641 (Add a diagnostic attribute for special casing const bound errors for non-const impls)
- #149074 (Add Command::get_env_clear)
- #149097 (num: Implement `uint_gather_scatter_bits` feature for unsigned integers)
- #149131 (optimize `slice::Iter::next_chunk`)
- #149190 (Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead))
- #149239 (clarify float min/max behavios for NaNs and signed zeros)
- #149243 (Fix typo and clarify bootstrap change tracker entry)
- #149301 (Motor OS: make decode_error_kind more comprehensive)
- #149306 (bootstrap: Miri now handles jemalloc like everything else)
- #149325 (rustdoc: add regression test for #140968)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit e4cd17c into rust-lang:mainNov 27, 2025
11 checks passed
@rustbotrustbot added this to the 1.93.0 milestone Nov 27, 2025
rust-timer added a commit that referenced this pull request Nov 27, 2025
Rollup merge of #148641 - oli-obk:push-olzwqxsmnxmz, r=jackh726
Add a diagnostic attribute for special casing const bound errors for non-const impls
Somewhat of a follow-up to #144194
My plan is to resolve
https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913
but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
@fmeasefmease added the PG-const-traits Project group: Const traits label Nov 27, 2025
@oli-obk
oli-obk deleted the push-olzwqxsmnxmz branch November 29, 2025 08:56
github-actionsBot pushed a commit to model-checking/verify-rust-std that referenced this pull request Jan 20, 2026
Add a diagnostic attribute for special casing const bound errors for non-const impls
Somewhat of a follow-up to rust-lang#144194
My plan is to resolve
https://github.com/rust-lang/rust/blob/f4e19c68786211f3c3cf2593442629599678800a/compiler/rustc_hir_typeck/src/callee.rs#L907-913
but doing so without being able to mark impls the way I do in this PR wrould cause all nice diagnostics about for loops and pointer comparisons to just be a `*const u32 does not implement [const] PartialEq` errors.
rust-borsBot pushed a commit that referenced this pull request Feb 19, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by #148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
github-actionsBot pushed a commit to rust-lang/miri that referenced this pull request Feb 22, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
github-actionsBot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Feb 23, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
github-actionsBot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Feb 23, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
github-actionsBot pushed a commit to rust-lang/stdarch that referenced this pull request Mar 9, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Mar 19, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Mar 19, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
makai410 pushed a commit to makai410/rustc_public that referenced this pull request Mar 27, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
github-actionsBot pushed a commit to rust-lang/compiler-builtins that referenced this pull request Mar 31, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
ghaaj pushed a commit to ghaaj/polygrammar that referenced this pull request Aug 7, 2026
Perform many const checks in typeck
Some smaller diagnostic changes, the biggest ones avoided by rust-lang/rust#148641
We should be able to move various checks in mir const checking to using `span_bug!` instead of reporting an error, just like mir typeck does as a sanity check. I would like to start doing so separately though, as this PR is a big enough (in what effects it causes, pun intended).
r? @fee1-dead
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)PG-const-traitsProject group: Const traitsS-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@oli-obk@rustbot@rust-log-analyzer@jackh726@bors@estebank@fmease