use crate::middle::resolve_lifetime as rl;
use rustc_ast::ast;
use rustc_ast::ast::MetaItemKind;
-use rustc_attr::{list_contains_name, mark_used, InlineAttr, OptimizeAttr};
+use rustc_attr::{list_contains_name, InlineAttr, OptimizeAttr};
use rustc_data_structures::captures::Captures;
-use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, DefKind, Res};
}
pub fn hir_id(&self) -> hir::HirId {
- self.tcx.hir().as_local_hir_id(self.item_def_id.expect_local())
+ self.tcx.hir().local_def_id_to_hir_id(self.item_def_id.expect_local())
}
pub fn node(&self) -> hir::Node<'tcx> {
// written inline like `<T: Foo>` or in a where-clause like
// `where T: Foo`.
- let param_id = tcx.hir().as_local_hir_id(def_id);
+ let param_id = tcx.hir().local_def_id_to_hir_id(def_id);
let param_owner = tcx.hir().ty_param_owner(param_id);
let param_owner_def_id = tcx.hir().local_def_id(param_owner);
let generics = tcx.generics_of(param_owner_def_id);
.unwrap_or_default();
let mut extend = None;
- let item_hir_id = tcx.hir().as_local_hir_id(item_def_id.expect_local());
+ let item_hir_id = tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local());
let ast_generics = match tcx.hir().get(item_hir_id) {
Node::TraitItem(item) => &item.generics,
parent_did: LocalDefId,
) -> ty::VariantDef {
let mut seen_fields: FxHashMap<Ident, Span> = Default::default();
- let hir_id = tcx.hir().as_local_hir_id(variant_did.unwrap_or(parent_did));
+ let hir_id = tcx.hir().local_def_id_to_hir_id(variant_did.unwrap_or(parent_did));
let fields = def
.fields()
.iter()
use rustc_hir::*;
let def_id = def_id.expect_local();
- let hir_id = tcx.hir().as_local_hir_id(def_id);
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let item = match tcx.hir().get(hir_id) {
Node::Item(item) => item,
_ => bug!(),
/// the transitive super-predicates are converted.
fn super_predicates_of(tcx: TyCtxt<'_>, trait_def_id: DefId) -> ty::GenericPredicates<'_> {
debug!("super_predicates(trait_def_id={:?})", trait_def_id);
- let trait_hir_id = tcx.hir().as_local_hir_id(trait_def_id.expect_local());
+ let trait_hir_id = tcx.hir().local_def_id_to_hir_id(trait_def_id.expect_local());
let item = match tcx.hir().get(trait_hir_id) {
Node::Item(item) => item,
}
fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef {
- let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let item = tcx.hir().expect_item(hir_id);
let (is_auto, unsafety) = match item.kind {
fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
use rustc_hir::*;
- let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let node = tcx.hir().get(hir_id);
let parent_def_id = match node {
use rustc_hir::*;
let def_id = def_id.expect_local();
- let hir_id = tcx.hir().as_local_hir_id(def_id);
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let icx = ItemCtxt::new(tcx, def_id.to_def_id());
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::TraitRef<'_>> {
let icx = ItemCtxt::new(tcx, def_id);
- let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
match tcx.hir().expect_item(hir_id).kind {
hir::ItemKind::Impl { ref of_trait, .. } => of_trait.as_ref().map(|ast_trait_ref| {
let selfty = tcx.type_of(def_id);
}
fn impl_polarity(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ImplPolarity {
- let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl);
let item = tcx.hir().expect_item(hir_id);
match &item.kind {
/// A data structure with unique elements, which preserves order of insertion.
/// Preserving the order of insertion is important here so as not to break
/// compile-fail UI tests.
- // FIXME(eddyb) just use `IndexSet` from `indexmap`.
struct UniquePredicates<'tcx> {
- predicates: Vec<(ty::Predicate<'tcx>, Span)>,
- uniques: FxHashSet<(ty::Predicate<'tcx>, Span)>,
+ predicates: FxIndexSet<(ty::Predicate<'tcx>, Span)>,
}
impl<'tcx> UniquePredicates<'tcx> {
fn new() -> Self {
- UniquePredicates { predicates: vec![], uniques: FxHashSet::default() }
+ UniquePredicates { predicates: FxIndexSet::default() }
}
fn push(&mut self, value: (ty::Predicate<'tcx>, Span)) {
- if self.uniques.insert(value) {
- self.predicates.push(value);
- }
+ self.predicates.insert(value);
}
fn extend<I: IntoIterator<Item = (ty::Predicate<'tcx>, Span)>>(&mut self, iter: I) {
}
}
- let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
+ let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let node = tcx.hir().get(hir_id);
let mut is_trait = None;
}))
}
- let mut predicates = predicates.predicates;
+ let mut predicates: Vec<_> = predicates.predicates.into_iter().collect();
// Subtle: before we store the predicates into the tcx, we
// sort them so that predicates like `T: Foo<Item=U>` come
let mut link_ordinal_span = None;
let mut no_sanitize_span = None;
for attr in attrs.iter() {
- if attr.check_name(sym::cold) {
+ if tcx.sess.check_name(attr, sym::cold) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
- } else if attr.check_name(sym::rustc_allocator) {
+ } else if tcx.sess.check_name(attr, sym::rustc_allocator) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR;
- } else if attr.check_name(sym::unwind) {
+ } else if tcx.sess.check_name(attr, sym::unwind) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::UNWIND;
- } else if attr.check_name(sym::ffi_returns_twice) {
+ } else if tcx.sess.check_name(attr, sym::ffi_returns_twice) {
if tcx.is_foreign_item(id) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_RETURNS_TWICE;
} else {
)
.emit();
}
- } else if attr.check_name(sym::ffi_pure) {
+ } else if tcx.sess.check_name(attr, sym::ffi_pure) {
if tcx.is_foreign_item(id) {
- if attrs.iter().any(|a| a.check_name(sym::ffi_const)) {
+ if attrs.iter().any(|a| tcx.sess.check_name(a, sym::ffi_const)) {
// `#[ffi_const]` functions cannot be `#[ffi_pure]`
struct_span_err!(
tcx.sess,
)
.emit();
}
- } else if attr.check_name(sym::ffi_const) {
+ } else if tcx.sess.check_name(attr, sym::ffi_const) {
if tcx.is_foreign_item(id) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::FFI_CONST;
} else {
)
.emit();
}
- } else if attr.check_name(sym::rustc_allocator_nounwind) {
+ } else if tcx.sess.check_name(attr, sym::rustc_allocator_nounwind) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_ALLOCATOR_NOUNWIND;
- } else if attr.check_name(sym::naked) {
+ } else if tcx.sess.check_name(attr, sym::naked) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED;
- } else if attr.check_name(sym::no_mangle) {
+ } else if tcx.sess.check_name(attr, sym::no_mangle) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
- } else if attr.check_name(sym::rustc_std_internal_symbol) {
+ } else if tcx.sess.check_name(attr, sym::rustc_std_internal_symbol) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
- } else if attr.check_name(sym::used) {
+ } else if tcx.sess.check_name(attr, sym::used) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
- } else if attr.check_name(sym::thread_local) {
+ } else if tcx.sess.check_name(attr, sym::thread_local) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL;
- } else if attr.check_name(sym::track_caller) {
+ } else if tcx.sess.check_name(attr, sym::track_caller) {
if tcx.is_closure(id) || tcx.fn_sig(id).abi() != abi::Abi::Rust {
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
.emit();
}
codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER;
- } else if attr.check_name(sym::export_name) {
+ } else if tcx.sess.check_name(attr, sym::export_name) {
if let Some(s) = attr.value_str() {
if s.as_str().contains('\0') {
// `#[export_name = ...]` will be converted to a null-terminated string,
}
codegen_fn_attrs.export_name = Some(s);
}
- } else if attr.check_name(sym::target_feature) {
+ } else if tcx.sess.check_name(attr, sym::target_feature) {
if !tcx.features().target_feature_11 {
check_target_feature_safe_fn(tcx, id, attr.span);
} else if let Some(local_id) = id.as_local() {
&supported_target_features,
&mut codegen_fn_attrs.target_features,
);
- } else if attr.check_name(sym::linkage) {
+ } else if tcx.sess.check_name(attr, sym::linkage) {
if let Some(val) = attr.value_str() {
codegen_fn_attrs.linkage = Some(linkage_by_name(tcx, id, &val.as_str()));
}
- } else if attr.check_name(sym::link_section) {
+ } else if tcx.sess.check_name(attr, sym::link_section) {
if let Some(val) = attr.value_str() {
if val.as_str().bytes().any(|b| b == 0) {
let msg = format!(
codegen_fn_attrs.link_section = Some(val);
}
}
- } else if attr.check_name(sym::link_name) {
+ } else if tcx.sess.check_name(attr, sym::link_name) {
codegen_fn_attrs.link_name = attr.value_str();
- } else if attr.check_name(sym::link_ordinal) {
+ } else if tcx.sess.check_name(attr, sym::link_ordinal) {
link_ordinal_span = Some(attr.span);
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {
codegen_fn_attrs.link_ordinal = ordinal;
}
- } else if attr.check_name(sym::no_sanitize) {
+ } else if tcx.sess.check_name(attr, sym::no_sanitize) {
no_sanitize_span = Some(attr.span);
if let Some(list) = attr.meta_item_list() {
for item in list.iter() {
}
match attr.meta().map(|i| i.kind) {
Some(MetaItemKind::Word) => {
- mark_used(attr);
+ tcx.sess.mark_attr_used(attr);
InlineAttr::Hint
}
Some(MetaItemKind::List(ref items)) => {
- mark_used(attr);
+ tcx.sess.mark_attr_used(attr);
inline_span = Some(attr.span);
if items.len() != 1 {
struct_span_err!(
ia
}
Some(MetaItemKind::List(ref items)) => {
- mark_used(attr);
+ tcx.sess.mark_attr_used(attr);
inline_span = Some(attr.span);
if items.len() != 1 {
err(attr.span, "expected one argument");
if !codegen_fn_attrs.no_sanitize.is_empty() {
if codegen_fn_attrs.inline == InlineAttr::Always {
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
- let hir_id = tcx.hir().as_local_hir_id(id.expect_local());
+ let hir_id = tcx.hir().local_def_id_to_hir_id(id.expect_local());
tcx.struct_span_lint_hir(
lint::builtin::INLINE_NO_SANITIZE,
hir_id,
if tcx.is_weak_lang_item(id) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
}
- if let Some(name) = weak_lang_items::link_name(&attrs) {
+ let check_name = |attr, sym| tcx.sess.check_name(attr, sym);
+ if let Some(name) = weak_lang_items::link_name(check_name, &attrs) {
codegen_fn_attrs.export_name = Some(name);
codegen_fn_attrs.link_name = Some(name);
}
/// Checks the function annotated with `#[target_feature]` is not a safe
/// trait method implementation, reporting an error if it is.
fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span: Span) {
- let hir_id = tcx.hir().as_local_hir_id(id);
+ let hir_id = tcx.hir().local_def_id_to_hir_id(id);
let node = tcx.hir().get(hir_id);
if let Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) = node {
let parent_id = tcx.hir().get_parent_item(hir_id);