Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimize use of #![feature(custom_attribute)] #61660

Merged
merged 6 commits into from
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/doc/rustc/src/lints/listing/warn-by-default.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,19 +728,17 @@ This lint detects attributes that were not used by the compiler. Some
example code that triggers this lint:

```rust
#![feature(custom_attribute)]

#![mutable_doc]
#![macro_export]
```

This will produce:

```text
warning: unused attribute
--> src/main.rs:4:1
--> src/main.rs:1:1
|
4 | #![mutable_doc]
| ^^^^^^^^^^^^^^^
1 | #![macro_export]
| ^^^^^^^^^^^^^^^^
|
```

Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ extern "Rust" {
// them from the `#[global_allocator]` attribute if there is one, or uses the
// default implementations in libstd (`__rdl_alloc` etc in `src/libstd/alloc.rs`)
// otherwise.
#[allocator]
#[cfg_attr(bootstrap, allocator)]
#[cfg_attr(not(bootstrap), rustc_allocator)]
#[rustc_allocator_nounwind]
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
#[rustc_allocator_nounwind]
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
#![feature(coerce_unsized)]
#![feature(dispatch_from_dyn)]
#![feature(core_intrinsics)]
#![feature(custom_attribute)]
#![cfg_attr(bootstrap, feature(custom_attribute))]
#![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)]
#![feature(fmt_internals)]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#![feature(concat_idents)]
#![feature(const_fn)]
#![feature(const_fn_union)]
#![feature(custom_attribute)]
#![feature(doc_cfg)]
#![feature(doc_spotlight)]
#![feature(extern_types)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ bitflags! {
/// `#[cold]`: a hint to LLVM that this function, when called, is never on
/// the hot path.
const COLD = 1 << 0;
/// `#[allocator]`: a hint to LLVM that the pointer returned from this
/// `#[rustc_allocator]`: a hint to LLVM that the pointer returned from this
/// function is never null.
const ALLOCATOR = 1 << 1;
/// `#[unwind]`: an indicator that this function may unwind despite what
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#![feature(box_syntax)]
#![feature(const_cstr_unchecked)]
#![feature(crate_visibility_modifier)]
#![feature(custom_attribute)]
#![feature(extern_types)]
#![feature(in_band_lifetimes)]
#![allow(unused_attributes)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(custom_attribute)]
#![feature(libc)]
#![feature(rustc_diagnostic_macros)]
#![feature(stmt_expr_attributes)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_utils/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(custom_attribute)]
#![feature(never_type)]
#![feature(nll)]
#![allow(unused_attributes)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]

#![feature(custom_attribute)]
#![allow(unused_attributes)]
#![cfg_attr(unix, feature(libc))]
#![feature(nll)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(custom_attribute)]
#![feature(nll)]
#![deny(rust_2018_idioms)]
#![deny(internal)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
for attr in attrs.iter() {
if attr.check_name(sym::cold) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::COLD;
} else if attr.check_name(sym::allocator) {
} else if attr.check_name(sym::rustc_allocator) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR;
} else if attr.check_name(sym::unwind) {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::UNWIND;
Expand Down
20 changes: 14 additions & 6 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,16 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
"internal implementation detail",
cfg_fn!(rustc_attrs))),

(sym::rustc_allocator, Whitelisted, template!(Word), Gated(Stability::Unstable,
sym::rustc_attrs,
"internal implementation detail",
cfg_fn!(rustc_attrs))),

(sym::rustc_dummy, Normal, template!(Word /* doesn't matter*/), Gated(Stability::Unstable,
sym::rustc_attrs,
"used by the test suite",
cfg_fn!(rustc_attrs))),

// FIXME: #14408 whitelist docs since rustdoc looks at them
(
sym::doc,
Expand Down Expand Up @@ -1957,12 +1967,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

match attr_info {
Some(&(name, _, template, _)) => self.check_builtin_attribute(
attr,
name,
template
),
None => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
Some(&(name, _, template, _)) if name != sym::rustc_dummy =>
self.check_builtin_attribute(attr, name, template),
_ => if let Some(TokenTree::Token(token)) = attr.tokens.trees().next() {
if token == token::Eq {
// All key-value attributes are restricted to meta-item syntax.
attr.parse_meta(self.context.parse_sess).map_err(|mut err| err.emit()).ok();
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#![feature(const_fn)]
#![feature(crate_visibility_modifier)]
#![feature(custom_attribute)]
#![feature(nll)]
#![feature(non_exhaustive)]
#![feature(optin_builtin_traits)]
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ symbols! {
rust_2018_preview,
rust_begin_unwind,
rustc,
rustc_allocator,
rustc_allocator_nounwind,
rustc_allow_const_fn_ptr,
rustc_args_required_const,
Expand All @@ -526,6 +527,7 @@ symbols! {
rustc_diagnostic_macros,
rustc_dirty,
rustc_doc_only_macro,
rustc_dummy,
rustc_dump_env_program_clauses,
rustc_dump_program_clauses,
rustc_dump_user_substs,
Expand Down
3 changes: 0 additions & 3 deletions src/libterm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
#![deny(rust_2018_idioms)]

#![cfg_attr(windows, feature(libc))]
// Handle rustfmt skips
#![feature(custom_attribute)]
#![allow(unused_attributes)]

use std::io::prelude::*;
use std::io::{self, Stdout, Stderr};
Expand Down
4 changes: 2 additions & 2 deletions src/test/codegen/function-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ignore-tidy-linelength

#![crate_type = "lib"]
#![feature(custom_attribute)]
#![feature(rustc_attrs)]

pub struct S {
_field: [i32; 8],
Expand Down Expand Up @@ -146,7 +146,7 @@ pub fn enum_id_2(x: Option<u8>) -> Option<u8> {

// CHECK: noalias i8* @allocator()
#[no_mangle]
#[allocator]
#[rustc_allocator]
pub fn allocator() -> *const i8 {
std::ptr::null()
}
11 changes: 6 additions & 5 deletions src/test/pretty/attr-fn-inner.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// pp-exact
// Testing that both the inner item and next outer item are
// preserved, and that the first outer item parsed in main is not
// accidentally carried over to each inner function

#![feature(custom_attribute)]
// pp-exact

#![feature(rustc_attrs)]

fn main() {
#![inner_attr]
#[outer_attr]
#![rustc_dummy]
#[rustc_dummy]
fn f() { }

#[outer_attr]
#[rustc_dummy]
fn g() { }
}
11 changes: 6 additions & 5 deletions src/test/pretty/attr-literals.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// pp-exact
// Tests literals in attributes.

#![feature(custom_attribute)]
// pp-exact

#![feature(rustc_attrs)]

fn main() {
#![hello("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
#[align = 8]
#![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
#[rustc_dummy = 8]
fn f() { }

#[vector(1, 2, 3)]
#[rustc_dummy(1, 2, 3)]
fn g() { }
}
Loading