Port #![no_builtins] to the attribute parser.
This commit is contained in:
parent
54385b52b4
commit
f6d76385e2
11 changed files with 114 additions and 89 deletions
|
|
@ -211,3 +211,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for ProfilerRuntimeParser {
|
|||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::ProfilerRuntime;
|
||||
}
|
||||
|
||||
pub(crate) struct NoBuiltinsParser;
|
||||
|
||||
impl<S: Stage> NoArgsAttributeParser<S> for NoBuiltinsParser {
|
||||
const PATH: &[Symbol] = &[sym::no_builtins];
|
||||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
|
||||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoBuiltins;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,9 +28,10 @@ use crate::attributes::codegen_attrs::{
|
|||
};
|
||||
use crate::attributes::confusables::ConfusablesParser;
|
||||
use crate::attributes::crate_level::{
|
||||
CrateNameParser, MoveSizeLimitParser, NeedsPanicRuntimeParser, NoCoreParser, NoMainParser, NoStdParser,
|
||||
PanicRuntimeParser, PatternComplexityLimitParser, ProfilerRuntimeParser, RecursionLimitParser,
|
||||
RustcCoherenceIsCoreParser, TypeLengthLimitParser, WindowsSubsystemParser,
|
||||
CrateNameParser, MoveSizeLimitParser, NeedsPanicRuntimeParser, NoBuiltinsParser, NoCoreParser,
|
||||
NoMainParser, NoStdParser, PanicRuntimeParser, PatternComplexityLimitParser,
|
||||
ProfilerRuntimeParser, RecursionLimitParser, RustcCoherenceIsCoreParser, TypeLengthLimitParser,
|
||||
WindowsSubsystemParser,
|
||||
};
|
||||
use crate::attributes::debugger::DebuggerViualizerParser;
|
||||
use crate::attributes::deprecation::DeprecationParser;
|
||||
|
|
@ -269,6 +270,7 @@ attribute_parsers!(
|
|||
Single<WithoutArgs<MayDangleParser>>,
|
||||
Single<WithoutArgs<NeedsAllocatorParser>>,
|
||||
Single<WithoutArgs<NeedsPanicRuntimeParser>>,
|
||||
Single<WithoutArgs<NoBuiltinsParser>>,
|
||||
Single<WithoutArgs<NoCoreParser>>,
|
||||
Single<WithoutArgs<NoImplicitPreludeParser>>,
|
||||
Single<WithoutArgs<NoLinkParser>>,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use std::sync::mpsc::{Receiver, Sender, channel};
|
|||
use std::{fs, io, mem, str, thread};
|
||||
|
||||
use rustc_abi::Size;
|
||||
use rustc_ast::attr;
|
||||
use rustc_data_structures::assert_matches;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::jobserver::{self, Acquired};
|
||||
|
|
@ -19,6 +18,8 @@ use rustc_errors::{
|
|||
Level, MultiSpan, Style, Suggestions, catch_fatal_errors,
|
||||
};
|
||||
use rustc_fs_util::link_or_copy;
|
||||
use rustc_hir::attrs::AttributeKind;
|
||||
use rustc_hir::find_attr;
|
||||
use rustc_incremental::{
|
||||
copy_cgu_workproduct_to_incr_comp_cache_dir, in_incr_comp_dir, in_incr_comp_dir_sess,
|
||||
};
|
||||
|
|
@ -31,7 +32,7 @@ use rustc_session::config::{
|
|||
self, CrateType, Lto, OutFileName, OutputFilenames, OutputType, Passes, SwitchWithOptPath,
|
||||
};
|
||||
use rustc_span::source_map::SourceMap;
|
||||
use rustc_span::{FileName, InnerSpan, Span, SpanData, sym};
|
||||
use rustc_span::{FileName, InnerSpan, Span, SpanData};
|
||||
use rustc_target::spec::{MergeFunctions, SanitizerSet};
|
||||
use tracing::debug;
|
||||
|
||||
|
|
@ -453,7 +454,7 @@ pub(crate) fn start_async_codegen<B: ExtraBackendMethods>(
|
|||
let (coordinator_send, coordinator_receive) = channel();
|
||||
|
||||
let crate_attrs = tcx.hir_attrs(rustc_hir::CRATE_HIR_ID);
|
||||
let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
|
||||
let no_builtins = find_attr!(crate_attrs, AttributeKind::NoBuiltins);
|
||||
|
||||
let crate_info = CrateInfo::new(tcx, target_cpu);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::str::FromStr;
|
|||
|
||||
use rustc_abi::{Align, ExternAbi};
|
||||
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
|
||||
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
|
||||
use rustc_ast::{LitKind, MetaItem, MetaItemInner};
|
||||
use rustc_hir::attrs::{
|
||||
AttributeKind, EiiImplResolution, InlineAttr, Linkage, RtsanSetting, UsedBy,
|
||||
};
|
||||
|
|
@ -353,7 +353,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
|
|||
// When `no_builtins` is applied at the crate level, we should add the
|
||||
// `no-builtins` attribute to each function to ensure it takes effect in LTO.
|
||||
let crate_attrs = tcx.hir_attrs(rustc_hir::CRATE_HIR_ID);
|
||||
let no_builtins = attr::contains_name(crate_attrs, sym::no_builtins);
|
||||
let no_builtins = find_attr!(crate_attrs, AttributeKind::NoBuiltins);
|
||||
if no_builtins {
|
||||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_BUILTINS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -849,6 +849,9 @@ pub enum AttributeKind {
|
|||
/// Represents `#[needs_panic_runtime]`
|
||||
NeedsPanicRuntime,
|
||||
|
||||
/// Represents `#[no_builtins]`
|
||||
NoBuiltins,
|
||||
|
||||
/// Represents `#[no_core]`
|
||||
NoCore(Span),
|
||||
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ impl AttributeKind {
|
|||
Naked(..) => No,
|
||||
NeedsAllocator => No,
|
||||
NeedsPanicRuntime => No,
|
||||
NoBuiltins => Yes,
|
||||
NoCore(..) => No,
|
||||
NoImplicitPrelude(..) => No,
|
||||
NoLink => No,
|
||||
|
|
|
|||
|
|
@ -744,7 +744,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
compiler_builtins: find_attr!(attrs, AttributeKind::CompilerBuiltins),
|
||||
needs_allocator: find_attr!(attrs, AttributeKind::NeedsAllocator),
|
||||
needs_panic_runtime: find_attr!(attrs, AttributeKind::NeedsPanicRuntime),
|
||||
no_builtins: ast::attr::contains_name(attrs, sym::no_builtins),
|
||||
no_builtins: find_attr!(attrs, AttributeKind::NoBuiltins),
|
||||
panic_runtime: find_attr!(attrs, AttributeKind::PanicRuntime),
|
||||
profiler_runtime: find_attr!(attrs, AttributeKind::ProfilerRuntime),
|
||||
symbol_mangling_version: tcx.sess.opts.get_symbol_mangling_version(),
|
||||
|
|
|
|||
|
|
@ -303,6 +303,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| AttributeKind::PanicRuntime
|
||||
| AttributeKind::NeedsPanicRuntime
|
||||
| AttributeKind::ProfilerRuntime
|
||||
| AttributeKind::NoBuiltins
|
||||
| AttributeKind::ObjcClass { .. }
|
||||
| AttributeKind::ObjcSelector { .. }
|
||||
| AttributeKind::RustcCoherenceIsCore(..)
|
||||
|
|
@ -401,7 +402,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| sym::rustc_no_implicit_bounds
|
||||
| sym::test_runner
|
||||
| sym::reexport_test_harness_main
|
||||
| sym::no_builtins
|
||||
| sym::crate_type
|
||||
| sym::rustc_preserve_ub_checks,
|
||||
..
|
||||
|
|
|
|||
|
|
@ -908,26 +908,26 @@ mod no_main_1 {
|
|||
|
||||
#[no_builtins]
|
||||
//~^ WARN crate-level attribute should be an inner attribute
|
||||
//~| HELP add a `!`
|
||||
mod no_builtins {
|
||||
//~^ NOTE: this attribute does not have an `!`, which means it is applied to this module
|
||||
mod inner { #![no_builtins] }
|
||||
//~^ WARN crate-level attribute should be in the root module
|
||||
//~^ WARN the `#![no_builtins]` attribute can only be used at the crate root
|
||||
|
||||
#[no_builtins] fn f() { }
|
||||
//~^ WARN crate-level attribute should be an inner attribute
|
||||
//~| HELP add a `!`
|
||||
//~| NOTE this attribute does not have an `!`, which means it is applied to this function
|
||||
|
||||
#[no_builtins] struct S;
|
||||
//~^ WARN crate-level attribute should be an inner attribute
|
||||
//~| HELP add a `!`
|
||||
//~| NOTE this attribute does not have an `!`, which means it is applied to this struct
|
||||
|
||||
#[no_builtins] type T = S;
|
||||
//~^ WARN crate-level attribute should be an inner attribute
|
||||
//~| HELP add a `!`
|
||||
//~| NOTE this attribute does not have an `!`, which means it is applied to this type alias
|
||||
|
||||
#[no_builtins] impl S { }
|
||||
//~^ WARN crate-level attribute should be an inner attribute
|
||||
//~| HELP add a `!`
|
||||
//~| NOTE this attribute does not have an `!`, which means it is applied to this implementation
|
||||
}
|
||||
|
||||
#[recursion_limit="0200"]
|
||||
|
|
|
|||
|
|
@ -240,17 +240,6 @@ help: add a `!`
|
|||
LL | #![feature(x0600)]
|
||||
| +
|
||||
|
||||
warning: crate-level attribute should be an inner attribute
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:909:1
|
||||
|
|
||||
LL | #[no_builtins]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a `!`
|
||||
|
|
||||
LL | #![no_builtins]
|
||||
| +
|
||||
|
||||
warning: attribute should be applied to an `extern` block with non-Rust ABI
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:71:1
|
||||
|
|
||||
|
|
@ -465,56 +454,6 @@ help: add a `!`
|
|||
LL | #![feature(x0600)] impl S { }
|
||||
| +
|
||||
|
||||
warning: crate-level attribute should be in the root module
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:913:17
|
||||
|
|
||||
LL | mod inner { #![no_builtins] }
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:916:5
|
||||
|
|
||||
LL | #[no_builtins] fn f() { }
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a `!`
|
||||
|
|
||||
LL | #![no_builtins] fn f() { }
|
||||
| +
|
||||
|
||||
warning: crate-level attribute should be an inner attribute
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:920:5
|
||||
|
|
||||
LL | #[no_builtins] struct S;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a `!`
|
||||
|
|
||||
LL | #![no_builtins] struct S;
|
||||
| +
|
||||
|
||||
warning: crate-level attribute should be an inner attribute
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:924:5
|
||||
|
|
||||
LL | #[no_builtins] type T = S;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a `!`
|
||||
|
|
||||
LL | #![no_builtins] type T = S;
|
||||
| +
|
||||
|
||||
warning: crate-level attribute should be an inner attribute
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:928:5
|
||||
|
|
||||
LL | #[no_builtins] impl S { }
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add a `!`
|
||||
|
|
||||
LL | #![no_builtins] impl S { }
|
||||
| +
|
||||
|
||||
warning: `#[macro_use]` attribute cannot be used on functions
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:190:5
|
||||
|
|
||||
|
|
@ -1416,6 +1355,76 @@ note: this attribute does not have an `!`, which means it is applied to this imp
|
|||
LL | #[no_main] impl S { }
|
||||
| ^^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:909:1
|
||||
|
|
||||
LL | #[no_builtins]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: this attribute does not have an `!`, which means it is applied to this module
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:911:1
|
||||
|
|
||||
LL | / mod no_builtins {
|
||||
LL | |
|
||||
LL | | mod inner { #![no_builtins] }
|
||||
... |
|
||||
LL | | }
|
||||
| |_^
|
||||
|
||||
warning: the `#![no_builtins]` attribute can only be used at the crate root
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:913:17
|
||||
|
|
||||
LL | mod inner { #![no_builtins] }
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:916:5
|
||||
|
|
||||
LL | #[no_builtins] fn f() { }
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: this attribute does not have an `!`, which means it is applied to this function
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:916:20
|
||||
|
|
||||
LL | #[no_builtins] fn f() { }
|
||||
| ^^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:920:5
|
||||
|
|
||||
LL | #[no_builtins] struct S;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: this attribute does not have an `!`, which means it is applied to this struct
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:920:20
|
||||
|
|
||||
LL | #[no_builtins] struct S;
|
||||
| ^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:924:5
|
||||
|
|
||||
LL | #[no_builtins] type T = S;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: this attribute does not have an `!`, which means it is applied to this type alias
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:924:20
|
||||
|
|
||||
LL | #[no_builtins] type T = S;
|
||||
| ^^^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![no_builtins]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:928:5
|
||||
|
|
||||
LL | #[no_builtins] impl S { }
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
note: this attribute does not have an `!`, which means it is applied to this implementation block
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:928:20
|
||||
|
|
||||
LL | #[no_builtins] impl S { }
|
||||
| ^^^^^^^^^^
|
||||
|
||||
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![recursion_limit]`
|
||||
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:933:1
|
||||
|
|
||||
|
|
|
|||
|
|
@ -16,18 +16,6 @@ note: the lint level is defined here
|
|||
LL | #![deny(unused_attributes)]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused attribute
|
||||
--> $DIR/unused-attr-duplicate.rs:34:1
|
||||
|
|
||||
LL | #![no_builtins]
|
||||
| ^^^^^^^^^^^^^^^ help: remove this attribute
|
||||
|
|
||||
note: attribute also specified here
|
||||
--> $DIR/unused-attr-duplicate.rs:33:1
|
||||
|
|
||||
LL | #![no_builtins]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: unused attribute
|
||||
--> $DIR/unused-attr-duplicate.rs:37:1
|
||||
|
|
||||
|
|
@ -316,5 +304,17 @@ LL | #![windows_subsystem = "console"]
|
|||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
|
||||
error: unused attribute
|
||||
--> $DIR/unused-attr-duplicate.rs:34:1
|
||||
|
|
||||
LL | #![no_builtins]
|
||||
| ^^^^^^^^^^^^^^^ help: remove this attribute
|
||||
|
|
||||
note: attribute also specified here
|
||||
--> $DIR/unused-attr-duplicate.rs:33:1
|
||||
|
|
||||
LL | #![no_builtins]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 25 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue