Pass a Symbol to check_name, emit_feature_err, and related functions.
This commit is contained in:
parent
79602c87b5
commit
fb084a48e2
114 changed files with 671 additions and 621 deletions
|
|
@ -12,6 +12,7 @@ use crate::hir;
|
|||
use crate::hir::def_id::DefId;
|
||||
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
use std::fmt::{self, Display};
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::Span;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
|
|
@ -95,18 +96,18 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
|||
fn check_attributes(&self, item: &hir::Item, target: Target) {
|
||||
if target == Target::Fn || target == Target::Const {
|
||||
self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id_from_hir_id(item.hir_id));
|
||||
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name("target_feature")) {
|
||||
} else if let Some(a) = item.attrs.iter().find(|a| a.check_name(sym::target_feature)) {
|
||||
self.tcx.sess.struct_span_err(a.span, "attribute should be applied to a function")
|
||||
.span_label(item.span, "not a function")
|
||||
.emit();
|
||||
}
|
||||
|
||||
for attr in &item.attrs {
|
||||
if attr.check_name("inline") {
|
||||
if attr.check_name(sym::inline) {
|
||||
self.check_inline(attr, &item.span, target)
|
||||
} else if attr.check_name("non_exhaustive") {
|
||||
} else if attr.check_name(sym::non_exhaustive) {
|
||||
self.check_non_exhaustive(attr, item, target)
|
||||
} else if attr.check_name("marker") {
|
||||
} else if attr.check_name(sym::marker) {
|
||||
self.check_marker(attr, item, target)
|
||||
}
|
||||
}
|
||||
|
|
@ -166,7 +167,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
|||
// ```
|
||||
let hints: Vec<_> = item.attrs
|
||||
.iter()
|
||||
.filter(|attr| attr.check_name("repr"))
|
||||
.filter(|attr| attr.check_name(sym::repr))
|
||||
.filter_map(|attr| attr.meta_item_list())
|
||||
.flatten()
|
||||
.collect();
|
||||
|
|
@ -268,10 +269,10 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
|||
// When checking statements ignore expressions, they will be checked later
|
||||
if let hir::StmtKind::Local(ref l) = stmt.node {
|
||||
for attr in l.attrs.iter() {
|
||||
if attr.check_name("inline") {
|
||||
if attr.check_name(sym::inline) {
|
||||
self.check_inline(attr, &stmt.span, Target::Statement);
|
||||
}
|
||||
if attr.check_name("repr") {
|
||||
if attr.check_name(sym::repr) {
|
||||
self.emit_repr_error(
|
||||
attr.span,
|
||||
stmt.span,
|
||||
|
|
@ -289,10 +290,10 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
|||
_ => Target::Expression,
|
||||
};
|
||||
for attr in expr.attrs.iter() {
|
||||
if attr.check_name("inline") {
|
||||
if attr.check_name(sym::inline) {
|
||||
self.check_inline(attr, &expr.span, target);
|
||||
}
|
||||
if attr.check_name("repr") {
|
||||
if attr.check_name(sym::repr) {
|
||||
self.emit_repr_error(
|
||||
attr.span,
|
||||
expr.span,
|
||||
|
|
@ -305,7 +306,7 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
|
|||
|
||||
fn check_used(&self, item: &hir::Item, target: Target) {
|
||||
for attr in &item.attrs {
|
||||
if attr.check_name("used") && target != Target::Static {
|
||||
if attr.check_name(sym::used) && target != Target::Static {
|
||||
self.tcx.sess
|
||||
.span_err(attr.span, "attribute must be applied to a `static` variable");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ use syntax::ptr::P;
|
|||
use syntax::source_map::{respan, CompilerDesugaringKind, Spanned};
|
||||
use syntax::source_map::CompilerDesugaringKind::IfTemporary;
|
||||
use syntax::std_inject;
|
||||
use syntax::symbol::{keywords, Symbol};
|
||||
use syntax::symbol::{keywords, Symbol, sym};
|
||||
use syntax::tokenstream::{TokenStream, TokenTree};
|
||||
use syntax::parse::token::Token;
|
||||
use syntax::visit::{self, Visitor};
|
||||
|
|
@ -2727,7 +2727,7 @@ impl<'a> LoweringContext<'a> {
|
|||
self.lower_ty(x, ImplTraitContext::disallowed())
|
||||
}),
|
||||
synthetic: param.attrs.iter()
|
||||
.filter(|attr| attr.check_name("rustc_synthetic"))
|
||||
.filter(|attr| attr.check_name(sym::rustc_synthetic))
|
||||
.map(|_| hir::SyntheticTyParamKind::ImplTrait)
|
||||
.next(),
|
||||
};
|
||||
|
|
@ -2745,7 +2745,7 @@ impl<'a> LoweringContext<'a> {
|
|||
hir_id: self.lower_node_id(param.id),
|
||||
name,
|
||||
span: param.ident.span,
|
||||
pure_wrt_drop: attr::contains_name(¶m.attrs, "may_dangle"),
|
||||
pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
|
||||
attrs: self.lower_attrs(¶m.attrs),
|
||||
bounds,
|
||||
kind,
|
||||
|
|
@ -3773,8 +3773,8 @@ impl<'a> LoweringContext<'a> {
|
|||
let mut vis = self.lower_visibility(&i.vis, None);
|
||||
let attrs = self.lower_attrs(&i.attrs);
|
||||
if let ItemKind::MacroDef(ref def) = i.node {
|
||||
if !def.legacy || attr::contains_name(&i.attrs, "macro_export") ||
|
||||
attr::contains_name(&i.attrs, "rustc_doc_only_macro") {
|
||||
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) ||
|
||||
attr::contains_name(&i.attrs, sym::rustc_doc_only_macro) {
|
||||
let body = self.lower_token_stream(def.stream());
|
||||
let hir_id = self.lower_node_id(i.id);
|
||||
self.exported_macros.push(hir::MacroDef {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use smallvec::SmallVec;
|
|||
|
||||
fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
|
||||
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
|
||||
ich::IGNORED_ATTRIBUTES.iter().map(|&s| Symbol::intern(s)).collect()
|
||||
ich::IGNORED_ATTRIBUTES.iter().map(|&s| s).collect()
|
||||
}
|
||||
|
||||
/// This is the context state available during incr. comp. hashing. It contains
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ crate use rustc_data_structures::fingerprint::Fingerprint;
|
|||
pub use self::caching_source_map_view::CachingSourceMapView;
|
||||
pub use self::hcx::{StableHashingContextProvider, StableHashingContext, NodeIdHashingMode,
|
||||
hash_stable_trait_impls};
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
|
||||
mod caching_source_map_view;
|
||||
mod hcx;
|
||||
|
||||
|
|
@ -12,16 +14,16 @@ mod impls_misc;
|
|||
mod impls_ty;
|
||||
mod impls_syntax;
|
||||
|
||||
pub const ATTR_DIRTY: &str = "rustc_dirty";
|
||||
pub const ATTR_CLEAN: &str = "rustc_clean";
|
||||
pub const ATTR_IF_THIS_CHANGED: &str = "rustc_if_this_changed";
|
||||
pub const ATTR_THEN_THIS_WOULD_NEED: &str = "rustc_then_this_would_need";
|
||||
pub const ATTR_PARTITION_REUSED: &str = "rustc_partition_reused";
|
||||
pub const ATTR_PARTITION_CODEGENED: &str = "rustc_partition_codegened";
|
||||
pub const ATTR_EXPECTED_CGU_REUSE: &str = "rustc_expected_cgu_reuse";
|
||||
pub const ATTR_DIRTY: Symbol = sym::rustc_dirty;
|
||||
pub const ATTR_CLEAN: Symbol = sym::rustc_clean;
|
||||
pub const ATTR_IF_THIS_CHANGED: Symbol = sym::rustc_if_this_changed;
|
||||
pub const ATTR_THEN_THIS_WOULD_NEED: Symbol = sym::rustc_then_this_would_need;
|
||||
pub const ATTR_PARTITION_REUSED: Symbol = sym::rustc_partition_reused;
|
||||
pub const ATTR_PARTITION_CODEGENED: Symbol = sym::rustc_partition_codegened;
|
||||
pub const ATTR_EXPECTED_CGU_REUSE: Symbol = sym::rustc_expected_cgu_reuse;
|
||||
|
||||
pub const IGNORED_ATTRIBUTES: &[&str] = &[
|
||||
"cfg",
|
||||
pub const IGNORED_ATTRIBUTES: &[Symbol] = &[
|
||||
sym::cfg,
|
||||
ATTR_IF_THIS_CHANGED,
|
||||
ATTR_THEN_THIS_WOULD_NEED,
|
||||
ATTR_DIRTY,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use syntax::ast;
|
|||
use syntax::attr;
|
||||
use syntax::feature_gate;
|
||||
use syntax::source_map::MultiSpan;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
|
||||
pub struct LintLevelSets {
|
||||
list: Vec<LintSet>,
|
||||
|
|
@ -230,7 +230,7 @@ impl<'a> LintLevelsBuilder<'a> {
|
|||
if !self.sess.features_untracked().lint_reasons {
|
||||
feature_gate::emit_feature_err(
|
||||
&self.sess.parse_sess,
|
||||
"lint_reasons",
|
||||
sym::lint_reasons,
|
||||
item.span,
|
||||
feature_gate::GateIssue::Language,
|
||||
"lint reasons are experimental"
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use rustc_data_structures::fx::FxHashMap;
|
|||
|
||||
use syntax::{ast, source_map};
|
||||
use syntax::attr;
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos;
|
||||
|
||||
// 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> {
|
|||
fn has_allow_dead_code_or_lang_attr(tcx: TyCtxt<'_, '_, '_>,
|
||||
id: hir::HirId,
|
||||
attrs: &[ast::Attribute]) -> bool {
|
||||
if attr::contains_name(attrs, "lang") {
|
||||
if attr::contains_name(attrs, sym::lang) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Stable attribute for #[lang = "panic_impl"]
|
||||
if attr::contains_name(attrs, "panic_handler") {
|
||||
if attr::contains_name(attrs, sym::panic_handler) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// (To be) stable attribute for #[lang = "oom"]
|
||||
if attr::contains_name(attrs, "alloc_error_handler") {
|
||||
if attr::contains_name(attrs, sym::alloc_error_handler) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't lint about global allocators
|
||||
if attr::contains_name(attrs, "global_allocator") {
|
||||
if attr::contains_name(attrs, sym::global_allocator) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use crate::session::{config, Session};
|
|||
use crate::session::config::EntryFnType;
|
||||
use syntax::attr;
|
||||
use syntax::entry::EntryPointType;
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::Span;
|
||||
use crate::hir::{HirId, Item, ItemKind, ImplItem, TraitItem};
|
||||
use crate::hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
|
@ -58,7 +59,7 @@ fn entry_fn(tcx: TyCtxt<'_, '_, '_>, cnum: CrateNum) -> Option<(DefId, EntryFnTy
|
|||
}
|
||||
|
||||
// If the user wants no main function at all, then stop here.
|
||||
if attr::contains_name(&tcx.hir().krate().attrs, "no_main") {
|
||||
if attr::contains_name(&tcx.hir().krate().attrs, sym::no_main) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +82,9 @@ fn entry_fn(tcx: TyCtxt<'_, '_, '_>, cnum: CrateNum) -> Option<(DefId, EntryFnTy
|
|||
fn entry_point_type(item: &Item, at_root: bool) -> EntryPointType {
|
||||
match item.node {
|
||||
ItemKind::Fn(..) => {
|
||||
if attr::contains_name(&item.attrs, "start") {
|
||||
if attr::contains_name(&item.attrs, sym::start) {
|
||||
EntryPointType::Start
|
||||
} else if attr::contains_name(&item.attrs, "main") {
|
||||
} else if attr::contains_name(&item.attrs, sym::main) {
|
||||
EntryPointType::MainAttr
|
||||
} else if item.ident.name == "main" {
|
||||
if at_root {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use crate::middle::weak_lang_items;
|
|||
use crate::util::nodemap::FxHashMap;
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax_pos::Span;
|
||||
use rustc_macros::HashStable;
|
||||
use crate::hir::itemlikevisit::ItemLikeVisitor;
|
||||
|
|
@ -209,9 +209,9 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
|
|||
/// are also extracted out when found.
|
||||
pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
|
||||
attrs.iter().find_map(|attr| Some(match attr {
|
||||
_ if attr.check_name("lang") => (attr.value_str()?, attr.span),
|
||||
_ if attr.check_name("panic_handler") => (Symbol::intern("panic_impl"), attr.span),
|
||||
_ if attr.check_name("alloc_error_handler") => (Symbol::intern("oom"), attr.span),
|
||||
_ if attr.check_name(sym::lang) => (attr.value_str()?, attr.span),
|
||||
_ if attr.check_name(sym::panic_handler) => (Symbol::intern("panic_impl"), attr.span),
|
||||
_ if attr.check_name(sym::alloc_error_handler) => (Symbol::intern("oom"), attr.span),
|
||||
_ => return None,
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ use std::io;
|
|||
use std::rc::Rc;
|
||||
use syntax::ast::{self, NodeId};
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use crate::hir;
|
||||
|
|
@ -362,7 +362,7 @@ fn visit_fn<'a, 'tcx: 'a>(ir: &mut IrMaps<'a, 'tcx>,
|
|||
if let FnKind::Method(..) = fk {
|
||||
let parent = ir.tcx.hir().get_parent_item(id);
|
||||
if let Some(Node::Item(i)) = ir.tcx.hir().find_by_hir_id(parent) {
|
||||
if i.attrs.iter().any(|a| a.check_name("automatically_derived")) {
|
||||
if i.attrs.iter().any(|a| a.check_name(sym::automatically_derived)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ use crate::hir::{MutImmutable, MutMutable, PatKind};
|
|||
use crate::hir::pat_util::EnumerateAndAdjustIterator;
|
||||
use crate::hir;
|
||||
use syntax::ast::{self, Name};
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::Span;
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
|
@ -714,7 +715,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
|||
// they also cannot be moved out of.
|
||||
let is_thread_local = self.tcx.get_attrs(def_id)[..]
|
||||
.iter()
|
||||
.any(|attr| attr.check_name("thread_local"));
|
||||
.any(|attr| attr.check_name(sym::thread_local));
|
||||
|
||||
let cat = if is_thread_local {
|
||||
let re = self.temporary_scope(hir_id.local_id);
|
||||
|
|
|
|||
|
|
@ -7,15 +7,16 @@
|
|||
|
||||
use crate::session::Session;
|
||||
use syntax::ast;
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
|
||||
use rustc_data_structures::sync::Once;
|
||||
|
||||
pub fn update_limits(sess: &Session, krate: &ast::Crate) {
|
||||
update_limit(krate, &sess.recursion_limit, "recursion_limit", 64);
|
||||
update_limit(krate, &sess.type_length_limit, "type_length_limit", 1048576);
|
||||
update_limit(krate, &sess.recursion_limit, sym::recursion_limit, 64);
|
||||
update_limit(krate, &sess.type_length_limit, sym::type_length_limit, 1048576);
|
||||
}
|
||||
|
||||
fn update_limit(krate: &ast::Crate, limit: &Once<usize>, name: &str, default: usize) {
|
||||
fn update_limit(krate: &ast::Crate, limit: &Once<usize>, name: Symbol, default: usize) {
|
||||
for attr in &krate.attrs {
|
||||
if !attr.check_name(name) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ use std::mem::replace;
|
|||
use syntax::ast;
|
||||
use syntax::attr;
|
||||
use syntax::ptr::P;
|
||||
use syntax::symbol::keywords;
|
||||
use syntax::symbol::{keywords, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use crate::hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
|
|
@ -1285,7 +1285,7 @@ fn compute_object_lifetime_defaults(
|
|||
let result = object_lifetime_defaults_for_item(tcx, generics);
|
||||
|
||||
// Debugging aid.
|
||||
if attr::contains_name(&item.attrs, "rustc_object_lifetime_default") {
|
||||
if attr::contains_name(&item.attrs, sym::rustc_object_lifetime_default) {
|
||||
let object_lifetime_default_reprs: String = result
|
||||
.iter()
|
||||
.map(|set| match *set {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
|||
use crate::ty::query::Providers;
|
||||
use crate::middle::privacy::AccessLevels;
|
||||
use crate::session::{DiagnosticMessageId, Session};
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax_pos::{Span, MultiSpan};
|
||||
use syntax::ast::Attribute;
|
||||
use syntax::errors::Applicability;
|
||||
|
|
@ -669,7 +669,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
match stability {
|
||||
Some(&Stability { level: attr::Unstable { reason, issue }, feature, .. }) => {
|
||||
if span.allows_unstable(&feature.as_str()) {
|
||||
if span.allows_unstable(feature) {
|
||||
debug!("stability: skipping span={:?} since it is internal", span);
|
||||
return EvalResult::Allow;
|
||||
}
|
||||
|
|
@ -739,7 +739,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
|
||||
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(error_id);
|
||||
if fresh {
|
||||
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
|
||||
emit_feature_err(&self.sess.parse_sess, feature, span,
|
||||
GateIssue::Library(Some(issue)), &msg);
|
||||
}
|
||||
}
|
||||
|
|
@ -802,13 +802,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
|
|||
|
||||
if adt_def.has_dtor(self.tcx) {
|
||||
emit_feature_err(&self.tcx.sess.parse_sess,
|
||||
"untagged_unions", item.span, GateIssue::Language,
|
||||
sym::untagged_unions, item.span, GateIssue::Language,
|
||||
"unions with `Drop` implementations are unstable");
|
||||
} else {
|
||||
let param_env = self.tcx.param_env(def_id);
|
||||
if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() {
|
||||
emit_feature_err(&self.tcx.sess.parse_sess,
|
||||
"untagged_unions", item.span, GateIssue::Language,
|
||||
sym::untagged_unions, item.span, GateIssue::Language,
|
||||
"unions with non-`Copy` fields are unstable");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1052,7 +1052,7 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
Other {
|
||||
query target_features_whitelist(_: CrateNum) -> Lrc<FxHashMap<String, Option<String>>> {
|
||||
query target_features_whitelist(_: CrateNum) -> Lrc<FxHashMap<String, Option<Symbol>>> {
|
||||
eval_always
|
||||
desc { "looking up the whitelist of target features" }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ use syntax::feature_gate::{self, AttributeType};
|
|||
use syntax::json::JsonEmitter;
|
||||
use syntax::source_map;
|
||||
use syntax::parse::{self, ParseSess};
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax_pos::{MultiSpan, Span};
|
||||
use crate::util::profiling::SelfProfiler;
|
||||
|
||||
|
|
@ -86,7 +87,7 @@ pub struct Session {
|
|||
/// in order to avoid redundantly verbose output (Issue #24690, #44953).
|
||||
pub one_time_diagnostics: Lock<FxHashSet<(DiagnosticMessageId, Option<Span>, String)>>,
|
||||
pub plugin_llvm_passes: OneThread<RefCell<Vec<String>>>,
|
||||
pub plugin_attributes: Lock<Vec<(String, AttributeType)>>,
|
||||
pub plugin_attributes: Lock<Vec<(Symbol, AttributeType)>>,
|
||||
pub crate_types: Once<Vec<config::CrateType>>,
|
||||
pub dependency_formats: Once<dependency_format::Dependencies>,
|
||||
/// The crate_disambiguator is constructed out of all the `-C metadata`
|
||||
|
|
|
|||
|
|
@ -4,17 +4,16 @@
|
|||
//! [trait-resolution]: https://rust-lang.github.io/rustc-guide/traits/resolution.html
|
||||
//! [trait-specialization]: https://rust-lang.github.io/rustc-guide/traits/specialization.html
|
||||
|
||||
use crate::infer::CombinedSnapshot;
|
||||
use crate::infer::{CombinedSnapshot, InferOk};
|
||||
use crate::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use syntax_pos::DUMMY_SP;
|
||||
use crate::traits::{self, Normalized, SelectionContext, Obligation, ObligationCause};
|
||||
use crate::traits::IntercrateMode;
|
||||
use crate::traits::select::IntercrateAmbiguityCause;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::subst::Subst;
|
||||
|
||||
use crate::infer::{InferOk};
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::DUMMY_SP;
|
||||
|
||||
/// Whether we do the orphan check relative to this crate or
|
||||
/// to some remote crate.
|
||||
|
|
@ -233,7 +232,7 @@ pub fn trait_ref_is_knowable<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
|||
pub fn trait_ref_is_local_or_fundamental<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
|
||||
trait_ref: ty::TraitRef<'tcx>)
|
||||
-> bool {
|
||||
trait_ref.def_id.krate == LOCAL_CRATE || tcx.has_attr(trait_ref.def_id, "fundamental")
|
||||
trait_ref.def_id.krate == LOCAL_CRATE || tcx.has_attr(trait_ref.def_id, sym::fundamental)
|
||||
}
|
||||
|
||||
pub enum OrphanCheckErr<'tcx> {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ use crate::util::nodemap::{FxHashMap, FxHashSet};
|
|||
use errors::{Applicability, DiagnosticBuilder};
|
||||
use std::fmt;
|
||||
use syntax::ast;
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::{DUMMY_SP, Span, ExpnInfo, ExpnFormat};
|
||||
|
||||
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
||||
|
|
@ -329,7 +330,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
return None
|
||||
};
|
||||
|
||||
if tcx.has_attr(impl_def_id, "rustc_on_unimplemented") {
|
||||
if tcx.has_attr(impl_def_id, sym::rustc_on_unimplemented) {
|
||||
Some(impl_def_id)
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use crate::util::nodemap::FxHashMap;
|
|||
|
||||
use syntax::ast::{MetaItem, NestedMetaItem};
|
||||
use syntax::attr;
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::Span;
|
||||
use syntax_pos::symbol::LocalInternedString;
|
||||
|
||||
|
|
@ -84,25 +85,25 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
|
|||
let mut note = None;
|
||||
let mut subcommands = vec![];
|
||||
for item in item_iter {
|
||||
if item.check_name("message") && message.is_none() {
|
||||
if item.check_name(sym::message) && message.is_none() {
|
||||
if let Some(message_) = item.value_str() {
|
||||
message = Some(OnUnimplementedFormatString::try_parse(
|
||||
tcx, trait_def_id, message_.as_str(), span)?);
|
||||
continue;
|
||||
}
|
||||
} else if item.check_name("label") && label.is_none() {
|
||||
} else if item.check_name(sym::label) && label.is_none() {
|
||||
if let Some(label_) = item.value_str() {
|
||||
label = Some(OnUnimplementedFormatString::try_parse(
|
||||
tcx, trait_def_id, label_.as_str(), span)?);
|
||||
continue;
|
||||
}
|
||||
} else if item.check_name("note") && note.is_none() {
|
||||
} else if item.check_name(sym::note) && note.is_none() {
|
||||
if let Some(note_) = item.value_str() {
|
||||
note = Some(OnUnimplementedFormatString::try_parse(
|
||||
tcx, trait_def_id, note_.as_str(), span)?);
|
||||
continue;
|
||||
}
|
||||
} else if item.check_name("on") && is_root &&
|
||||
} else if item.check_name(sym::on) && is_root &&
|
||||
message.is_none() && label.is_none() && note.is_none()
|
||||
{
|
||||
if let Some(items) = item.meta_item_list() {
|
||||
|
|
@ -139,7 +140,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedDirective {
|
|||
{
|
||||
let attrs = tcx.get_attrs(impl_def_id);
|
||||
|
||||
let attr = if let Some(item) = attr::find_by_name(&attrs, "rustc_on_unimplemented") {
|
||||
let attr = if let Some(item) = attr::find_by_name(&attrs, sym::rustc_on_unimplemented) {
|
||||
item
|
||||
} else {
|
||||
return Ok(None);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ use syntax::ast;
|
|||
use syntax::attr;
|
||||
use syntax::source_map::MultiSpan;
|
||||
use syntax::feature_gate;
|
||||
use syntax::symbol::{Symbol, keywords, InternedString};
|
||||
use syntax::symbol::{Symbol, keywords, InternedString, sym};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use crate::hir;
|
||||
|
|
@ -1213,7 +1213,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
span_bug!(attr.span, "no arguments to `rustc_layout_scalar_valid_range` attribute");
|
||||
};
|
||||
(get("rustc_layout_scalar_valid_range_start"), get("rustc_layout_scalar_valid_range_end"))
|
||||
(get(sym::rustc_layout_scalar_valid_range_start),
|
||||
get(sym::rustc_layout_scalar_valid_range_end))
|
||||
}
|
||||
|
||||
pub fn lift<T: ?Sized + Lift<'tcx>>(self, value: &T) -> Option<T::Lifted> {
|
||||
|
|
@ -3102,10 +3103,10 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
|
|||
};
|
||||
providers.is_panic_runtime = |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
attr::contains_name(tcx.hir().krate_attrs(), "panic_runtime")
|
||||
attr::contains_name(tcx.hir().krate_attrs(), sym::panic_runtime)
|
||||
};
|
||||
providers.is_compiler_builtins = |tcx, cnum| {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
attr::contains_name(tcx.hir().krate_attrs(), "compiler_builtins")
|
||||
attr::contains_name(tcx.hir().krate_attrs(), sym::compiler_builtins)
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ use std::ops::Range;
|
|||
use syntax::ast::{self, Name, Ident, NodeId};
|
||||
use syntax::attr;
|
||||
use syntax::ext::hygiene::Mark;
|
||||
use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
|
||||
use syntax::symbol::{keywords, sym, Symbol, LocalInternedString, InternedString};
|
||||
use syntax_pos::Span;
|
||||
|
||||
use smallvec;
|
||||
|
|
@ -1875,11 +1875,11 @@ impl<'a, 'gcx, 'tcx> VariantDef {
|
|||
);
|
||||
|
||||
let mut flags = VariantFlags::NO_VARIANT_FLAGS;
|
||||
if adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, "non_exhaustive") {
|
||||
if adt_kind == AdtKind::Struct && tcx.has_attr(parent_did, sym::non_exhaustive) {
|
||||
debug!("found non-exhaustive field list for {:?}", parent_did);
|
||||
flags = flags | VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
|
||||
} else if let Some(variant_did) = variant_did {
|
||||
if tcx.has_attr(variant_did, "non_exhaustive") {
|
||||
if tcx.has_attr(variant_did, sym::non_exhaustive) {
|
||||
debug!("found non-exhaustive field list for {:?}", variant_did);
|
||||
flags = flags | VariantFlags::IS_FIELD_LIST_NON_EXHAUSTIVE;
|
||||
}
|
||||
|
|
@ -2156,7 +2156,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
debug!("AdtDef::new({:?}, {:?}, {:?}, {:?})", did, kind, variants, repr);
|
||||
let mut flags = AdtFlags::NO_ADT_FLAGS;
|
||||
|
||||
if kind == AdtKind::Enum && tcx.has_attr(did, "non_exhaustive") {
|
||||
if kind == AdtKind::Enum && tcx.has_attr(did, sym::non_exhaustive) {
|
||||
debug!("found non-exhaustive variant list for {:?}", did);
|
||||
flags = flags | AdtFlags::IS_VARIANT_LIST_NON_EXHAUSTIVE;
|
||||
}
|
||||
|
|
@ -2172,7 +2172,7 @@ impl<'a, 'gcx, 'tcx> AdtDef {
|
|||
}
|
||||
|
||||
let attrs = tcx.get_attrs(did);
|
||||
if attr::contains_name(&attrs, "fundamental") {
|
||||
if attr::contains_name(&attrs, sym::fundamental) {
|
||||
flags |= AdtFlags::IS_FUNDAMENTAL;
|
||||
}
|
||||
if Some(did) == tcx.lang_items().phantom_data() {
|
||||
|
|
@ -3030,7 +3030,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
|
||||
/// Determines whether an item is annotated with an attribute.
|
||||
pub fn has_attr(self, did: DefId, attr: &str) -> bool {
|
||||
pub fn has_attr(self, did: DefId, attr: Symbol) -> bool {
|
||||
attr::contains_name(&self.get_attrs(did), attr)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use rustc_macros::HashStable;
|
|||
use std::{cmp, fmt};
|
||||
use syntax::ast;
|
||||
use syntax::attr::{self, SignedInt, UnsignedInt};
|
||||
use syntax::symbol::sym;
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
|
@ -447,7 +448,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
// Such access can be in plain sight (e.g., dereferencing
|
||||
// `*foo.0` of `Foo<'a>(&'a u32)`) or indirectly hidden
|
||||
// (e.g., calling `foo.0.clone()` of `Foo<T:Clone>`).
|
||||
if self.has_attr(dtor, "unsafe_destructor_blind_to_params") {
|
||||
if self.has_attr(dtor, sym::unsafe_destructor_blind_to_params) {
|
||||
debug!("destructor_constraint({:?}) - blind", def.did);
|
||||
return vec![];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue