Skip to content

Commit 848a6ad

Browse files
committed
Remove redundant attributes
1 parent 61013ef commit 848a6ad

24 files changed

Lines changed: 87 additions & 197 deletions

File tree

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ use rustc_attr_parsing::AttributeParser;
2525
use rustc_errors::{Applicability, LintDiagnostic};
2626
use rustc_feature::GateIssue;
2727
use rustc_hir as hir;
28-
use rustc_hir::attrs::{AttributeKind, DocAttribute, InlineAttr};
28+
use rustc_hir::attrs::{AttributeKind, DocAttribute};
2929
use rustc_hir::def::{DefKind, Res};
3030
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
3131
use rustc_hir::intravisit::FnKind as HirFnKind;
32-
use rustc_hir::{AttrPath, Body, FnDecl, ImplItemImplKind, PatKind, PredicateOrigin, find_attr};
32+
use rustc_hir::{Body, FnDecl, ImplItemImplKind, PatKind, PredicateOrigin, find_attr};
3333
use rustc_middle::bug;
3434
use rustc_middle::lint::LevelAndSource;
3535
use rustc_middle::ty::layout::LayoutOf;
@@ -3187,100 +3187,3 @@ impl EarlyLintPass for SpecialModuleName {
31873187
}
31883188
}
31893189
}
3190-
3191-
declare_lint! {
3192-
/// The `missing_panic_entrypoint` lint detects forgotten use of #[rustc_panic_entrypoint]
3193-
///
3194-
/// ### Example
3195-
///
3196-
/// ```rust,compile_fail
3197-
/// # #![cfg(not(bootstrap))]
3198-
/// #[deny(missing_panic_entrypoint)]
3199-
/// pub fn panic_wrapper() -> ! {
3200-
/// panic!("ouch!")
3201-
/// }
3202-
/// ```
3203-
///
3204-
/// {{produces}}
3205-
///
3206-
/// ### Explanation
3207-
///
3208-
/// This lint is intended to ensure that panic=immediate-abort can function as designed,
3209-
/// because it uses #[rustc_panic_entrypoint] to locate functions that should be outlined
3210-
/// for other panic modes, and be deleted entirely when immediate-abort is enabled.
3211-
pub MISSING_PANIC_ENTRYPOINT,
3212-
Allow,
3213-
"detects missing #[rustc_panic_entrypoint]",
3214-
}
3215-
3216-
#[derive(Default)]
3217-
pub struct MissingPanicEntrypoint;
3218-
3219-
impl_lint_pass!(MissingPanicEntrypoint => [MISSING_PANIC_ENTRYPOINT]);
3220-
3221-
fn has_panic_entrypoint(attrs: &[hir::Attribute]) -> bool {
3222-
attrs.iter().any(|attr| {
3223-
if let hir::Attribute::Unparsed(box hir::AttrItem {
3224-
path: AttrPath { segments, .. }, ..
3225-
}) = attr
3226-
{
3227-
if segments[0].name == sym::rustc_panic_entrypoint {
3228-
return true;
3229-
}
3230-
}
3231-
false
3232-
})
3233-
}
3234-
3235-
fn has_inline_encouragement(attrs: &[hir::Attribute]) -> bool {
3236-
attrs.iter().any(|attr| {
3237-
matches!(
3238-
attr,
3239-
hir::Attribute::Parsed(hir::attrs::AttributeKind::Inline(
3240-
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. },
3241-
_
3242-
))
3243-
)
3244-
})
3245-
}
3246-
3247-
fn has_rustc_intrinsic(attrs: &[hir::Attribute]) -> bool {
3248-
attrs.iter().any(|attr| {
3249-
if let hir::Attribute::Unparsed(box hir::AttrItem {
3250-
path: AttrPath { segments, .. }, ..
3251-
}) = attr
3252-
{
3253-
if segments[0].name == sym::rustc_intrinsic {
3254-
return true;
3255-
}
3256-
}
3257-
false
3258-
})
3259-
}
3260-
3261-
impl<'tcx> LateLintPass<'tcx> for MissingPanicEntrypoint {
3262-
fn check_fn(
3263-
&mut self,
3264-
cx: &LateContext<'tcx>,
3265-
_: HirFnKind<'tcx>,
3266-
fn_decl: &'tcx FnDecl<'tcx>,
3267-
_: &'tcx Body<'tcx>,
3268-
span: Span,
3269-
def_id: LocalDefId,
3270-
) {
3271-
if matches!(fn_decl.output, hir::FnRetTy::Return(hir::Ty { kind: hir::TyKind::Never, .. }))
3272-
{
3273-
let attrs = cx.tcx.hir_attrs(cx.tcx.local_def_id_to_hir_id(def_id));
3274-
if has_rustc_intrinsic(attrs) {
3275-
return;
3276-
}
3277-
if !has_inline_encouragement(attrs) && !has_panic_entrypoint(attrs) {
3278-
cx.emit_span_lint(
3279-
MISSING_PANIC_ENTRYPOINT,
3280-
span,
3281-
crate::lints::MissingPanicEntrypoint,
3282-
);
3283-
}
3284-
}
3285-
}
3286-
}

compiler/rustc_lint/src/internal.rs

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
22
//! Clippy.
33
4-
use rustc_hir::attrs::AttributeKind;
4+
use rustc_hir::attrs::{AttributeKind, InlineAttr};
55
use rustc_hir::def::Res;
66
use rustc_hir::def_id::DefId;
7-
use rustc_hir::{Expr, ExprKind, HirId, find_attr};
7+
use rustc_hir::intravisit::FnKind;
8+
use rustc_hir::{AttrPath, Body, Expr, ExprKind, FnDecl, HirId, find_attr};
89
use rustc_middle::ty::{self, GenericArgsRef, PredicatePolarity, Ty};
910
use rustc_session::{declare_lint_pass, declare_tool_lint};
11+
use rustc_span::def_id::LocalDefId;
1012
use rustc_span::hygiene::{ExpnKind, MacroKind};
1113
use rustc_span::{Span, sym};
1214
use tracing::debug;
@@ -784,3 +786,84 @@ impl EarlyLintPass for ImplicitSysrootCrateImport {
784786
}
785787
}
786788
}
789+
790+
declare_tool_lint! {
791+
/// The `missing_panic_entrypoint` lint detects forgotten use of #[rustc_panic_entrypoint].
792+
///
793+
/// This lint is intended to ensure that panic=immediate-abort can function as designed,
794+
/// because it uses #[rustc_panic_entrypoint] to locate functions that should be outlined
795+
/// for other panic modes, and be deleted entirely when immediate-abort is enabled.
796+
pub rustc::MISSING_PANIC_ENTRYPOINT,
797+
Allow,
798+
"detects missing #[rustc_panic_entrypoint]",
799+
report_in_external_macro: false
800+
}
801+
802+
declare_lint_pass!(MissingPanicEntrypoint => [MISSING_PANIC_ENTRYPOINT]);
803+
804+
fn has_panic_entrypoint(attrs: &[hir::Attribute]) -> bool {
805+
attrs.iter().any(|attr| {
806+
if let hir::Attribute::Unparsed(box hir::AttrItem {
807+
path: AttrPath { segments, .. }, ..
808+
}) = attr
809+
{
810+
if segments[0].name == sym::rustc_panic_entrypoint {
811+
return true;
812+
}
813+
}
814+
false
815+
})
816+
}
817+
818+
fn has_inline_encouragement(attrs: &[hir::Attribute]) -> bool {
819+
attrs.iter().any(|attr| {
820+
matches!(
821+
attr,
822+
hir::Attribute::Parsed(hir::attrs::AttributeKind::Inline(
823+
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Force { .. },
824+
_
825+
))
826+
)
827+
})
828+
}
829+
830+
fn has_rustc_intrinsic(attrs: &[hir::Attribute]) -> bool {
831+
attrs.iter().any(|attr| {
832+
if let hir::Attribute::Unparsed(box hir::AttrItem {
833+
path: AttrPath { segments, .. }, ..
834+
}) = attr
835+
{
836+
if segments[0].name == sym::rustc_intrinsic {
837+
return true;
838+
}
839+
}
840+
false
841+
})
842+
}
843+
844+
impl<'tcx> LateLintPass<'tcx> for MissingPanicEntrypoint {
845+
fn check_fn(
846+
&mut self,
847+
cx: &LateContext<'tcx>,
848+
_: FnKind<'tcx>,
849+
fn_decl: &'tcx FnDecl<'tcx>,
850+
_: &'tcx Body<'tcx>,
851+
span: Span,
852+
def_id: LocalDefId,
853+
) {
854+
if matches!(fn_decl.output, hir::FnRetTy::Return(hir::Ty { kind: hir::TyKind::Never, .. }))
855+
{
856+
let attrs = cx.tcx.hir_attrs(cx.tcx.local_def_id_to_hir_id(def_id));
857+
if has_rustc_intrinsic(attrs) {
858+
return;
859+
}
860+
if !has_inline_encouragement(attrs) && !has_panic_entrypoint(attrs) {
861+
cx.emit_span_lint(
862+
MISSING_PANIC_ENTRYPOINT,
863+
span,
864+
crate::lints::MissingPanicEntrypoint,
865+
);
866+
}
867+
}
868+
}
869+
}

library/alloc/src/alloc.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ unsafe extern "Rust" {
394394
#[stable(feature = "global_alloc", since = "1.28.0")]
395395
#[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")]
396396
#[cfg(not(no_global_oom_handling))]
397-
#[cold]
398-
#[optimize(size)]
399397
#[rustc_panic_entrypoint]
400398
pub const fn handle_alloc_error(layout: Layout) -> ! {
401399
#[inline]

library/alloc/src/raw_vec/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ mod tests;
2323
// ensure that the code generation related to these panics is minimal as there's
2424
// only one location which panics rather than a bunch throughout the module.
2525
#[cfg(not(no_global_oom_handling))]
26-
#[cold]
27-
#[inline(never)]
2826
#[rustc_panic_entrypoint]
2927
fn capacity_overflow() -> ! {
3028
panic!("capacity overflow");
@@ -839,8 +837,6 @@ impl<A: Allocator> RawVecInner<A> {
839837

840838
// Central function for reserve error handling.
841839
#[cfg(not(no_global_oom_handling))]
842-
#[cold]
843-
#[optimize(size)]
844840
#[rustc_panic_entrypoint]
845841
fn handle_error(e: TryReserveError) -> ! {
846842
match e.kind() {

library/alloc/src/vec/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,9 +2027,6 @@ impl<T, A: Allocator> Vec<T, A> {
20272027
#[inline]
20282028
#[stable(feature = "rust1", since = "1.0.0")]
20292029
pub fn swap_remove(&mut self, index: usize) -> T {
2030-
#[cold]
2031-
#[inline(never)]
2032-
#[optimize(size)]
20332030
#[track_caller]
20342031
#[rustc_panic_entrypoint]
20352032
fn assert_failed(index: usize, len: usize) -> ! {
@@ -2110,10 +2107,7 @@ impl<T, A: Allocator> Vec<T, A> {
21102107
#[track_caller]
21112108
#[must_use = "if you don't need a reference to the value, use `Vec::insert` instead"]
21122109
pub fn insert_mut(&mut self, index: usize, element: T) -> &mut T {
2113-
#[cold]
2114-
#[inline(never)]
21152110
#[track_caller]
2116-
#[optimize(size)]
21172111
#[rustc_panic_entrypoint]
21182112
fn assert_failed(index: usize, len: usize) -> ! {
21192113
panic!("insertion index (is {index}) should be <= len (is {len})");
@@ -2175,10 +2169,7 @@ impl<T, A: Allocator> Vec<T, A> {
21752169
#[track_caller]
21762170
#[rustc_confusables("delete", "take")]
21772171
pub fn remove(&mut self, index: usize) -> T {
2178-
#[cold]
2179-
#[inline(never)]
21802172
#[track_caller]
2181-
#[optimize(size)]
21822173
#[rustc_panic_entrypoint]
21832174
fn assert_failed(index: usize, len: usize) -> ! {
21842175
panic!("removal index (is {index}) should be < len (is {len})");
@@ -2971,10 +2962,7 @@ impl<T, A: Allocator> Vec<T, A> {
29712962
where
29722963
A: Clone,
29732964
{
2974-
#[cold]
2975-
#[inline(never)]
29762965
#[track_caller]
2977-
#[optimize(size)]
29782966
#[rustc_panic_entrypoint]
29792967
fn assert_failed(at: usize, len: usize) -> ! {
29802968
panic!("`at` split index (is {at}) should be <= len (is {len})");

library/core/src/cell.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,6 @@ impl Display for BorrowMutError {
885885

886886
// This ensures the panicking code is outlined from `borrow_mut` for `RefCell`.
887887
#[track_caller]
888-
#[cold]
889-
#[inline(never)]
890888
#[rustc_panic_entrypoint]
891889
const fn panic_already_borrowed(err: BorrowMutError) -> ! {
892890
const_panic!(
@@ -898,8 +896,6 @@ const fn panic_already_borrowed(err: BorrowMutError) -> ! {
898896

899897
// This ensures the panicking code is outlined from `borrow` for `RefCell`.
900898
#[track_caller]
901-
#[cold]
902-
#[inline(never)]
903899
#[rustc_panic_entrypoint]
904900
const fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
905901
const_panic!(

library/core/src/cell/lazy.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ impl<T: fmt::Debug, F> fmt::Debug for LazyCell<T, F> {
366366
}
367367
}
368368

369-
#[cold]
370-
#[inline(never)]
371369
#[rustc_panic_entrypoint]
372370
const fn panic_poisoned() -> ! {
373371
panic!("LazyCell instance has previously been poisoned")

library/core/src/num/int_log10.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ define_signed_ilog10! {
164164

165165
/// Instantiate this panic logic once, rather than for all the ilog methods
166166
/// on every single primitive type.
167-
#[cold]
168167
#[track_caller]
169168
#[rustc_panic_entrypoint]
170169
pub(super) const fn panic_for_nonpositive_argument() -> ! {

library/core/src/num/int_sqrt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ unsigned_fn!(u128, u64, u128_stages);
309309

310310
/// Instantiate this panic logic once, rather than for all the isqrt methods
311311
/// on every single primitive type.
312-
#[cold]
313312
#[track_caller]
314313
#[rustc_panic_entrypoint]
315314
pub(super) const fn panic_for_negative_argument() -> ! {

library/core/src/num/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,8 +1388,6 @@ pub const fn can_not_overflow<T>(radix: u32, is_signed_ty: bool, digits: &[u8])
13881388
radix <= 16 && digits.len() <= size_of::<T>() * 2 - is_signed_ty as usize
13891389
}
13901390

1391-
#[cold]
1392-
#[inline(never)]
13931391
#[track_caller]
13941392
#[rustc_panic_entrypoint]
13951393
const fn from_ascii_radix_panic(radix: u32) -> ! {

0 commit comments

Comments
 (0)