Port two panic attrs to the attr parser.
Ports #![panic_runtime] and #![needs_panic_runtime]
This commit is contained in:
parent
8c4e48e9b5
commit
1143cb2bb2
7 changed files with 38 additions and 14 deletions
|
|
@ -184,3 +184,21 @@ impl<S: Stage> SingleAttributeParser<S> for WindowsSubsystemParser {
|
|||
Some(AttributeKind::WindowsSubsystem(kind, cx.attr_span))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct PanicRuntimeParser;
|
||||
|
||||
impl<S: Stage> NoArgsAttributeParser<S> for PanicRuntimeParser {
|
||||
const PATH: &[Symbol] = &[sym::panic_runtime];
|
||||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
|
||||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::PanicRuntime;
|
||||
}
|
||||
|
||||
pub(crate) struct NeedsPanicRuntimeParser;
|
||||
|
||||
impl<S: Stage> NoArgsAttributeParser<S> for NeedsPanicRuntimeParser {
|
||||
const PATH: &[Symbol] = &[sym::needs_panic_runtime];
|
||||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
|
||||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NeedsPanicRuntime;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ use crate::attributes::codegen_attrs::{
|
|||
};
|
||||
use crate::attributes::confusables::ConfusablesParser;
|
||||
use crate::attributes::crate_level::{
|
||||
CrateNameParser, MoveSizeLimitParser, NoCoreParser, NoMainParser, NoStdParser,
|
||||
PatternComplexityLimitParser, RecursionLimitParser, RustcCoherenceIsCoreParser,
|
||||
TypeLengthLimitParser, WindowsSubsystemParser,
|
||||
CrateNameParser, MoveSizeLimitParser, NeedsPanicRuntimeParser, NoCoreParser, NoMainParser,
|
||||
NoStdParser, PanicRuntimeParser, PatternComplexityLimitParser, RecursionLimitParser,
|
||||
RustcCoherenceIsCoreParser, TypeLengthLimitParser, WindowsSubsystemParser,
|
||||
};
|
||||
use crate::attributes::debugger::DebuggerViualizerParser;
|
||||
use crate::attributes::deprecation::DeprecationParser;
|
||||
|
|
@ -268,6 +268,7 @@ attribute_parsers!(
|
|||
Single<WithoutArgs<MarkerParser>>,
|
||||
Single<WithoutArgs<MayDangleParser>>,
|
||||
Single<WithoutArgs<NeedsAllocatorParser>>,
|
||||
Single<WithoutArgs<NeedsPanicRuntimeParser>>,
|
||||
Single<WithoutArgs<NoCoreParser>>,
|
||||
Single<WithoutArgs<NoImplicitPreludeParser>>,
|
||||
Single<WithoutArgs<NoLinkParser>>,
|
||||
|
|
@ -275,6 +276,7 @@ attribute_parsers!(
|
|||
Single<WithoutArgs<NoMangleParser>>,
|
||||
Single<WithoutArgs<NoStdParser>>,
|
||||
Single<WithoutArgs<NonExhaustiveParser>>,
|
||||
Single<WithoutArgs<PanicRuntimeParser>>,
|
||||
Single<WithoutArgs<ParenSugarParser>>,
|
||||
Single<WithoutArgs<PassByValueParser>>,
|
||||
Single<WithoutArgs<PinV2Parser>>,
|
||||
|
|
|
|||
|
|
@ -846,6 +846,9 @@ pub enum AttributeKind {
|
|||
/// Represents `#[needs_allocator]`
|
||||
NeedsAllocator,
|
||||
|
||||
/// Represents `#[needs_panic_runtime]`
|
||||
NeedsPanicRuntime,
|
||||
|
||||
/// Represents `#[no_core]`
|
||||
NoCore(Span),
|
||||
|
||||
|
|
@ -876,6 +879,9 @@ pub enum AttributeKind {
|
|||
/// Represents `#[optimize(size|speed)]`
|
||||
Optimize(OptimizeAttr, Span),
|
||||
|
||||
/// Represents `#[panic_runtime]`
|
||||
PanicRuntime,
|
||||
|
||||
/// Represents `#[rustc_paren_sugar]`.
|
||||
ParenSugar(Span),
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ impl AttributeKind {
|
|||
MustUse { .. } => Yes,
|
||||
Naked(..) => No,
|
||||
NeedsAllocator => No,
|
||||
NeedsPanicRuntime => No,
|
||||
NoCore(..) => No,
|
||||
NoImplicitPrelude(..) => No,
|
||||
NoLink => No,
|
||||
|
|
@ -87,6 +88,7 @@ impl AttributeKind {
|
|||
ObjcClass { .. } => No,
|
||||
ObjcSelector { .. } => No,
|
||||
Optimize(..) => No,
|
||||
PanicRuntime => No,
|
||||
ParenSugar(..) => No,
|
||||
PassByValue(..) => Yes,
|
||||
PatchableFunctionEntry { .. } => Yes,
|
||||
|
|
|
|||
|
|
@ -743,9 +743,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
debugger_visualizers,
|
||||
compiler_builtins: find_attr!(attrs, AttributeKind::CompilerBuiltins),
|
||||
needs_allocator: find_attr!(attrs, AttributeKind::NeedsAllocator),
|
||||
needs_panic_runtime: ast::attr::contains_name(attrs, sym::needs_panic_runtime),
|
||||
needs_panic_runtime: find_attr!(attrs, AttributeKind::NeedsPanicRuntime),
|
||||
no_builtins: ast::attr::contains_name(attrs, sym::no_builtins),
|
||||
panic_runtime: ast::attr::contains_name(attrs, sym::panic_runtime),
|
||||
panic_runtime: find_attr!(attrs, AttributeKind::PanicRuntime),
|
||||
profiler_runtime: ast::attr::contains_name(attrs, sym::profiler_runtime),
|
||||
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ use rustc_hir::definitions::{DefPathData, Definitions, DisambiguatorState};
|
|||
use rustc_hir::intravisit::VisitorExt;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::limit::Limit;
|
||||
use rustc_hir::{self as hir, Attribute, HirId, Node, TraitCandidate, find_attr};
|
||||
use rustc_hir::{self as hir, HirId, Node, TraitCandidate, find_attr};
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_query_system::cache::WithDepNode;
|
||||
use rustc_query_system::dep_graph::DepNodeIndex;
|
||||
|
|
@ -49,7 +49,7 @@ use rustc_session::config::CrateType;
|
|||
use rustc_session::cstore::{CrateStoreDyn, Untracked};
|
||||
use rustc_session::lint::Lint;
|
||||
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
|
||||
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
|
||||
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw};
|
||||
use rustc_type_ir::TyKind::*;
|
||||
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
|
||||
pub use rustc_type_ir::lift::Lift;
|
||||
|
|
@ -3560,7 +3560,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
providers.is_panic_runtime =
|
||||
|tcx, LocalCrate| contains_name(tcx.hir_krate_attrs(), sym::panic_runtime);
|
||||
|tcx, LocalCrate| find_attr!(tcx.hir_krate_attrs(), AttributeKind::PanicRuntime);
|
||||
providers.is_compiler_builtins =
|
||||
|tcx, LocalCrate| find_attr!(tcx.hir_krate_attrs(), AttributeKind::CompilerBuiltins);
|
||||
providers.has_panic_handler = |tcx, LocalCrate| {
|
||||
|
|
@ -3569,7 +3569,3 @@ pub fn provide(providers: &mut Providers) {
|
|||
};
|
||||
providers.source_span = |tcx, def_id| tcx.untracked.source_span.get(def_id).unwrap_or(DUMMY_SP);
|
||||
}
|
||||
|
||||
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {
|
||||
attrs.iter().any(|x| x.has_name(name))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -300,6 +300,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| AttributeKind::NoStd { .. }
|
||||
| AttributeKind::NoMain
|
||||
| AttributeKind::CompilerBuiltins
|
||||
| AttributeKind::PanicRuntime
|
||||
| AttributeKind::NeedsPanicRuntime
|
||||
| AttributeKind::ObjcClass { .. }
|
||||
| AttributeKind::ObjcSelector { .. }
|
||||
| AttributeKind::RustcCoherenceIsCore(..)
|
||||
|
|
@ -401,8 +403,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| sym::no_builtins
|
||||
| sym::crate_type
|
||||
| sym::profiler_runtime
|
||||
| sym::needs_panic_runtime
|
||||
| sym::panic_runtime
|
||||
| sym::rustc_preserve_ub_checks,
|
||||
..
|
||||
] => {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue