Add a diagnostic attribute for special casing const bound errors for non-const impls#148641
Merged
bors merged 2 commits intorust-lang:mainfrom Nov 27, 2025
Merged
Add a diagnostic attribute for special casing const bound errors for non-const impls#148641bors merged 2 commits intorust-lang:mainfrom
bors merged 2 commits intorust-lang:mainfrom
Conversation
Collaborator
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
Collaborator
This comment has been minimized.
This comment has been minimized.
c0e67f0 to
e501aad
Compare
This comment has been minimized.
This comment has been minimized.
e501aad to
d04c00d
Compare
This comment has been minimized.
This comment has been minimized.
estebank
reviewed
Nov 7, 2025
Comment on lines
529
to
549
| /// 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, | ||
| ); | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Should we also check that the impl is not const? Otherwise the annotation is fully inert in that case, right?
estebank
reviewed
Nov 7, 2025
d04c00d to
67b757b
Compare
This comment has been minimized.
This comment has been minimized.
67b757b to
4209241
Compare
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. |
This comment has been minimized.
This comment has been minimized.
Member
|
r=me after rebase |
4209241 to
9218298
Compare
Contributor
Author
|
@bors r=jackh726 |
Collaborator
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.
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
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
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.
github-actions bot
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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] PartialEqerrors.