mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Report error for each invalid nested attribute
This commit is contained in:
parent
7189c05bf8
commit
7e972a39b8
@ -531,6 +531,8 @@ impl CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool {
|
fn check_doc_attrs(&self, attr: &Attribute, hir_id: HirId, target: Target) -> bool {
|
||||||
|
let mut is_valid = true;
|
||||||
|
|
||||||
if let Some(list) = attr.meta().and_then(|mi| mi.meta_item_list().map(|l| l.to_vec())) {
|
if let Some(list) = attr.meta().and_then(|mi| mi.meta_item_list().map(|l| l.to_vec())) {
|
||||||
for meta in list {
|
for meta in list {
|
||||||
if let Some(i_meta) = meta.meta_item() {
|
if let Some(i_meta) = meta.meta_item() {
|
||||||
@ -539,14 +541,14 @@ impl CheckAttrVisitor<'tcx> {
|
|||||||
if !self.check_attr_crate_level(&meta, hir_id, "alias")
|
if !self.check_attr_crate_level(&meta, hir_id, "alias")
|
||||||
|| !self.check_doc_alias(&meta, hir_id, target) =>
|
|| !self.check_doc_alias(&meta, hir_id, target) =>
|
||||||
{
|
{
|
||||||
return false;
|
is_valid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::keyword
|
sym::keyword
|
||||||
if !self.check_attr_crate_level(&meta, hir_id, "keyword")
|
if !self.check_attr_crate_level(&meta, hir_id, "keyword")
|
||||||
|| !self.check_doc_keyword(&meta, hir_id) =>
|
|| !self.check_doc_keyword(&meta, hir_id) =>
|
||||||
{
|
{
|
||||||
return false;
|
is_valid = false
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::test if CRATE_HIR_ID != hir_id => {
|
sym::test if CRATE_HIR_ID != hir_id => {
|
||||||
@ -562,7 +564,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||||||
.emit();
|
.emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return false;
|
is_valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no_default_passes: deprecated
|
// no_default_passes: deprecated
|
||||||
@ -602,7 +604,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||||||
.emit();
|
.emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return false;
|
is_valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -614,11 +616,12 @@ impl CheckAttrVisitor<'tcx> {
|
|||||||
lint.build(&format!("unknown `doc` attribute")).emit();
|
lint.build(&format!("unknown `doc` attribute")).emit();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return false;
|
is_valid = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
|
||||||
|
is_valid
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
|
/// Checks if `#[cold]` is applied to a non-function. Returns `true` if valid.
|
||||||
|
@ -15,4 +15,6 @@ pub fn foo() {}
|
|||||||
#[doc("hello", "bar")]
|
#[doc("hello", "bar")]
|
||||||
//~^ ERROR unknown `doc` attribute
|
//~^ ERROR unknown `doc` attribute
|
||||||
//~| WARN
|
//~| WARN
|
||||||
|
//~| ERROR unknown `doc` attribute
|
||||||
|
//~| WARN
|
||||||
fn bar() {}
|
fn bar() {}
|
||||||
|
@ -31,6 +31,15 @@ LL | #[doc("hello", "bar")]
|
|||||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||||
|
|
||||||
|
error: unknown `doc` attribute
|
||||||
|
--> $DIR/doc-attr.rs:15:16
|
||||||
|
|
|
||||||
|
LL | #[doc("hello", "bar")]
|
||||||
|
| ^^^^^
|
||||||
|
|
|
||||||
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
|
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||||
|
|
||||||
error: unknown `doc` attribute `as_ptr`
|
error: unknown `doc` attribute `as_ptr`
|
||||||
--> $DIR/doc-attr.rs:3:8
|
--> $DIR/doc-attr.rs:3:8
|
||||||
|
|
|
|
||||||
@ -40,5 +49,5 @@ LL | #![doc(as_ptr)]
|
|||||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||||
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
= note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user