about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2021-05-09 14:21:33 +0200
committerRalf Jung <post@ralfj.de>2021-05-12 16:15:27 +0200
commit44a8e8d7455cd8f8ec3b3f2d5d4ef80693608f63 (patch)
tree85f45da51bcc24e5895d8e19f11969ebc688f0ef
parent22e1778ec0e7fc77ae465bd0f69ead91447be742 (diff)
downloadrust-44a8e8d7455cd8f8ec3b3f2d5d4ef80693608f63.tar.gz
rust-44a8e8d7455cd8f8ec3b3f2d5d4ef80693608f63.zip
entirely remove rustc_args_required_const attribute
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/rvalue.rs4
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs1
-rw-r--r--compiler/rustc_mir/src/interpret/cast.rs8
-rw-r--r--compiler/rustc_mir/src/interpret/intern.rs1
-rw-r--r--compiler/rustc_mir/src/transform/promote_consts.rs4
-rw-r--r--compiler/rustc_passes/src/check_attr.rs80
-rw-r--r--compiler/rustc_span/src/symbol.rs1
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs2
-rw-r--r--compiler/rustc_typeck/src/check/fn_ctxt/checks.rs30
-rw-r--r--src/test/ui/consts/const-eval/double_promotion.rs17
-rw-r--r--src/test/ui/invalid/invalid-rustc_args_required_const-arguments.rs32
-rw-r--r--src/test/ui/invalid/invalid-rustc_args_required_const-arguments.stderr60
-rw-r--r--src/test/ui/rustc-args-required-const2.rs10
-rw-r--r--src/test/ui/rustc-args-required-const2.stderr8
14 files changed, 4 insertions, 254 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
index 9917c23f121..530de3de9e8 100644
--- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs
@@ -14,7 +14,6 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
 use rustc_middle::ty::layout::HasTyCtxt;
 use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
 use rustc_span::source_map::{Span, DUMMY_SP};
-use rustc_span::symbol::sym;
 use rustc_target::abi::{Abi, Int, LayoutOf, Variants};
 
 impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -187,9 +186,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                     mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => {
                         match *operand.layout.ty.kind() {
                             ty::FnDef(def_id, substs) => {
-                                if bx.cx().tcx().has_attr(def_id, sym::rustc_args_required_const) {
-                                    bug!("reifying a fn ptr that requires const arguments");
-                                }
                                 let instance = ty::Instance::resolve_for_fn_ptr(
                                     bx.tcx(),
                                     ty::ParamEnv::reveal_all(),
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index a8719be84c2..24b53bcf82a 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -469,7 +469,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
     // ==========================================================================
 
     rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
-    rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
     rustc_attr!(rustc_legacy_const_generics, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
 
     // ==========================================================================
diff --git a/compiler/rustc_mir/src/interpret/cast.rs b/compiler/rustc_mir/src/interpret/cast.rs
index 2d9e6df0ab8..848b44d13aa 100644
--- a/compiler/rustc_mir/src/interpret/cast.rs
+++ b/compiler/rustc_mir/src/interpret/cast.rs
@@ -7,7 +7,6 @@ use rustc_middle::mir::CastKind;
 use rustc_middle::ty::adjustment::PointerCast;
 use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
 use rustc_middle::ty::{self, FloatTy, Ty, TypeAndMut};
-use rustc_span::symbol::sym;
 use rustc_target::abi::{Integer, LayoutOf, Variants};
 
 use super::{
@@ -49,13 +48,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
                         // All reifications must be monomorphic, bail out otherwise.
                         ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
 
-                        if self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
-                            span_bug!(
-                                self.cur_span(),
-                                "reifying a fn ptr that requires const arguments"
-                            );
-                        }
-
                         let instance = ty::Instance::resolve_for_fn_ptr(
                             *self.tcx,
                             self.param_env,
diff --git a/compiler/rustc_mir/src/interpret/intern.rs b/compiler/rustc_mir/src/interpret/intern.rs
index 95464da145c..23c0fe97c5f 100644
--- a/compiler/rustc_mir/src/interpret/intern.rs
+++ b/compiler/rustc_mir/src/interpret/intern.rs
@@ -305,7 +305,6 @@ where
     let base_intern_mode = match intern_kind {
         InternKind::Static(mutbl) => InternMode::Static(mutbl),
         // `Constant` includes array lengths.
-        // `Promoted` includes non-`Copy` array initializers and `rustc_args_required_const` arguments.
         InternKind::Constant | InternKind::Promoted => InternMode::Const,
     };
 
diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs
index f786f327ba2..f6b1323e107 100644
--- a/compiler/rustc_mir/src/transform/promote_consts.rs
+++ b/compiler/rustc_mir/src/transform/promote_consts.rs
@@ -32,8 +32,8 @@ use crate::transform::MirPass;
 
 /// A `MirPass` for promotion.
 ///
-/// Promotion is the extraction of promotable temps into separate MIR bodies. This pass also emits
-/// errors when promotion of `#[rustc_args_required_const]` arguments fails.
+/// Promotion is the extraction of promotable temps into separate MIR bodies so they can have
+/// `'static` lifetime.
 ///
 /// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each
 /// newly created `Constant`.
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index cb06cbfcc7b..bf574bbfbb5 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -13,9 +13,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability};
 use rustc_hir as hir;
 use rustc_hir::def_id::LocalDefId;
 use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
-use rustc_hir::{
-    self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID,
-};
+use rustc_hir::{self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID};
 use rustc_hir::{MethodKind, Target};
 use rustc_session::lint::builtin::{
     CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES,
@@ -81,9 +79,6 @@ impl CheckAttrVisitor<'tcx> {
                 sym::doc => self.check_doc_attrs(attr, hir_id, target, &mut specified_inline),
                 sym::no_link => self.check_no_link(hir_id, &attr, span, target),
                 sym::export_name => self.check_export_name(hir_id, &attr, span, target),
-                sym::rustc_args_required_const => {
-                    self.check_rustc_args_required_const(&attr, span, target, item)
-                }
                 sym::rustc_layout_scalar_valid_range_start
                 | sym::rustc_layout_scalar_valid_range_end => {
                     self.check_rustc_layout_scalar_valid_range(&attr, span, target)
@@ -948,79 +943,6 @@ impl CheckAttrVisitor<'tcx> {
         }
     }
 
-    /// Checks if `#[rustc_args_required_const]` is applied to a function and has a valid argument.
-    fn check_rustc_args_required_const(
-        &self,
-        attr: &Attribute,
-        span: &Span,
-        target: Target,
-        item: Option<ItemLike<'_>>,
-    ) -> bool {
-        let is_function = matches!(target, Target::Fn | Target::Method(..) | Target::ForeignFn);
-        if !is_function {
-            self.tcx
-                .sess
-                .struct_span_err(attr.span, "attribute should be applied to a function")
-                .span_label(*span, "not a function")
-                .emit();
-            return false;
-        }
-
-        let list = match attr.meta_item_list() {
-            // The attribute form is validated on AST.
-            None => return false,
-            Some(it) => it,
-        };
-
-        let mut invalid_args = vec![];
-        for meta in list {
-            if let Some(LitKind::Int(val, _)) = meta.literal().map(|lit| &lit.kind) {
-                if let Some(ItemLike::Item(Item {
-                    kind: ItemKind::Fn(FnSig { decl, .. }, ..),
-                    ..
-                }))
-                | Some(ItemLike::ForeignItem(ForeignItem {
-                    kind: ForeignItemKind::Fn(decl, ..),
-                    ..
-                })) = item
-                {
-                    let arg_count = decl.inputs.len() as u128;
-                    if *val >= arg_count {
-                        let span = meta.span();
-                        self.tcx
-                            .sess
-                            .struct_span_err(span, "index exceeds number of arguments")
-                            .span_label(
-                                span,
-                                format!(
-                                    "there {} only {} argument{}",
-                                    if arg_count != 1 { "are" } else { "is" },
-                                    arg_count,
-                                    pluralize!(arg_count)
-                                ),
-                            )
-                            .emit();
-                        return false;
-                    }
-                } else {
-                    bug!("should be a function item");
-                }
-            } else {
-                invalid_args.push(meta.span());
-            }
-        }
-
-        if !invalid_args.is_empty() {
-            self.tcx
-                .sess
-                .struct_span_err(invalid_args, "arguments should be non-negative integers")
-                .emit();
-            false
-        } else {
-            true
-        }
-    }
-
     fn check_rustc_layout_scalar_valid_range(
         &self,
         attr: &Attribute,
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 4c80b84e3d2..a65c66f8ee7 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -992,7 +992,6 @@ symbols! {
         rustc_allocator,
         rustc_allocator_nounwind,
         rustc_allow_const_fn_unstable,
-        rustc_args_required_const,
         rustc_attrs,
         rustc_builtin_macro,
         rustc_capture_analysis,
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
index 4d6caf07236..4de8216884a 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
@@ -1537,8 +1537,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
             }
         }
 
-        self.check_rustc_args_require_const(def_id, hir_id, span);
-
         debug!("instantiate_value_path: type of {:?} is {:?}", hir_id, ty_substituted);
         self.write_substs(hir_id, substs);
 
diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
index 3417bc01972..49aea19c8d0 100644
--- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
+++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
@@ -18,7 +18,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
 use rustc_middle::ty::fold::TypeFoldable;
 use rustc_middle::ty::{self, Ty};
 use rustc_session::Session;
-use rustc_span::symbol::{sym, Ident};
+use rustc_span::symbol::Ident;
 use rustc_span::{self, MultiSpan, Span};
 use rustc_trait_selection::traits::{self, ObligationCauseCode, StatementAsExpression};
 
@@ -720,34 +720,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
         ty
     }
 
-    pub(in super::super) fn check_rustc_args_require_const(
-        &self,
-        def_id: DefId,
-        hir_id: hir::HirId,
-        span: Span,
-    ) {
-        // We're only interested in functions tagged with
-        // #[rustc_args_required_const], so ignore anything that's not.
-        if !self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
-            return;
-        }
-
-        // If our calling expression is indeed the function itself, we're good!
-        // If not, generate an error that this can only be called directly.
-        if let Node::Expr(expr) = self.tcx.hir().get(self.tcx.hir().get_parent_node(hir_id)) {
-            if let ExprKind::Call(ref callee, ..) = expr.kind {
-                if callee.hir_id == hir_id {
-                    return;
-                }
-            }
-        }
-
-        self.tcx.sess.span_err(
-            span,
-            "this function can only be invoked directly, not through a function pointer",
-        );
-    }
-
     /// A common error is to add an extra semicolon:
     ///
     /// ```
diff --git a/src/test/ui/consts/const-eval/double_promotion.rs b/src/test/ui/consts/const-eval/double_promotion.rs
deleted file mode 100644
index 9ee2777a647..00000000000
--- a/src/test/ui/consts/const-eval/double_promotion.rs
+++ /dev/null
@@ -1,17 +0,0 @@
-// check-pass
-
-#![feature(rustc_attrs)]
-
-#[rustc_args_required_const(0)]
-pub const fn a(value: u8) -> u8 {
-    value
-}
-
-#[rustc_args_required_const(0)]
-pub fn b(_: u8) {
-    unimplemented!()
-}
-
-fn main() {
-    let _ = b(a(0));
-}
diff --git a/src/test/ui/invalid/invalid-rustc_args_required_const-arguments.rs b/src/test/ui/invalid/invalid-rustc_args_required_const-arguments.rs
deleted file mode 100644
index 99508baeb00..00000000000
--- a/src/test/ui/invalid/invalid-rustc_args_required_const-arguments.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_args_required_const(0)] //~ ERROR index exceeds number of arguments
-fn foo1() {}
-
-#[rustc_args_required_const(1)] //~ ERROR index exceeds number of arguments
-fn foo2(_: u8) {}
-
-#[rustc_args_required_const(a)] //~ ERROR arguments should be non-negative integers
-fn foo4() {}
-
-#[rustc_args_required_const(1, a, 2, b)] //~ ERROR arguments should be non-negative integers
-fn foo5(_: u8, _: u8, _: u8) {}
-
-#[rustc_args_required_const(0)] //~ ERROR attribute should be applied to a function
-struct S;
-
-#[rustc_args_required_const(0usize)] //~ ERROR suffixed literals are not allowed in attributes
-fn foo6(_: u8) {}
-
-extern {
-    #[rustc_args_required_const(1)] //~ ERROR index exceeds number of arguments
-    fn foo7(_: u8);
-}
-
-#[rustc_args_required_const] //~ ERROR malformed `rustc_args_required_const` attribute
-fn bar1() {}
-
-#[rustc_args_required_const = 1] //~ ERROR malformed `rustc_args_required_const` attribute
-fn bar2() {}
-
-fn main() {}
diff --git a/src/test/ui/invalid/invalid-rustc_args_required_const-arguments.stderr b/src/test/ui/invalid/invalid-rustc_args_required_const-arguments.stderr
deleted file mode 100644
index 932344f0a33..00000000000
--- a/src/test/ui/invalid/invalid-rustc_args_required_const-arguments.stderr
+++ /dev/null
@@ -1,60 +0,0 @@
-error: suffixed literals are not allowed in attributes
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:18:29
-   |
-LL | #[rustc_args_required_const(0usize)]
-   |                             ^^^^^^
-   |
-   = help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
-
-error: malformed `rustc_args_required_const` attribute input
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:26:1
-   |
-LL | #[rustc_args_required_const]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_args_required_const(N)]`
-
-error: malformed `rustc_args_required_const` attribute input
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:29:1
-   |
-LL | #[rustc_args_required_const = 1]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_args_required_const(N)]`
-
-error: index exceeds number of arguments
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:3:29
-   |
-LL | #[rustc_args_required_const(0)]
-   |                             ^ there are only 0 arguments
-
-error: index exceeds number of arguments
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:6:29
-   |
-LL | #[rustc_args_required_const(1)]
-   |                             ^ there is only 1 argument
-
-error: arguments should be non-negative integers
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:9:29
-   |
-LL | #[rustc_args_required_const(a)]
-   |                             ^
-
-error: arguments should be non-negative integers
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:12:32
-   |
-LL | #[rustc_args_required_const(1, a, 2, b)]
-   |                                ^     ^
-
-error: attribute should be applied to a function
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:15:1
-   |
-LL | #[rustc_args_required_const(0)]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-LL | struct S;
-   | --------- not a function
-
-error: index exceeds number of arguments
-  --> $DIR/invalid-rustc_args_required_const-arguments.rs:22:33
-   |
-LL |     #[rustc_args_required_const(1)]
-   |                                 ^ there is only 1 argument
-
-error: aborting due to 9 previous errors
-
diff --git a/src/test/ui/rustc-args-required-const2.rs b/src/test/ui/rustc-args-required-const2.rs
deleted file mode 100644
index 06457bc5ca6..00000000000
--- a/src/test/ui/rustc-args-required-const2.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-#![feature(rustc_attrs)]
-
-#[rustc_args_required_const(0)]
-fn foo(_a: i32) {
-}
-
-fn main() {
-    let a = foo; //~ ERROR: this function can only be invoked directly
-    a(2);
-}
diff --git a/src/test/ui/rustc-args-required-const2.stderr b/src/test/ui/rustc-args-required-const2.stderr
deleted file mode 100644
index a8906ad3bc5..00000000000
--- a/src/test/ui/rustc-args-required-const2.stderr
+++ /dev/null
@@ -1,8 +0,0 @@
-error: this function can only be invoked directly, not through a function pointer
-  --> $DIR/rustc-args-required-const2.rs:8:13
-   |
-LL |     let a = foo;
-   |             ^^^
-
-error: aborting due to previous error
-