Skip to content

Commit

Permalink
make /// doc comments compatible with naked functions
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jul 30, 2024
1 parent 3954398 commit 58bfd98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Target::Fn
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => {
for other_attr in attrs {
// this covers "sugared doc comments" of the form `/// ...`
// it does not cover `#[doc = "..."]`, which is handled below
if other_attr.is_doc_comment() {
continue;
}

if !ALLOW_LIST.iter().any(|name| other_attr.has_name(*name)) {
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
span: other_attr.span,
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/asm/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ pub unsafe extern "C" fn compatible_target_feature() {
}

#[doc = "foo bar baz"]
/// a doc comment
// a normal comment
#[doc(alias = "ADocAlias")]
#[naked]
pub unsafe extern "C" fn compatible_doc_attributes() {
asm!("", options(noreturn, raw));
Expand Down

0 comments on commit 58bfd98

Please sign in to comment.