Skip to content

Commit 6bf62ce

Browse files
authored
Unrolled build for #149627
Rollup merge of #149627 - lapla-cogito:diag_onconst, r=jdonszelmann Point to the item that is incorrectly annotated with `#[diagnostic::on_const]` close #149606 r? estebank
2 parents b33119f + 2db3c95 commit 6bf62ce

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ passes_deprecated_attribute =
9898
9999
passes_diagnostic_diagnostic_on_const_only_for_trait_impls =
100100
`#[diagnostic::on_const]` can only be applied to trait impls
101+
.label = not a trait impl
101102
102103
passes_diagnostic_diagnostic_on_unimplemented_only_for_traits =
103104
`#[diagnostic::on_unimplemented]` can only be applied to trait definitions

compiler/rustc_passes/src/check_attr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ struct DiagnosticOnUnimplementedOnlyForTraits;
5757

5858
#[derive(LintDiagnostic)]
5959
#[diag(passes_diagnostic_diagnostic_on_const_only_for_trait_impls)]
60-
struct DiagnosticOnConstOnlyForTraitImpls;
60+
struct DiagnosticOnConstOnlyForTraitImpls {
61+
#[label]
62+
item_span: Span,
63+
}
6164

6265
fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
6366
match impl_item.kind {
@@ -541,11 +544,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
541544
ItemLike::ForeignItem => {}
542545
}
543546
}
547+
let item_span = self.tcx.hir_span(hir_id);
544548
self.tcx.emit_node_span_lint(
545549
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
546550
hir_id,
547551
attr_span,
548-
DiagnosticOnConstOnlyForTraitImpls,
552+
DiagnosticOnConstOnlyForTraitImpls { item_span },
549553
);
550554
}
551555

tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error: `#[diagnostic::on_const]` can only be applied to trait impls
33
|
44
LL | #[diagnostic::on_const(message = "tadaa", note = "boing")]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
LL |
7+
LL | pub struct Foo;
8+
| -------------- not a trait impl
69
|
710
note: the lint level is defined here
811
--> $DIR/misplaced_attr.rs:2:9
@@ -15,18 +18,27 @@ error: `#[diagnostic::on_const]` can only be applied to trait impls
1518
|
1619
LL | #[diagnostic::on_const(message = "tadaa", note = "boing")]
1720
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
LL |
22+
LL | impl const PartialEq for Foo {
23+
| ---------------------------- not a trait impl
1824

1925
error: `#[diagnostic::on_const]` can only be applied to trait impls
2026
--> $DIR/misplaced_attr.rs:16:1
2127
|
2228
LL | #[diagnostic::on_const(message = "tadaa", note = "boing")]
2329
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL |
31+
LL | impl Foo {
32+
| -------- not a trait impl
2433

2534
error: `#[diagnostic::on_const]` can only be applied to trait impls
2635
--> $DIR/misplaced_attr.rs:25:5
2736
|
2837
LL | #[diagnostic::on_const(message = "tadaa", note = "boing")]
2938
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
LL |
40+
LL | fn partial_cmp(&self, other: &Foo) -> Option<std::cmp::Ordering> {
41+
| ---------------------------------------------------------------- not a trait impl
3042

3143
error: aborting due to 4 previous errors
3244

0 commit comments

Comments
 (0)