Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;
use std::rc::Rc;
use std::sync::Arc;
use std::{iter, mem};
use std::{iter, mem, slice};

use rustc_ast::mut_visit::*;
use rustc_ast::tokenstream::TokenStream;
Expand Down Expand Up @@ -2228,18 +2228,35 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
// Run attributes through the attribute parser
// since they will not be detected after macro expansion.
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
AttributeParser::parse_limited_all(
self.cx.sess,
attrs,
None,
AstTarget::MacroCall,
call.span(),
self.cx.current_expansion.lint_node_id,
Some(self.cx.ecfg.features),
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
Some(self.cx.resolver.registered_attr_tools()),
Some(self.cx.resolver.registered_lint_tools()),
);
let parse = |group| {
AttributeParser::parse_limited_all(
self.cx.sess,
group,
None,
AstTarget::MacroCall,
call.span(),
self.cx.current_expansion.lint_node_id,
Some(self.cx.ecfg.features),
ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed },
Some(self.cx.resolver.registered_attr_tools()),
Some(self.cx.resolver.registered_lint_tools()),
)
};

let mut doc_attrs = vec![];
for attr in attrs {
if matches!(attr.kind, AttrKind::DocComment(..)) {
doc_attrs.push(attr.clone());
continue;
}
parse(slice::from_ref(attr));
}

// Parse all doc comments together in a group, to prevent a group of
// unused doc comments from emitting multiple lints
if !doc_attrs.is_empty() {
parse(doc_attrs.as_slice());
}
}

fn expand_cfg_true(
Expand Down
8 changes: 8 additions & 0 deletions tests/ui/attributes/attr-on-mac-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,12 @@ fn main() {
}]
//~^^^ ERROR attribute value must be a literal
unreachable!();

#[deprecated]
//~^ WARN cannot be used on
//~| WARN previously accepted
#[deprecated]
//~^ WARN cannot be used on
//~| WARN previously accepted
unreachable!();
}
26 changes: 25 additions & 1 deletion tests/ui/attributes/attr-on-mac-call.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,30 @@ LL | unreachable!();
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

error: aborting due to 8 previous errors; 30 warnings emitted
warning: the `deprecated` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:155:7
|
LL | #[deprecated]
| ^^^^^^^^^^
...
LL | unreachable!();
|
= help: the `deprecated` attribute can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

warning: the `deprecated` attribute cannot be used on macro calls
--> $DIR/attr-on-mac-call.rs:158:7
|
LL | #[deprecated]
| ^^^^^^^^^^
...
LL | unreachable!();
|
= help: the `deprecated` attribute can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: attributes on a macro invocation apply to the invocation itself and are not forwarded to its expansion

error: aborting due to 8 previous errors; 32 warnings emitted

For more information about this error, try `rustc --explain E0658`.
Loading