diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 1cecce8fd43ef..45c2b49c9952b 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -334,20 +334,6 @@ impl<'sess> AttributeParser<'sess> { } } - fn is_doc_non_lit_expr(attr: &ast::Attribute) -> bool { - if !attr.has_name(sym::doc) { - return false; - } - let ast::AttrKind::Normal(n) = &attr.kind else { return false }; - let ast::AttrArgs::Eq { expr, .. } = &n.item.args else { return false }; - !matches!(expr.kind, ast::ExprKind::Lit(_)) - } - - // FIXME accidentally allowed on Stable Rust - if target == Target::MacroCall && is_doc_non_lit_expr(attr) { - continue; - } - let attr_span = lower_span(attr.span); match &attr.kind { ast::AttrKind::DocComment(comment_kind, symbol) => { diff --git a/tests/ui/attributes/attr-on-mac-call.rs b/tests/ui/attributes/attr-on-mac-call.rs index 618e583d0af5e..28fbd0ca48600 100644 --- a/tests/ui/attributes/attr-on-mac-call.rs +++ b/tests/ui/attributes/attr-on-mac-call.rs @@ -113,6 +113,7 @@ fn main() { #[deprecated = concat!("woah", "dude")] //~^ ERROR attribute value must be a literal #[doc = concat!("woah", "dude")] + //~^ ERROR attribute value must be a literal unreachable!(); #[doc = { let a = 1; @@ -120,5 +121,11 @@ fn main() { let sum = a + b; assert_eq!(sum, 2); }] + //~^^^^^^ ERROR attribute value must be a literal + unreachable!(); + #[doc = { + let expressions @ r#in @ doc @ attributes @ at = home; + }] + //~^^^ ERROR attribute value must be a literal unreachable!(); } diff --git a/tests/ui/attributes/attr-on-mac-call.stderr b/tests/ui/attributes/attr-on-mac-call.stderr index aa158bee22768..b1b4112e27e2b 100644 --- a/tests/ui/attributes/attr-on-mac-call.stderr +++ b/tests/ui/attributes/attr-on-mac-call.stderr @@ -44,6 +44,33 @@ error: attribute value must be a literal LL | #[deprecated = concat!("woah", "dude")] | ^^^^^^^^^^^^^^^^^^^^^^^ +error: attribute value must be a literal + --> $DIR/attr-on-mac-call.rs:115:13 + | +LL | #[doc = concat!("woah", "dude")] + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: attribute value must be a literal + --> $DIR/attr-on-mac-call.rs:118:13 + | +LL | #[doc = { + | _____________^ +LL | | let a = 1; +LL | | let b = 1; +LL | | let sum = a + b; +LL | | assert_eq!(sum, 2); +LL | | }] + | |_____^ + +error: attribute value must be a literal + --> $DIR/attr-on-mac-call.rs:126:13 + | +LL | #[doc = { + | _____________^ +LL | | let expressions @ r#in @ doc @ attributes @ at = home; +LL | | }] + | |_____^ + warning: the `export_name` attribute cannot be used on macro calls --> $DIR/attr-on-mac-call.rs:8:7 | @@ -347,6 +374,6 @@ LL | #[repr(Rust)] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: placing this attribute on a macro invocation does nothing even if the macro expands to what would be a valid target for the attribute -error: aborting due to 5 previous errors; 30 warnings emitted +error: aborting due to 8 previous errors; 30 warnings emitted For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/lint/unused/unused-doc-comments-for-macros.rs b/tests/ui/lint/unused/unused-doc-comments-for-macros.rs index 62c4fe82348cc..8a3dd45c02115 100644 --- a/tests/ui/lint/unused/unused-doc-comments-for-macros.rs +++ b/tests/ui/lint/unused/unused-doc-comments-for-macros.rs @@ -23,5 +23,6 @@ fn main() { assert_eq!(sum, 2); }] //~^^^^^^ ERROR: unused doc comment + //~| ERROR attribute value must be a literal foo!(); } diff --git a/tests/ui/lint/unused/unused-doc-comments-for-macros.stderr b/tests/ui/lint/unused/unused-doc-comments-for-macros.stderr index 4634e0704c536..9bb89974f9e23 100644 --- a/tests/ui/lint/unused/unused-doc-comments-for-macros.stderr +++ b/tests/ui/lint/unused/unused-doc-comments-for-macros.stderr @@ -1,3 +1,15 @@ +error: attribute value must be a literal + --> $DIR/unused-doc-comments-for-macros.rs:19:13 + | +LL | #[doc = { + | _____________^ +LL | | let a = 1; +LL | | let b = 1; +LL | | let sum = a + b; +LL | | assert_eq!(sum, 2); +LL | | }] + | |_____^ + error: unused doc comment --> $DIR/unused-doc-comments-for-macros.rs:7:5 | @@ -40,5 +52,5 @@ LL | | }] | = help: to document an item produced by a macro, the macro must produce the documentation as part of its expansion -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors