Skip to content

Commit fb084a4

Browse files
committed
Pass a Symbol to check_name, emit_feature_err, and related functions.
1 parent 79602c8 commit fb084a4

File tree

114 files changed

+670
-620
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+670
-620
lines changed

src/librustc/hir/check_attr.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::hir;
1212
use crate::hir::def_id::DefId;
1313
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
1414
use std::fmt::{self, Display};
15+
use syntax::symbol::sym;
1516
use syntax_pos::Span;
1617

1718
#[derive(Copy, Clone, PartialEq)]
@@ -95,18 +96,18 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
9596
fn check_attributes(&self, item: &hir::Item, target: Target) {
9697
if target == Target::Fn || target == Target::Const {
9798
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id_from_hir_id(item.hir_id));
98-
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
99+
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name(sym::target_feature)) {
99100
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
100101
.span_label(item.span, "not a function")
101102
.emit();
102103
}
103104

104105
for attr in &item.attrs {
105-
if attr.check_name("inline") {
106+
if attr.check_name(sym::inline) {
106107
self.check_inline(attr, &item.span, target)
107-
} else if attr.check_name("non_exhaustive") {
108+
} else if attr.check_name(sym::non_exhaustive) {
108109
self.check_non_exhaustive(attr, item, target)
109-
} else if attr.check_name("marker") {
110+
} else if attr.check_name(sym::marker) {
110111
self.check_marker(attr, item, target)
111112
}
112113
}
@@ -166,7 +167,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
166167
// ```
167168
let hints: Vec<_> = item.attrs
168169
.iter()
169-
.filter(|attr| attr.check_name("repr"))
170+
.filter(|attr| attr.check_name(sym::repr))
170171
.filter_map(|attr| attr.meta_item_list())
171172
.flatten()
172173
.collect();
@@ -268,10 +269,10 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
268269
// When checking statements ignore expressions, they will be checked later
269270
if let hir::StmtKind::Local(ref l) = stmt.node {
270271
for attr in l.attrs.iter() {
271-
if attr.check_name("inline") {
272+
if attr.check_name(sym::inline) {
272273
self.check_inline(attr, &stmt.span, Target::Statement);
273274
}
274-
if attr.check_name("repr") {
275+
if attr.check_name(sym::repr) {
275276
self.emit_repr_error(
276277
attr.span,
277278
stmt.span,
@@ -289,10 +290,10 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
289290
_ => Target::Expression,
290291
};
291292
for attr in expr.attrs.iter() {
292-
if attr.check_name("inline") {
293+
if attr.check_name(sym::inline) {
293294
self.check_inline(attr, &expr.span, target);
294295
}
295-
if attr.check_name("repr") {
296+
if attr.check_name(sym::repr) {
296297
self.emit_repr_error(
297298
attr.span,
298299
expr.span,
@@ -305,7 +306,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
305306

306307
fn check_used(&self, item: &hir::Item, target: Target) {
307308
for attr in &item.attrs {
308-
if attr.check_name("used") && target != Target::Static {
309+
if attr.check_name(sym::used) && target != Target::Static {
309310
self.tcx.sess
310311
.span_err(attr.span, "attribute must be applied to a `static` variable");
311312
}

src/librustc/hir/lowering.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use syntax::ptr::P;
6464
use syntax::source_map::{respan, CompilerDesugaringKind, Spanned};
6565
use syntax::source_map::CompilerDesugaringKind::IfTemporary;
6666
use syntax::std_inject;
67-
use syntax::symbol::{keywords, Symbol};
67+
use syntax::symbol::{keywords, Symbol, sym};
6868
use syntax::tokenstream::{TokenStream, TokenTree};
6969
use syntax::parse::token::Token;
7070
use syntax::visit::{self, Visitor};
@@ -2727,7 +2727,7 @@ impl<'a> LoweringContext<'a> {
27272727
self.lower_ty(x, ImplTraitContext::disallowed())
27282728
}),
27292729
synthetic: param.attrs.iter()
2730-
.filter(|attr| attr.check_name("rustc_synthetic"))
2730+
.filter(|attr| attr.check_name(sym::rustc_synthetic))
27312731
.map(|_| hir::SyntheticTyParamKind::ImplTrait)
27322732
.next(),
27332733
};
@@ -2745,7 +2745,7 @@ impl<'a> LoweringContext<'a> {
27452745
hir_id: self.lower_node_id(param.id),
27462746
name,
27472747
span: param.ident.span,
2748-
pure_wrt_drop: attr::contains_name(&param.attrs, "may_dangle"),
2748+
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
27492749
attrs: self.lower_attrs(&param.attrs),
27502750
bounds,
27512751
kind,
@@ -3773,8 +3773,8 @@ impl<'a> LoweringContext<'a> {
37733773
let mut vis = self.lower_visibility(&i.vis, None);
37743774
let attrs = self.lower_attrs(&i.attrs);
37753775
if let ItemKind::MacroDef(ref def) = i.node {
3776-
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
3777-
attr::contains_name(&i.attrs, "rustc_doc_only_macro") {
3776+
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) ||
3777+
attr::contains_name(&i.attrs, sym::rustc_doc_only_macro) {
37783778
let body = self.lower_token_stream(def.stream());
37793779
let hir_id = self.lower_node_id(i.id);
37803780
self.exported_macros.push(hir::MacroDef {

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use smallvec::SmallVec;
2828

2929
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
3030
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
31-
ich::IGNORED_ATTRIBUTES.iter().map(|&s| Symbol::intern(s)).collect()
31+
ich::IGNORED_ATTRIBUTES.iter().map(|&s| s).collect()
3232
}
3333

3434
/// This is the context state available during incr. comp. hashing. It contains

src/librustc/ich/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ crate use rustc_data_structures::fingerprint::Fingerprint;
44
pub use self::caching_source_map_view::CachingSourceMapView;
55
pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHashingMode,
66
hash_stable_trait_impls};
7+
use syntax::symbol::{Symbol, sym};
8+
79
mod caching_source_map_view;
810
mod hcx;
911

@@ -12,16 +14,16 @@ mod impls_misc;
1214
mod impls_ty;
1315
mod impls_syntax;
1416

15-
pub const ATTR_DIRTY: &str = "rustc_dirty";
16-
pub const ATTR_CLEAN: &str = "rustc_clean";
17-
pub const ATTR_IF_THIS_CHANGED: &str = "rustc_if_this_changed";
18-
pub const ATTR_THEN_THIS_WOULD_NEED: &str = "rustc_then_this_would_need";
19-
pub const ATTR_PARTITION_REUSED: &str = "rustc_partition_reused";
20-
pub const ATTR_PARTITION_CODEGENED: &str = "rustc_partition_codegened";
21-
pub const ATTR_EXPECTED_CGU_REUSE: &str = "rustc_expected_cgu_reuse";
17+
pub const ATTR_DIRTY: Symbol = sym::rustc_dirty;
18+
pub const ATTR_CLEAN: Symbol = sym::rustc_clean;
19+
pub const ATTR_IF_THIS_CHANGED: Symbol = sym::rustc_if_this_changed;
20+
pub const ATTR_THEN_THIS_WOULD_NEED: Symbol = sym::rustc_then_this_would_need;
21+
pub const ATTR_PARTITION_REUSED: Symbol = sym::rustc_partition_reused;
22+
pub const ATTR_PARTITION_CODEGENED: Symbol = sym::rustc_partition_codegened;
23+
pub const ATTR_EXPECTED_CGU_REUSE: Symbol = sym::rustc_expected_cgu_reuse;
2224

23-
pub const IGNORED_ATTRIBUTES: &[&str] = &[
24-
"cfg",
25+
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
26+
sym::cfg,
2527
ATTR_IF_THIS_CHANGED,
2628
ATTR_THEN_THIS_WOULD_NEED,
2729
ATTR_DIRTY,

src/librustc/lint/levels.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use syntax::ast;
1414
use syntax::attr;
1515
use syntax::feature_gate;
1616
use syntax::source_map::MultiSpan;
17-
use syntax::symbol::Symbol;
17+
use syntax::symbol::{Symbol, sym};
1818

1919
pub struct LintLevelSets {
2020
list: Vec<LintSet>,
@@ -230,7 +230,7 @@ impl<'a> LintLevelsBuilder<'a> {
230230
if !self.sess.features_untracked().lint_reasons {
231231
feature_gate::emit_feature_err(
232232
&self.sess.parse_sess,
233-
"lint_reasons",
233+
sym::lint_reasons,
234234
item.span,
235235
feature_gate::GateIssue::Language,
236236
"lint reasons are experimental"

src/librustc/middle/dead.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_data_structures::fx::FxHashMap;
1919

2020
use syntax::{ast, source_map};
2121
use syntax::attr;
22+
use syntax::symbol::sym;
2223
use syntax_pos;
2324

2425
// Any local node that may call something in its body block should be
@@ -304,22 +305,22 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> {
304305
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
305306
id: hir::HirId,
306307
attrs: &[ast::Attribute]) -> bool {
307-
if attr::contains_name(attrs, "lang") {
308+
if attr::contains_name(attrs, sym::lang) {
308309
return true;
309310
}
310311

311312
// Stable attribute for #[lang = "panic_impl"]
312-
if attr::contains_name(attrs, "panic_handler") {
313+
if attr::contains_name(attrs, sym::panic_handler) {
313314
return true;
314315
}
315316

316317
// (To be) stable attribute for #[lang = "oom"]
317-
if attr::contains_name(attrs, "alloc_error_handler") {
318+
if attr::contains_name(attrs, sym::alloc_error_handler) {
318319
return true;
319320
}
320321

321322
// Don't lint about global allocators
322-
if attr::contains_name(attrs, "global_allocator") {
323+
if attr::contains_name(attrs, sym::global_allocator) {
323324
return true;
324325
}
325326

src/librustc/middle/entry.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::session::{config, Session};
44
use crate::session::config::EntryFnType;
55
use syntax::attr;
66
use syntax::entry::EntryPointType;
7+
use syntax::symbol::sym;
78
use syntax_pos::Span;
89
use crate::hir::{HirId, Item, ItemKind, ImplItem, TraitItem};
910
use crate::hir::itemlikevisit::ItemLikeVisitor;
@@ -58,7 +59,7 @@ fn entry_fn(tcx: TyCtxt<'_, '_, '_>, cnum: CrateNum) -> Option<(DefId, EntryFnTy
5859
}
5960

6061
// If the user wants no main function at all, then stop here.
61-
if attr::contains_name(&tcx.hir().krate().attrs, "no_main") {
62+
if attr::contains_name(&tcx.hir().krate().attrs, sym::no_main) {
6263
return None;
6364
}
6465

@@ -81,9 +82,9 @@ fn entry_fn(tcx: TyCtxt<'_, '_, '_>, cnum: CrateNum) -> Option<(DefId, EntryFnTy
8182
fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
8283
match item.node {
8384
ItemKind::Fn(..) => {
84-
if attr::contains_name(&item.attrs, "start") {
85+
if attr::contains_name(&item.attrs, sym::start) {
8586
EntryPointType::Start
86-
} else if attr::contains_name(&item.attrs, "main") {
87+
} else if attr::contains_name(&item.attrs, sym::main) {
8788
EntryPointType::MainAttr
8889
} else if item.ident.name == "main" {
8990
if at_root {

src/librustc/middle/lang_items.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::middle::weak_lang_items;
1818
use crate::util::nodemap::FxHashMap;
1919

2020
use syntax::ast;
21-
use syntax::symbol::Symbol;
21+
use syntax::symbol::{Symbol, sym};
2222
use syntax_pos::Span;
2323
use rustc_macros::HashStable;
2424
use crate::hir::itemlikevisit::ItemLikeVisitor;
@@ -209,9 +209,9 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
209209
/// are also extracted out when found.
210210
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
211211
attrs.iter().find_map(|attr| Some(match attr {
212-
_ if attr.check_name("lang") => (attr.value_str()?, attr.span),
213-
_ if attr.check_name("panic_handler") => (Symbol::intern("panic_impl"), attr.span),
214-
_ if attr.check_name("alloc_error_handler") => (Symbol::intern("oom"), attr.span),
212+
_ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span),
213+
_ if attr.check_name(sym::panic_handler) => (Symbol::intern("panic_impl"), attr.span),
214+
_ if attr.check_name(sym::alloc_error_handler) => (Symbol::intern("oom"), attr.span),
215215
_ => return None,
216216
}))
217217
}

src/librustc/middle/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ use std::io;
112112
use std::rc::Rc;
113113
use syntax::ast::{self, NodeId};
114114
use syntax::ptr::P;
115-
use syntax::symbol::keywords;
115+
use syntax::symbol::{keywords, sym};
116116
use syntax_pos::Span;
117117

118118
use crate::hir;
@@ -362,7 +362,7 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
362362
if let FnKind::Method(..) = fk {
363363
let parent = ir.tcx.hir().get_parent_item(id);
364364
if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) {
365-
if i.attrs.iter().any(|a| a.check_name("automatically_derived")) {
365+
if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) {
366366
return;
367367
}
368368
}

src/librustc/middle/mem_categorization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ use crate::hir::{MutImmutable, MutMutable, PatKind};
7272
use crate::hir::pat_util::EnumerateAndAdjustIterator;
7373
use crate::hir;
7474
use syntax::ast::{self, Name};
75+
use syntax::symbol::sym;
7576
use syntax_pos::Span;
7677

7778
use std::borrow::Cow;
@@ -714,7 +715,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
714715
// they also cannot be moved out of.
715716
let is_thread_local = self.tcx.get_attrs(def_id)[..]
716717
.iter()
717-
.any(|attr| attr.check_name("thread_local"));
718+
.any(|attr| attr.check_name(sym::thread_local));
718719

719720
let cat = if is_thread_local {
720721
let re = self.temporary_scope(hir_id.local_id);

src/librustc/middle/recursion_limit.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
use crate::session::Session;
99
use syntax::ast;
10+
use syntax::symbol::{Symbol, sym};
1011

1112
use rustc_data_structures::sync::Once;
1213

1314
pub fn update_limits(sess: &Session, krate: &ast::Crate) {
14-
update_limit(krate, &sess.recursion_limit, "recursion_limit", 64);
15-
update_limit(krate, &sess.type_length_limit, "type_length_limit", 1048576);
15+
update_limit(krate, &sess.recursion_limit, sym::recursion_limit, 64);
16+
update_limit(krate, &sess.type_length_limit, sym::type_length_limit, 1048576);
1617
}
1718

18-
fn update_limit(krate: &ast::Crate, limit: &Once<usize>, name: &str, default: usize) {
19+
fn update_limit(krate: &ast::Crate, limit: &Once<usize>, name: Symbol, default: usize) {
1920
for attr in &krate.attrs {
2021
if !attr.check_name(name) {
2122
continue;

src/librustc/middle/resolve_lifetime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::mem::replace;
2323
use syntax::ast;
2424
use syntax::attr;
2525
use syntax::ptr::P;
26-
use syntax::symbol::keywords;
26+
use syntax::symbol::{keywords, sym};
2727
use syntax_pos::Span;
2828

2929
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -1285,7 +1285,7 @@ fn compute_object_lifetime_defaults(
12851285
let result = object_lifetime_defaults_for_item(tcx, generics);
12861286

12871287
// Debugging aid.
1288-
if attr::contains_name(&item.attrs, "rustc_object_lifetime_default") {
1288+
if attr::contains_name(&item.attrs, sym::rustc_object_lifetime_default) {
12891289
let object_lifetime_default_reprs: String = result
12901290
.iter()
12911291
.map(|set| match *set {

src/librustc/middle/stability.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
1111
use crate::ty::query::Providers;
1212
use crate::middle::privacy::AccessLevels;
1313
use crate::session::{DiagnosticMessageId, Session};
14-
use syntax::symbol::Symbol;
14+
use syntax::symbol::{Symbol, sym};
1515
use syntax_pos::{Span, MultiSpan};
1616
use syntax::ast::Attribute;
1717
use syntax::errors::Applicability;
@@ -669,7 +669,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
669669

670670
match stability {
671671
Some(&Stability { level: attr::Unstable { reason, issue }, feature, .. }) => {
672-
if span.allows_unstable(&feature.as_str()) {
672+
if span.allows_unstable(feature) {
673673
debug!("stability: skipping span={:?} since it is internal", span);
674674
return EvalResult::Allow;
675675
}
@@ -739,7 +739,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
739739
let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
740740
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(error_id);
741741
if fresh {
742-
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
742+
emit_feature_err(&self.sess.parse_sess, feature, span,
743743
GateIssue::Library(Some(issue)), &msg);
744744
}
745745
}
@@ -802,13 +802,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
802802

803803
if adt_def.has_dtor(self.tcx) {
804804
emit_feature_err(&self.tcx.sess.parse_sess,
805-
"untagged_unions", item.span, GateIssue::Language,
805+
sym::untagged_unions, item.span, GateIssue::Language,
806806
"unions with `Drop` implementations are unstable");
807807
} else {
808808
let param_env = self.tcx.param_env(def_id);
809809
if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() {
810810
emit_feature_err(&self.tcx.sess.parse_sess,
811-
"untagged_unions", item.span, GateIssue::Language,
811+
sym::untagged_unions, item.span, GateIssue::Language,
812812
"unions with non-`Copy` fields are unstable");
813813
}
814814
}

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ rustc_queries! {
10521052
}
10531053

10541054
Other {
1055-
query target_features_whitelist(_: CrateNum) -> Lrc<FxHashMap<String, Option<String>>> {
1055+
query target_features_whitelist(_: CrateNum) -> Lrc<FxHashMap<String, Option<Symbol>>> {
10561056
eval_always
10571057
desc { "looking up the whitelist of target features" }
10581058
}

0 commit comments

Comments
 (0)