use crate::mut_visit::*;
use crate::parse::{token, ParseSess};
use crate::ptr::P;
+use crate::symbol::sym;
use crate::util::map_in_place::MapInPlace;
use errors::Applicability;
/// is in the original source file. Gives a compiler error if the syntax of
/// the attribute is incorrect.
fn process_cfg_attr(&mut self, attr: ast::Attribute) -> Vec<ast::Attribute> {
- if !attr.check_name("cfg_attr") {
+ if !attr.check_name(sym::cfg_attr) {
return vec![attr];
}
+ if attr.tokens.len() == 0 {
+ self.sess.span_diagnostic
+ .struct_span_err(
+ attr.span,
+ "malformed `cfg_attr` attribute input",
+ ).span_suggestion(
+ attr.span,
+ "missing condition and attribute",
+ "#[cfg_attr(condition, attribute, other_attribute, ...)]".to_owned(),
+ Applicability::HasPlaceholders,
+ ).note("for more information, visit \
+ <https://doc.rust-lang.org/reference/conditional-compilation.html\
+ #the-cfg_attr-attribute>")
+ .emit();
+ return Vec::new();
+ }
let (cfg_predicate, expanded_attrs) = match attr.parse(self.sess, |parser| {
parser.expect(&token::OpenDelim(token::Paren))?;
pub fn maybe_emit_expr_attr_err(&self, attr: &ast::Attribute) {
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
let mut err = feature_err(self.sess,
- "stmt_expr_attributes",
+ sym::stmt_expr_attributes,
attr.span,
GateIssue::Language,
EXPLAIN_STMT_ATTR_SYNTAX);
/// See issue #51279.
pub fn disallow_cfg_on_generic_param(&mut self, param: &ast::GenericParam) {
for attr in param.attrs() {
- let offending_attr = if attr.check_name("cfg") {
+ let offending_attr = if attr.check_name(sym::cfg) {
"cfg"
- } else if attr.check_name("cfg_attr") {
+ } else if attr.check_name(sym::cfg_attr) {
"cfg_attr"
} else {
continue;
}
fn is_cfg(attr: &ast::Attribute) -> bool {
- attr.check_name("cfg")
+ attr.check_name(sym::cfg)
}