Skip to content

Commit 7e972a3

Browse files
committed
Report error for each invalid nested attribute
1 parent 7189c05 commit 7e972a3

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ impl CheckAttrVisitor<'tcx> {
531531
}
532532

533533
fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool {
534+
let mut is_valid = true;
535+
534536
if let Some(list) = attr.meta().and_then(|mi| mi.meta_item_list().map(|l| l.to_vec())) {
535537
for meta in list {
536538
if let Some(i_meta) = meta.meta_item() {
@@ -539,14 +541,14 @@ impl CheckAttrVisitor<'tcx> {
539541
if !self.check_attr_crate_level(&meta, hir_id, "alias")
540542
|| !self.check_doc_alias(&meta, hir_id, target) =>
541543
{
542-
return false;
544+
is_valid = false
543545
}
544546

545547
sym::keyword
546548
if !self.check_attr_crate_level(&meta, hir_id, "keyword")
547549
|| !self.check_doc_keyword(&meta, hir_id) =>
548550
{
549-
return false;
551+
is_valid = false
550552
}
551553

552554
sym::test if CRATE_HIR_ID != hir_id => {
@@ -562,7 +564,7 @@ impl CheckAttrVisitor<'tcx> {
562564
.emit();
563565
},
564566
);
565-
return false;
567+
is_valid = false;
566568
}
567569

568570
// no_default_passes: deprecated
@@ -602,7 +604,7 @@ impl CheckAttrVisitor<'tcx> {
602604
.emit();
603605
},
604606
);
605-
return false;
607+
is_valid = false;
606608
}
607609
}
608610
} else {
@@ -614,11 +616,12 @@ impl CheckAttrVisitor<'tcx> {
614616
lint.build(&format!("unknown `doc` attribute")).emit();
615617
},
616618
);
617-
return false;
619+
is_valid = false;
618620
}
619621
}
620622
}
621-
true
623+
624+
is_valid
622625
}
623626

624627
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.

src/test/ui/attributes/doc-attr.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ pub fn foo() {}
1515
#[doc("hello", "bar")]
1616
//~^ ERROR unknown `doc` attribute
1717
//~| WARN
18+
//~| ERROR unknown `doc` attribute
19+
//~| WARN
1820
fn bar() {}

src/test/ui/attributes/doc-attr.stderr

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ LL | #[doc("hello", "bar")]
3131
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3232
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
3333

34+
error: unknown `doc` attribute
35+
--> $DIR/doc-attr.rs:15:16
36+
|
37+
LL | #[doc("hello", "bar")]
38+
| ^^^^^
39+
|
40+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
41+
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
42+
3443
error: unknown `doc` attribute `as_ptr`
3544
--> $DIR/doc-attr.rs:3:8
3645
|
@@ -40,5 +49,5 @@ LL | #![doc(as_ptr)]
4049
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4150
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
4251

43-
error: aborting due to 4 previous errors
52+
error: aborting due to 5 previous errors
4453

0 commit comments

Comments
 (0)