Skip to content

Commit 2be0094

Browse files
committed
Add items to DocAliasBadLocation check error match arm
- Added `Impl`, `Closure`, ForeignMod` targets - `Target::name` changed for `Target::Impl` - Error output for `Target::ForeignMod` changed to "foreign module"
1 parent 1e8abe7 commit 2be0094

File tree

6 files changed

+17
-15
lines changed

6 files changed

+17
-15
lines changed

compiler/rustc_hir/src/target.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl Target {
162162
Target::Union => "union",
163163
Target::Trait => "trait",
164164
Target::TraitAlias => "trait alias",
165-
Target::Impl => "item",
165+
Target::Impl => "implementation block",
166166
Target::Expression => "expression",
167167
Target::Statement => "statement",
168168
Target::Arm => "match arm",

compiler/rustc_passes/src/check_attr.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,6 @@ impl CheckAttrVisitor<'_> {
596596

597597
let span = meta.span();
598598
if let Some(location) = match target {
599-
Target::Impl => Some("implementation block"),
600-
Target::ForeignMod => Some("extern block"),
601599
Target::AssocTy => {
602600
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
603601
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
@@ -619,13 +617,17 @@ impl CheckAttrVisitor<'_> {
619617
}
620618
// we check the validity of params elsewhere
621619
Target::Param => return false,
622-
Target::Expression | Target::Statement | Target::Arm => Some(target.name()),
620+
Target::Expression
621+
| Target::Statement
622+
| Target::Arm
623+
| Target::ForeignMod
624+
| Target::Closure
625+
| Target::Impl => Some(target.name()),
623626
Target::ExternCrate
624627
| Target::Use
625628
| Target::Static
626629
| Target::Const
627630
| Target::Fn
628-
| Target::Closure
629631
| Target::Mod
630632
| Target::GlobalAsm
631633
| Target::TyAlias

src/test/rustdoc-ui/check-doc-alias-attr-location.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: `#[doc(alias = "...")]` isn't allowed on extern block
1+
error: `#[doc(alias = "...")]` isn't allowed on foreign module
22
--> $DIR/check-doc-alias-attr-location.rs:7:7
33
|
44
LL | #[doc(alias = "foo")]

src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ note: the lint level is defined here
212212
LL | #![warn(unused_attributes, unknown_lints)]
213213
| ^^^^^^^^^^^^^^^^^
214214

215-
warning: `#[automatically_derived]` only has an effect on items
215+
warning: `#[automatically_derived]` only has an effect on implementation blocks
216216
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:266:1
217217
|
218218
LL | #[automatically_derived]
@@ -515,25 +515,25 @@ warning: `#[path]` only has an effect on modules
515515
LL | #[path = "3800"] impl S { }
516516
| ^^^^^^^^^^^^^^^^
517517

518-
warning: `#[automatically_derived]` only has an effect on items
518+
warning: `#[automatically_derived]` only has an effect on implementation blocks
519519
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:269:17
520520
|
521521
LL | mod inner { #![automatically_derived] }
522522
| ^^^^^^^^^^^^^^^^^^^^^^^^^
523523

524-
warning: `#[automatically_derived]` only has an effect on items
524+
warning: `#[automatically_derived]` only has an effect on implementation blocks
525525
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:272:5
526526
|
527527
LL | #[automatically_derived] fn f() { }
528528
| ^^^^^^^^^^^^^^^^^^^^^^^^
529529

530-
warning: `#[automatically_derived]` only has an effect on items
530+
warning: `#[automatically_derived]` only has an effect on implementation blocks
531531
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:275:5
532532
|
533533
LL | #[automatically_derived] struct S;
534534
| ^^^^^^^^^^^^^^^^^^^^^^^^
535535

536-
warning: `#[automatically_derived]` only has an effect on items
536+
warning: `#[automatically_derived]` only has an effect on implementation blocks
537537
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:278:5
538538
|
539539
LL | #[automatically_derived] type T = S;
@@ -923,7 +923,7 @@ warning: `#[must_use]` has no effect when applied to a type alias
923923
LL | #[must_use] type T = S;
924924
| ^^^^^^^^^^^
925925

926-
warning: `#[must_use]` has no effect when applied to an item
926+
warning: `#[must_use]` has no effect when applied to an implementation block
927927
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:614:5
928928
|
929929
LL | #[must_use] impl S { }

src/test/ui/lint/unused/unused_attributes-must_use.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ error: `#[must_use]` has no effect when applied to a static item
4545
LL | #[must_use]
4646
| ^^^^^^^^^^^
4747

48-
error: `#[must_use]` has no effect when applied to an item
48+
error: `#[must_use]` has no effect when applied to an implementation block
4949
--> $DIR/unused_attributes-must_use.rs:33:1
5050
|
5151
LL | #[must_use]
@@ -69,7 +69,7 @@ error: `#[must_use]` has no effect when applied to a type parameter
6969
LL | fn qux<#[must_use] T>(_: T) {}
7070
| ^^^^^^^^^^^
7171

72-
error: `#[must_use]` has no effect when applied to an item
72+
error: `#[must_use]` has no effect when applied to an implementation block
7373
--> $DIR/unused_attributes-must_use.rs:79:1
7474
|
7575
LL | #[must_use]

src/test/ui/rustdoc/check-doc-alias-attr-location.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed
44
LL | fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X {
55
| ^^^^^^^^^^^^^^^^^^^^^
66

7-
error: `#[doc(alias = "...")]` isn't allowed on extern block
7+
error: `#[doc(alias = "...")]` isn't allowed on foreign module
88
--> $DIR/check-doc-alias-attr-location.rs:9:7
99
|
1010
LL | #[doc(alias = "foo")]

0 commit comments

Comments
 (0)