Skip to content

Commit 44a8e8d

Browse files
committed
entirely remove rustc_args_required_const attribute
1 parent 22e1778 commit 44a8e8d

File tree

14 files changed

+4
-254
lines changed

14 files changed

+4
-254
lines changed

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc_middle::ty::cast::{CastTy, IntTy};
1414
use rustc_middle::ty::layout::HasTyCtxt;
1515
use rustc_middle::ty::{self, adjustment::PointerCast, Instance, Ty, TyCtxt};
1616
use rustc_span::source_map::{Span, DUMMY_SP};
17-
use rustc_span::symbol::sym;
1817
use rustc_target::abi::{Abi, Int, LayoutOf, Variants};
1918

2019
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> {
187186
mir::CastKind::Pointer(PointerCast::ReifyFnPointer) => {
188187
match *operand.layout.ty.kind() {
189188
ty::FnDef(def_id, substs) => {
190-
if bx.cx().tcx().has_attr(def_id, sym::rustc_args_required_const) {
191-
bug!("reifying a fn ptr that requires const arguments");
192-
}
193189
let instance = ty::Instance::resolve_for_fn_ptr(
194190
bx.tcx(),
195191
ty::ParamEnv::reveal_all(),

compiler/rustc_feature/src/builtin_attrs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
469469
// ==========================================================================
470470

471471
rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
472-
rustc_attr!(rustc_args_required_const, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
473472
rustc_attr!(rustc_legacy_const_generics, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
474473

475474
// ==========================================================================

compiler/rustc_mir/src/interpret/cast.rs

-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use rustc_middle::mir::CastKind;
77
use rustc_middle::ty::adjustment::PointerCast;
88
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
99
use rustc_middle::ty::{self, FloatTy, Ty, TypeAndMut};
10-
use rustc_span::symbol::sym;
1110
use rustc_target::abi::{Integer, LayoutOf, Variants};
1211

1312
use super::{
@@ -49,13 +48,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
4948
// All reifications must be monomorphic, bail out otherwise.
5049
ensure_monomorphic_enough(*self.tcx, src.layout.ty)?;
5150

52-
if self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
53-
span_bug!(
54-
self.cur_span(),
55-
"reifying a fn ptr that requires const arguments"
56-
);
57-
}
58-
5951
let instance = ty::Instance::resolve_for_fn_ptr(
6052
*self.tcx,
6153
self.param_env,

compiler/rustc_mir/src/interpret/intern.rs

-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ where
305305
let base_intern_mode = match intern_kind {
306306
InternKind::Static(mutbl) => InternMode::Static(mutbl),
307307
// `Constant` includes array lengths.
308-
// `Promoted` includes non-`Copy` array initializers and `rustc_args_required_const` arguments.
309308
InternKind::Constant | InternKind::Promoted => InternMode::Const,
310309
};
311310

compiler/rustc_mir/src/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use crate::transform::MirPass;
3232

3333
/// A `MirPass` for promotion.
3434
///
35-
/// Promotion is the extraction of promotable temps into separate MIR bodies. This pass also emits
36-
/// errors when promotion of `#[rustc_args_required_const]` arguments fails.
35+
/// Promotion is the extraction of promotable temps into separate MIR bodies so they can have
36+
/// `'static` lifetime.
3737
///
3838
/// After this pass is run, `promoted_fragments` will hold the MIR body corresponding to each
3939
/// newly created `Constant`.

compiler/rustc_passes/src/check_attr.rs

+1-79
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ use rustc_errors::{pluralize, struct_span_err, Applicability};
1313
use rustc_hir as hir;
1414
use rustc_hir::def_id::LocalDefId;
1515
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
16-
use rustc_hir::{
17-
self, FnSig, ForeignItem, ForeignItemKind, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID,
18-
};
16+
use rustc_hir::{self, FnSig, ForeignItem, HirId, Item, ItemKind, TraitItem, CRATE_HIR_ID};
1917
use rustc_hir::{MethodKind, Target};
2018
use rustc_session::lint::builtin::{
2119
CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES,
@@ -81,9 +79,6 @@ impl CheckAttrVisitor<'tcx> {
8179
sym::doc => self.check_doc_attrs(attr, hir_id, target, &mut specified_inline),
8280
sym::no_link => self.check_no_link(hir_id, &attr, span, target),
8381
sym::export_name => self.check_export_name(hir_id, &attr, span, target),
84-
sym::rustc_args_required_const => {
85-
self.check_rustc_args_required_const(&attr, span, target, item)
86-
}
8782
sym::rustc_layout_scalar_valid_range_start
8883
| sym::rustc_layout_scalar_valid_range_end => {
8984
self.check_rustc_layout_scalar_valid_range(&attr, span, target)
@@ -948,79 +943,6 @@ impl CheckAttrVisitor<'tcx> {
948943
}
949944
}
950945

951-
/// Checks if `#[rustc_args_required_const]` is applied to a function and has a valid argument.
952-
fn check_rustc_args_required_const(
953-
&self,
954-
attr: &Attribute,
955-
span: &Span,
956-
target: Target,
957-
item: Option<ItemLike<'_>>,
958-
) -> bool {
959-
let is_function = matches!(target, Target::Fn | Target::Method(..) | Target::ForeignFn);
960-
if !is_function {
961-
self.tcx
962-
.sess
963-
.struct_span_err(attr.span, "attribute should be applied to a function")
964-
.span_label(*span, "not a function")
965-
.emit();
966-
return false;
967-
}
968-
969-
let list = match attr.meta_item_list() {
970-
// The attribute form is validated on AST.
971-
None => return false,
972-
Some(it) => it,
973-
};
974-
975-
let mut invalid_args = vec![];
976-
for meta in list {
977-
if let Some(LitKind::Int(val, _)) = meta.literal().map(|lit| &lit.kind) {
978-
if let Some(ItemLike::Item(Item {
979-
kind: ItemKind::Fn(FnSig { decl, .. }, ..),
980-
..
981-
}))
982-
| Some(ItemLike::ForeignItem(ForeignItem {
983-
kind: ForeignItemKind::Fn(decl, ..),
984-
..
985-
})) = item
986-
{
987-
let arg_count = decl.inputs.len() as u128;
988-
if *val >= arg_count {
989-
let span = meta.span();
990-
self.tcx
991-
.sess
992-
.struct_span_err(span, "index exceeds number of arguments")
993-
.span_label(
994-
span,
995-
format!(
996-
"there {} only {} argument{}",
997-
if arg_count != 1 { "are" } else { "is" },
998-
arg_count,
999-
pluralize!(arg_count)
1000-
),
1001-
)
1002-
.emit();
1003-
return false;
1004-
}
1005-
} else {
1006-
bug!("should be a function item");
1007-
}
1008-
} else {
1009-
invalid_args.push(meta.span());
1010-
}
1011-
}
1012-
1013-
if !invalid_args.is_empty() {
1014-
self.tcx
1015-
.sess
1016-
.struct_span_err(invalid_args, "arguments should be non-negative integers")
1017-
.emit();
1018-
false
1019-
} else {
1020-
true
1021-
}
1022-
}
1023-
1024946
fn check_rustc_layout_scalar_valid_range(
1025947
&self,
1026948
attr: &Attribute,

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,6 @@ symbols! {
992992
rustc_allocator,
993993
rustc_allocator_nounwind,
994994
rustc_allow_const_fn_unstable,
995-
rustc_args_required_const,
996995
rustc_attrs,
997996
rustc_builtin_macro,
998997
rustc_capture_analysis,

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15371537
}
15381538
}
15391539

1540-
self.check_rustc_args_require_const(def_id, hir_id, span);
1541-
15421540
debug!("instantiate_value_path: type of {:?} is {:?}", hir_id, ty_substituted);
15431541
self.write_substs(hir_id, substs);
15441542

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
1818
use rustc_middle::ty::fold::TypeFoldable;
1919
use rustc_middle::ty::{self, Ty};
2020
use rustc_session::Session;
21-
use rustc_span::symbol::{sym, Ident};
21+
use rustc_span::symbol::Ident;
2222
use rustc_span::{self, MultiSpan, Span};
2323
use rustc_trait_selection::traits::{self, ObligationCauseCode, StatementAsExpression};
2424

@@ -720,34 +720,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
720720
ty
721721
}
722722

723-
pub(in super::super) fn check_rustc_args_require_const(
724-
&self,
725-
def_id: DefId,
726-
hir_id: hir::HirId,
727-
span: Span,
728-
) {
729-
// We're only interested in functions tagged with
730-
// #[rustc_args_required_const], so ignore anything that's not.
731-
if !self.tcx.has_attr(def_id, sym::rustc_args_required_const) {
732-
return;
733-
}
734-
735-
// If our calling expression is indeed the function itself, we're good!
736-
// If not, generate an error that this can only be called directly.
737-
if let Node::Expr(expr) = self.tcx.hir().get(self.tcx.hir().get_parent_node(hir_id)) {
738-
if let ExprKind::Call(ref callee, ..) = expr.kind {
739-
if callee.hir_id == hir_id {
740-
return;
741-
}
742-
}
743-
}
744-
745-
self.tcx.sess.span_err(
746-
span,
747-
"this function can only be invoked directly, not through a function pointer",
748-
);
749-
}
750-
751723
/// A common error is to add an extra semicolon:
752724
///
753725
/// ```

src/test/ui/consts/const-eval/double_promotion.rs

-17
This file was deleted.

src/test/ui/invalid/invalid-rustc_args_required_const-arguments.rs

-32
This file was deleted.

src/test/ui/invalid/invalid-rustc_args_required_const-arguments.stderr

-60
This file was deleted.

src/test/ui/rustc-args-required-const2.rs

-10
This file was deleted.

src/test/ui/rustc-args-required-const2.stderr

-8
This file was deleted.

0 commit comments

Comments
 (0)