mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
More symbol usage
This commit is contained in:
parent
c30bdfcc84
commit
df5f1777b8
50 changed files with 388 additions and 303 deletions
|
@ -24,6 +24,7 @@ use hir_expand::{
|
|||
name::{AsName, Name},
|
||||
HirFileId, MacroFileIdExt,
|
||||
};
|
||||
use intern::sym;
|
||||
use stdx::{always, never};
|
||||
use syntax::{
|
||||
ast::{self, HasName},
|
||||
|
@ -163,8 +164,8 @@ impl<'a> DeclValidator<'a> {
|
|||
let is_allowed = |def_id| {
|
||||
let attrs = self.db.attrs(def_id);
|
||||
// don't bug the user about directly no_mangle annotated stuff, they can't do anything about it
|
||||
(!recursing && attrs.by_key("no_mangle").exists())
|
||||
|| attrs.by_key("allow").tt_values().any(|tt| {
|
||||
(!recursing && attrs.by_key(&sym::no_mangle).exists())
|
||||
|| attrs.by_key(&sym::allow).tt_values().any(|tt| {
|
||||
let allows = tt.to_string();
|
||||
allows.contains(allow_name)
|
||||
|| allows.contains(allow::BAD_STYLE)
|
||||
|
|
|
@ -101,7 +101,7 @@ impl<'db> MatchCheckCtx<'db> {
|
|||
/// Returns whether the given ADT is from another crate declared `#[non_exhaustive]`.
|
||||
fn is_foreign_non_exhaustive(&self, adt: hir_def::AdtId) -> bool {
|
||||
let is_local = adt.krate(self.db.upcast()) == self.module.krate();
|
||||
!is_local && self.db.attrs(adt.into()).by_key("non_exhaustive").exists()
|
||||
!is_local && self.db.attrs(adt.into()).by_key(&sym::non_exhaustive).exists()
|
||||
}
|
||||
|
||||
fn variant_id_for_adt(
|
||||
|
|
|
@ -1935,7 +1935,7 @@ impl HirDisplay for TypeRef {
|
|||
}
|
||||
if let Some(abi) = abi {
|
||||
f.write_str("extern \"")?;
|
||||
f.write_str(abi)?;
|
||||
f.write_str(abi.as_str())?;
|
||||
f.write_str("\" ")?;
|
||||
}
|
||||
write!(f, "fn(")?;
|
||||
|
@ -2044,7 +2044,7 @@ impl HirDisplay for Path {
|
|||
.display_name
|
||||
.as_ref()
|
||||
.map(|name| name.canonical_name())
|
||||
.unwrap_or("$crate");
|
||||
.unwrap_or(&sym::dollar_crate);
|
||||
write!(f, "{name}")?
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use chalk_ir::{
|
|||
DebruijnIndex,
|
||||
};
|
||||
use hir_def::{visibility::Visibility, AdtId, EnumVariantId, HasModule, ModuleId, VariantId};
|
||||
use intern::sym;
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{
|
||||
|
@ -118,7 +119,7 @@ impl UninhabitedFrom<'_> {
|
|||
subst: &Substitution,
|
||||
) -> ControlFlow<VisiblyUninhabited> {
|
||||
let is_local = variant.krate(self.db.upcast()) == self.target_mod.krate();
|
||||
if !is_local && self.db.attrs(variant.into()).by_key("non_exhaustive").exists() {
|
||||
if !is_local && self.db.attrs(variant.into()).by_key(&sym::non_exhaustive).exists() {
|
||||
return CONTINUE_OPAQUELY_INHABITED;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use hir_def::{
|
|||
layout::{Integer, LayoutCalculator, ReprOptions, TargetDataLayout},
|
||||
AdtId, VariantId,
|
||||
};
|
||||
use intern::sym;
|
||||
use rustc_index::IndexVec;
|
||||
use smallvec::SmallVec;
|
||||
use triomphe::Arc;
|
||||
|
@ -129,7 +130,10 @@ fn layout_scalar_valid_range(db: &dyn HirDatabase, def: AdtId) -> (Bound<u128>,
|
|||
}
|
||||
Bound::Unbounded
|
||||
};
|
||||
(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 layout_of_adt_recover(
|
||||
|
|
|
@ -62,7 +62,7 @@ use chalk_ir::{
|
|||
use either::Either;
|
||||
use hir_def::{hir::ExprId, type_ref::Rawness, CallableDefId, GeneralConstId, TypeOrConstParamId};
|
||||
use hir_expand::name::Name;
|
||||
use intern::sym;
|
||||
use intern::{sym, Symbol};
|
||||
use la_arena::{Arena, Idx};
|
||||
use mir::{MirEvalError, VTableMap};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
@ -423,45 +423,45 @@ impl Hash for FnAbi {
|
|||
}
|
||||
|
||||
impl FnAbi {
|
||||
#[allow(clippy::should_implement_trait)]
|
||||
pub fn from_str(s: &str) -> FnAbi {
|
||||
#[rustfmt::skip]
|
||||
pub fn from_symbol(s: &Symbol) -> FnAbi {
|
||||
match s {
|
||||
"aapcs-unwind" => FnAbi::AapcsUnwind,
|
||||
"aapcs" => FnAbi::Aapcs,
|
||||
"avr-interrupt" => FnAbi::AvrInterrupt,
|
||||
"avr-non-blocking-interrupt" => FnAbi::AvrNonBlockingInterrupt,
|
||||
"C-cmse-nonsecure-call" => FnAbi::CCmseNonsecureCall,
|
||||
"C-unwind" => FnAbi::CUnwind,
|
||||
"C" => FnAbi::C,
|
||||
"cdecl-unwind" => FnAbi::CDeclUnwind,
|
||||
"cdecl" => FnAbi::CDecl,
|
||||
"efiapi" => FnAbi::Efiapi,
|
||||
"fastcall-unwind" => FnAbi::FastcallUnwind,
|
||||
"fastcall" => FnAbi::Fastcall,
|
||||
"msp430-interrupt" => FnAbi::Msp430Interrupt,
|
||||
"platform-intrinsic" => FnAbi::PlatformIntrinsic,
|
||||
"ptx-kernel" => FnAbi::PtxKernel,
|
||||
"riscv-interrupt-m" => FnAbi::RiscvInterruptM,
|
||||
"riscv-interrupt-s" => FnAbi::RiscvInterruptS,
|
||||
"rust-call" => FnAbi::RustCall,
|
||||
"rust-cold" => FnAbi::RustCold,
|
||||
"rust-intrinsic" => FnAbi::RustIntrinsic,
|
||||
"Rust" => FnAbi::Rust,
|
||||
"stdcall-unwind" => FnAbi::StdcallUnwind,
|
||||
"stdcall" => FnAbi::Stdcall,
|
||||
"system-unwind" => FnAbi::SystemUnwind,
|
||||
"system" => FnAbi::System,
|
||||
"sysv64-unwind" => FnAbi::Sysv64Unwind,
|
||||
"sysv64" => FnAbi::Sysv64,
|
||||
"thiscall-unwind" => FnAbi::ThiscallUnwind,
|
||||
"thiscall" => FnAbi::Thiscall,
|
||||
"unadjusted" => FnAbi::Unadjusted,
|
||||
"vectorcall-unwind" => FnAbi::VectorcallUnwind,
|
||||
"vectorcall" => FnAbi::Vectorcall,
|
||||
"wasm" => FnAbi::Wasm,
|
||||
"win64-unwind" => FnAbi::Win64Unwind,
|
||||
"win64" => FnAbi::Win64,
|
||||
"x86-interrupt" => FnAbi::X86Interrupt,
|
||||
s if *s == sym::aapcs_dash_unwind => FnAbi::AapcsUnwind,
|
||||
s if *s == sym::aapcs => FnAbi::Aapcs,
|
||||
s if *s == sym::avr_dash_interrupt => FnAbi::AvrInterrupt,
|
||||
s if *s == sym::avr_dash_non_dash_blocking_dash_interrupt => FnAbi::AvrNonBlockingInterrupt,
|
||||
s if *s == sym::C_dash_cmse_dash_nonsecure_dash_call => FnAbi::CCmseNonsecureCall,
|
||||
s if *s == sym::C_dash_unwind => FnAbi::CUnwind,
|
||||
s if *s == sym::C => FnAbi::C,
|
||||
s if *s == sym::cdecl_dash_unwind => FnAbi::CDeclUnwind,
|
||||
s if *s == sym::cdecl => FnAbi::CDecl,
|
||||
s if *s == sym::efiapi => FnAbi::Efiapi,
|
||||
s if *s == sym::fastcall_dash_unwind => FnAbi::FastcallUnwind,
|
||||
s if *s == sym::fastcall => FnAbi::Fastcall,
|
||||
s if *s == sym::msp430_dash_interrupt => FnAbi::Msp430Interrupt,
|
||||
s if *s == sym::platform_dash_intrinsic => FnAbi::PlatformIntrinsic,
|
||||
s if *s == sym::ptx_dash_kernel => FnAbi::PtxKernel,
|
||||
s if *s == sym::riscv_dash_interrupt_dash_m => FnAbi::RiscvInterruptM,
|
||||
s if *s == sym::riscv_dash_interrupt_dash_s => FnAbi::RiscvInterruptS,
|
||||
s if *s == sym::rust_dash_call => FnAbi::RustCall,
|
||||
s if *s == sym::rust_dash_cold => FnAbi::RustCold,
|
||||
s if *s == sym::rust_dash_intrinsic => FnAbi::RustIntrinsic,
|
||||
s if *s == sym::Rust => FnAbi::Rust,
|
||||
s if *s == sym::stdcall_dash_unwind => FnAbi::StdcallUnwind,
|
||||
s if *s == sym::stdcall => FnAbi::Stdcall,
|
||||
s if *s == sym::system_dash_unwind => FnAbi::SystemUnwind,
|
||||
s if *s == sym::system => FnAbi::System,
|
||||
s if *s == sym::sysv64_dash_unwind => FnAbi::Sysv64Unwind,
|
||||
s if *s == sym::sysv64 => FnAbi::Sysv64,
|
||||
s if *s == sym::thiscall_dash_unwind => FnAbi::ThiscallUnwind,
|
||||
s if *s == sym::thiscall => FnAbi::Thiscall,
|
||||
s if *s == sym::unadjusted => FnAbi::Unadjusted,
|
||||
s if *s == sym::vectorcall_dash_unwind => FnAbi::VectorcallUnwind,
|
||||
s if *s == sym::vectorcall => FnAbi::Vectorcall,
|
||||
s if *s == sym::wasm => FnAbi::Wasm,
|
||||
s if *s == sym::win64_dash_unwind => FnAbi::Win64Unwind,
|
||||
s if *s == sym::win64 => FnAbi::Win64,
|
||||
s if *s == sym::x86_dash_interrupt => FnAbi::X86Interrupt,
|
||||
_ => FnAbi::Unknown,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,7 +298,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
TyKind::Function(FnPointer {
|
||||
num_binders: 0, // FIXME lower `for<'a> fn()` correctly
|
||||
sig: FnSig {
|
||||
abi: abi.as_deref().map_or(FnAbi::Rust, FnAbi::from_str),
|
||||
abi: abi.as_ref().map_or(FnAbi::Rust, FnAbi::from_symbol),
|
||||
safety: if is_unsafe { Safety::Unsafe } else { Safety::Safe },
|
||||
variadic,
|
||||
},
|
||||
|
@ -1858,7 +1858,7 @@ fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig {
|
|||
ret,
|
||||
data.is_varargs(),
|
||||
if data.has_unsafe_kw() { Safety::Unsafe } else { Safety::Safe },
|
||||
data.abi.as_deref().map_or(FnAbi::Rust, FnAbi::from_str),
|
||||
data.abi.as_ref().map_or(FnAbi::Rust, FnAbi::from_symbol),
|
||||
);
|
||||
make_binders(db, &generics, sig)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use hir_def::{
|
|||
ModuleId, TraitId,
|
||||
};
|
||||
use hir_expand::name::Name;
|
||||
use intern::sym;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
use span::Edition;
|
||||
|
@ -200,7 +201,7 @@ impl TraitImpls {
|
|||
// FIXME: Reservation impls should be considered during coherence checks. If we are
|
||||
// (ever) to implement coherence checks, this filtering should be done by the trait
|
||||
// solver.
|
||||
if db.attrs(impl_id.into()).by_key("rustc_reservation_impl").exists() {
|
||||
if db.attrs(impl_id.into()).by_key(&sym::rustc_reservation_impl).exists() {
|
||||
continue;
|
||||
}
|
||||
let target_trait = match db.impl_trait(impl_id) {
|
||||
|
|
|
@ -15,7 +15,7 @@ use hir_def::{
|
|||
StaticId, VariantId,
|
||||
};
|
||||
use hir_expand::{mod_path::path, name::Name, HirFileIdExt, InFile};
|
||||
use intern::{sym, Interned};
|
||||
use intern::sym;
|
||||
use la_arena::ArenaMap;
|
||||
use rustc_abi::TargetDataLayout;
|
||||
use rustc_apfloat::{
|
||||
|
|
|
@ -15,9 +15,9 @@ use crate::{
|
|||
error_lifetime,
|
||||
mir::eval::{
|
||||
pad16, Address, AdtId, Arc, BuiltinType, Evaluator, FunctionId, HasModule, HirDisplay,
|
||||
Interned, InternedClosure, Interner, Interval, IntervalAndTy, IntervalOrOwned,
|
||||
ItemContainerId, LangItem, Layout, Locals, Lookup, MirEvalError, MirSpan, Mutability,
|
||||
Result, Substitution, Ty, TyBuilder, TyExt,
|
||||
InternedClosure, Interner, Interval, IntervalAndTy, IntervalOrOwned, ItemContainerId,
|
||||
LangItem, Layout, Locals, Lookup, MirEvalError, MirSpan, Mutability, Result, Substitution,
|
||||
Ty, TyBuilder, TyExt,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -54,12 +54,12 @@ impl Evaluator<'_> {
|
|||
|
||||
let function_data = self.db.function_data(def);
|
||||
let is_intrinsic = match &function_data.abi {
|
||||
Some(abi) => *abi == Interned::new_str("rust-intrinsic"),
|
||||
Some(abi) => *abi == sym::rust_dash_intrinsic,
|
||||
None => match def.lookup(self.db.upcast()).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let id = block.lookup(self.db.upcast()).id;
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_deref()
|
||||
== Some("rust-intrinsic")
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_ref()
|
||||
== Some(&sym::rust_dash_intrinsic)
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
|
@ -76,12 +76,12 @@ impl Evaluator<'_> {
|
|||
return Ok(true);
|
||||
}
|
||||
let is_platform_intrinsic = match &function_data.abi {
|
||||
Some(abi) => *abi == Interned::new_str("platform-intrinsic"),
|
||||
Some(abi) => *abi == sym::platform_dash_intrinsic,
|
||||
None => match def.lookup(self.db.upcast()).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let id = block.lookup(self.db.upcast()).id;
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_deref()
|
||||
== Some("platform-intrinsic")
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_ref()
|
||||
== Some(&sym::platform_dash_intrinsic)
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
|
@ -100,7 +100,7 @@ impl Evaluator<'_> {
|
|||
let is_extern_c = match def.lookup(self.db.upcast()).container {
|
||||
hir_def::ItemContainerId::ExternBlockId(block) => {
|
||||
let id = block.lookup(self.db.upcast()).id;
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_deref() == Some("C")
|
||||
id.item_tree(self.db.upcast())[id.value].abi.as_ref() == Some(&sym::C)
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
@ -314,7 +314,7 @@ impl Evaluator<'_> {
|
|||
use LangItem::*;
|
||||
let attrs = self.db.attrs(def.into());
|
||||
|
||||
if attrs.by_key("rustc_const_panic_str").exists() {
|
||||
if attrs.by_key(&sym::rustc_const_panic_str).exists() {
|
||||
// `#[rustc_const_panic_str]` is treated like `lang = "begin_panic"` by rustc CTFE.
|
||||
return Some(LangItem::BeginPanic);
|
||||
}
|
||||
|
|
|
@ -1406,6 +1406,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
|
|||
const USIZE_SIZE: usize = mem::size_of::<usize>();
|
||||
let bytes: Box<[_]> = match l {
|
||||
hir_def::hir::Literal::String(b) => {
|
||||
let b = b.as_str();
|
||||
let mut data = [0; { 2 * USIZE_SIZE }];
|
||||
data[..USIZE_SIZE].copy_from_slice(&0usize.to_le_bytes());
|
||||
data[USIZE_SIZE..].copy_from_slice(&b.len().to_le_bytes());
|
||||
|
|
|
@ -18,6 +18,7 @@ use hir_def::{
|
|||
TypeOrConstParamId,
|
||||
};
|
||||
use hir_expand::name::Name;
|
||||
use intern::sym;
|
||||
use rustc_abi::TargetDataLayout;
|
||||
use rustc_hash::FxHashSet;
|
||||
use smallvec::{smallvec, SmallVec};
|
||||
|
@ -254,7 +255,7 @@ pub fn is_fn_unsafe_to_call(db: &dyn HirDatabase, func: FunctionId) -> bool {
|
|||
let data = db.function_data(func);
|
||||
if data.has_unsafe_kw() {
|
||||
// Functions that are `#[rustc_deprecated_safe_2024]` are safe to call before 2024.
|
||||
if db.attrs(func.into()).by_key("rustc_deprecated_safe_2024").exists() {
|
||||
if db.attrs(func.into()).by_key(&sym::rustc_deprecated_safe_2024).exists() {
|
||||
// FIXME: Properly check the caller span and mark it as unsafe after 2024.
|
||||
return false;
|
||||
}
|
||||
|
@ -268,11 +269,11 @@ pub fn is_fn_unsafe_to_call(db: &dyn HirDatabase, func: FunctionId) -> bool {
|
|||
let id = block.lookup(db.upcast()).id;
|
||||
|
||||
let is_intrinsic =
|
||||
id.item_tree(db.upcast())[id.value].abi.as_deref() == Some("rust-intrinsic");
|
||||
id.item_tree(db.upcast())[id.value].abi.as_ref() == Some(&sym::rust_dash_intrinsic);
|
||||
|
||||
if is_intrinsic {
|
||||
// Intrinsics are unsafe unless they have the rustc_safe_intrinsic attribute
|
||||
!data.attrs.by_key("rustc_safe_intrinsic").exists()
|
||||
!data.attrs.by_key(&sym::rustc_safe_intrinsic).exists()
|
||||
} else {
|
||||
// Extern items are always unsafe
|
||||
true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue