Pass a Symbol to check_name, emit_feature_err, and related functions.

This commit is contained in:
Nicholas Nethercote 2019-05-08 13:21:18 +10:00
parent 79602c87b5
commit fb084a48e2
114 changed files with 671 additions and 621 deletions

View file

@ -14,7 +14,7 @@ use syntax::ast;
use syntax::attr;
use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable};
use syntax::ext::build::AstBuilder;
use syntax::symbol::Symbol;
use syntax::symbol::{Symbol, sym};
use syntax::ptr::P;
use syntax_ext::deriving::generic::{TraitDef, MethodDef, combine_substructure};
use syntax_ext::deriving::generic::{Substructure, Struct, EnumMatching};
@ -71,7 +71,7 @@ fn totalsum_substructure(cx: &mut ExtCtxt, trait_span: Span,
};
fields.iter().fold(cx.expr_isize(trait_span, 0), |acc, ref item| {
if attr::contains_name(&item.attrs, "ignore") {
if attr::contains_name(&item.attrs, sym::ignore) {
acc
} else {
cx.expr_binary(item.span, ast::BinOpKind::Add, acc,

View file

@ -23,7 +23,7 @@ use syntax::{ast, source_map};
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_late_lint_pass(box MissingWhitelistedAttrPass);
reg.register_attribute("whitelisted_attr".to_string(), Whitelisted);
reg.register_attribute(Symbol::intern("whitelisted_attr"), Whitelisted);
}
declare_lint! {
@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass {
_ => cx.tcx.hir().expect_item_by_hir_id(cx.tcx.hir().get_parent_item(id)),
};
if !attr::contains_name(&item.attrs, "whitelisted_attr") {
if !attr::contains_name(&item.attrs, Symbol::intern("whitelisted_attr")) {
cx.span_lint(MISSING_WHITELISTED_ATTR, span,
"Missing 'whitelisted_attr' attribute");
}

View file

@ -11,6 +11,7 @@ use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LateLintPass
use rustc_plugin::Registry;
use rustc::hir;
use syntax::attr;
use syntax::symbol::Symbol;
macro_rules! fake_lint_pass {
($struct:ident, $lints:expr, $($attr:expr),*) => {
@ -49,19 +50,19 @@ declare_lint!(CRATE_NOT_GREEN, Warn, "crate not marked with #![crate_green]");
fake_lint_pass! {
PassOkay,
lint_array!(CRATE_NOT_OKAY), // Single lint
"rustc_crate_okay"
Symbol::intern("rustc_crate_okay")
}
fake_lint_pass! {
PassRedBlue,
lint_array!(CRATE_NOT_RED, CRATE_NOT_BLUE), // Multiple lints
"rustc_crate_red", "rustc_crate_blue"
Symbol::intern("rustc_crate_red"), Symbol::intern("rustc_crate_blue")
}
fake_lint_pass! {
PassGreyGreen,
lint_array!(CRATE_NOT_GREY, CRATE_NOT_GREEN, ), // Trailing comma
"rustc_crate_grey", "rustc_crate_green"
Symbol::intern("rustc_crate_grey"), Symbol::intern("rustc_crate_green")
}
#[plugin_registrar]

View file

@ -8,14 +8,14 @@ extern crate syntax;
extern crate rustc;
extern crate rustc_plugin;
use syntax::symbol::Symbol;
use syntax::feature_gate::AttributeType;
use rustc_plugin::Registry;
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_attribute("foo".to_owned(), AttributeType::Normal);
reg.register_attribute("bar".to_owned(), AttributeType::CrateLevel);
reg.register_attribute("baz".to_owned(), AttributeType::Whitelisted);
reg.register_attribute(Symbol::intern("foo"), AttributeType::Normal);
reg.register_attribute(Symbol::intern("bar"), AttributeType::CrateLevel);
reg.register_attribute(Symbol::intern("baz"), AttributeType::Whitelisted);
}

View file

@ -11,6 +11,7 @@ use rustc::lint::{LateContext, LintContext, LintPass, LateLintPass, LateLintPass
use rustc_plugin::Registry;
use rustc::hir;
use syntax::attr;
use syntax::symbol::Symbol;
declare_lint! {
CRATE_NOT_OKAY,
@ -22,7 +23,7 @@ declare_lint_pass!(Pass => [CRATE_NOT_OKAY]);
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_crate(&mut self, cx: &LateContext, krate: &hir::Crate) {
if !attr::contains_name(&krate.attrs, "crate_okay") {
if !attr::contains_name(&krate.attrs, Symbol::intern("crate_okay")) {
cx.span_lint(CRATE_NOT_OKAY, krate.span,
"crate is not marked with #![crate_okay]");
}