From c81cc8028ce4acad45a1a74c0231044695ea2380 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:25:00 +0200 Subject: [PATCH 1/4] Implement lint helper namespace --- compiler/rustc_attr_ir/src/data_structures.rs | 6 +- .../rustc_attr_ir/src/encode_cross_crate.rs | 4 +- .../src/attributes/lint_helpers.rs | 8 +- compiler/rustc_attr_parsing/src/context.rs | 2 +- .../rustc_attr_parsing/src/diagnostics.rs | 8 + compiler/rustc_attr_parsing/src/interface.rs | 19 +- compiler/rustc_feature/src/builtin_attrs.rs | 1 - compiler/rustc_lint/src/dangling.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_span/src/symbol.rs | 3 +- library/alloc/src/boxed.rs | 6 +- library/alloc/src/lib.rs | 7 +- library/alloc/src/vec/mod.rs | 6 +- library/core/src/cell.rs | 8 +- .../core/src/cell/covariant_unsafe_cell.rs | 2 +- library/core/src/ffi/c_str.rs | 2 +- library/core/src/lib.rs | 5 + library/core/src/mem/maybe_uninit.rs | 4 +- library/core/src/slice/mod.rs | 4 +- library/core/src/str/mod.rs | 4 +- tests/ui/README.md | 4 + tests/ui/attributes/malformed-attrs.rs | 3 +- tests/ui/attributes/malformed-attrs.stderr | 164 +++++++++--------- .../ui/lint_helper_namespace/feature_gates.rs | 8 + .../feature_gates.stderr | 12 ++ .../registered_invalid.rs | 6 + .../registered_invalid.stderr | 8 + .../registered_resolve_as_macro.rs | 18 ++ .../ui/lint_helper_namespace/unregistered.rs | 4 + .../lint_helper_namespace/unregistered.stderr | 9 + .../unregistered_resolve_as_macro.rs | 16 ++ 31 files changed, 241 insertions(+), 114 deletions(-) create mode 100644 tests/ui/lint_helper_namespace/feature_gates.rs create mode 100644 tests/ui/lint_helper_namespace/feature_gates.stderr create mode 100644 tests/ui/lint_helper_namespace/registered_invalid.rs create mode 100644 tests/ui/lint_helper_namespace/registered_invalid.stderr create mode 100644 tests/ui/lint_helper_namespace/registered_resolve_as_macro.rs create mode 100644 tests/ui/lint_helper_namespace/unregistered.rs create mode 100644 tests/ui/lint_helper_namespace/unregistered.stderr create mode 100644 tests/ui/lint_helper_namespace/unregistered_resolve_as_macro.rs diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 55c0bedb9c39c..cb721509316f0 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -932,6 +932,9 @@ pub enum AttributeKind { /// Represents `#[linkage]`. Linkage(Linkage, Span), + /// Represents `#[lint::as_ptr]` (used by the `dangling_pointers_from_temporaries` lint). + LintAsPtr, + /// Represents `#[loop_match]`. LoopMatch(Span), @@ -1142,9 +1145,6 @@ pub enum AttributeKind { /// Represents `#[rustc_allow_lifetime_dependent_specialization]`. RustcAllowLifetimeDependentSpecialization, - /// Represents `#[rustc_as_ptr]` (used by the `dangling_pointers_from_temporaries` lint). - RustcAsPtr, - /// Represents `#[rustc_autodiff]`. RustcAutodiff(Option>), diff --git a/compiler/rustc_attr_ir/src/encode_cross_crate.rs b/compiler/rustc_attr_ir/src/encode_cross_crate.rs index b6733e8c1db54..4c039709c8376 100644 --- a/compiler/rustc_attr_ir/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_ir/src/encode_cross_crate.rs @@ -58,6 +58,7 @@ impl AttributeKind { LinkOrdinal { .. } => No, LinkSection { .. } => Yes, // Needed for rustdoc Linkage(..) => No, + LintAsPtr => Yes, LoopMatch(..) => No, MacroEscape => No, MacroExport { .. } => Yes, @@ -108,7 +109,6 @@ impl AttributeKind { RustcAllowConstFnUnstable(..) => No, RustcAllowIncoherentImpl(..) => No, RustcAllowLifetimeDependentSpecialization => No, - RustcAsPtr => Yes, RustcAutodiff(..) => Yes, RustcBodyStability { .. } => No, RustcBuiltinMacro { .. } => Yes, @@ -272,6 +272,7 @@ impl AttributeKind { | crate::Linkage::WeakAny | crate::Linkage::WeakODR => true, }, + LintAsPtr => false, LoopMatch(..) => false, MacroEscape => false, MacroExport { .. } => false, @@ -322,7 +323,6 @@ impl AttributeKind { RustcAllowConstFnUnstable(..) => false, RustcAllowIncoherentImpl(..) => false, RustcAllowLifetimeDependentSpecialization => false, - RustcAsPtr => false, RustcAutodiff(..) => false, RustcBodyStability { .. } => false, RustcBuiltinMacro { .. } => false, diff --git a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs index 10e42ced30705..6c1c91eadfb53 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs @@ -4,9 +4,9 @@ use rustc_feature::AttributeStability; use super::prelude::*; use crate::diagnostics::RustcPubTransparent; -pub(crate) struct RustcAsPtrParser; -impl NoArgsAttributeParser for RustcAsPtrParser { - const PATH: &[Symbol] = &[sym::rustc_as_ptr]; +pub(crate) struct LintAsPtrParser; +impl NoArgsAttributeParser for LintAsPtrParser { + const PATH: &[Symbol] = &[sym::lint, sym::as_ptr]; const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ Allow(Target::Fn), Allow(Target::Method(MethodKind::Inherent)), @@ -15,7 +15,7 @@ impl NoArgsAttributeParser for RustcAsPtrParser { Allow(Target::Method(MethodKind::TraitImpl)), ]); const STABILITY: AttributeStability = unstable!(rustc_attrs); - const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcAsPtr; + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::LintAsPtr; } pub(crate) struct RustcPubTransparentParser; diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 72839643b4dc3..15467029be970 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -271,6 +271,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, @@ -296,7 +297,6 @@ attribute_parsers!( Single>, Single>, Single>, - Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index df426cb5e19f5..7171ea8b89f9b 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -2077,3 +2077,11 @@ pub(crate) enum MacroExport { #[note("declarative macros follow the same exporting rules as regular items")] OnDeclMacro, } + +#[derive(Diagnostic)] +#[diag("the `lint::{$unknown}` attribute is not recognized")] +pub(crate) struct UnknownLintHelper { + #[primary_span] + pub span: Span, + pub unknown: Symbol, +} diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 95412c34be371..73d67363c9a12 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -23,7 +23,7 @@ use crate::context::{ use crate::diagnostics::ParsedDescription; use crate::parser::{AllowExprMetavar, ArgParser, PathParser, RefPathParser}; use crate::synthetic::SyntheticAttrState; -use crate::{AttributeTemplate, ShouldEmit}; +use crate::{AttributeTemplate, ShouldEmit, diagnostics}; pub struct EmitAttribute( pub Box< @@ -452,6 +452,23 @@ impl<'sess> AttributeParser<'sess> { } } else if let [sym::diagnostic, _unknown, ..] = &*parts { self.unknown_diagnostic_attr(&n.item.path.segments[1], &mut emit_lint); + } else if let [sym::lint, unknown, ..] = &*parts { + // Avoid cascading errors. If the `lint` tool has not been registered, + // we could be here in the `#[lint::attribute_macro] not found` case, + // which recovers with a `NonMacroAttr` res. + if let Some(tools) = self.attr_tools + && tools.iter().any(|i| i.name == sym::lint) + { + self.emit_err(diagnostics::UnknownLintHelper { + span: n.item.span, + unknown: *unknown, + }); + } else { + self.dcx().span_delayed_bug( + n.item.span, + "encountered `lint` tool attribute but error not reported", + ); + } } else { let attr = AttrItem { path: attr_path.clone(), diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 0f96eb7f158ed..f1c0b0ff1c121 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -346,7 +346,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ // Internal attributes, Misc: // ========================================================================== sym::lang, - sym::rustc_as_ptr, sym::rustc_should_not_be_called_on_const_items, sym::rustc_pass_by_value, sym::rustc_never_returns_null_ptr, diff --git a/compiler/rustc_lint/src/dangling.rs b/compiler/rustc_lint/src/dangling.rs index dbe20dbef3c87..8cf1cb926b786 100644 --- a/compiler/rustc_lint/src/dangling.rs +++ b/compiler/rustc_lint/src/dangling.rs @@ -269,7 +269,7 @@ fn lint_expr(cx: &LateContext<'_>, expr: &Expr<'_>) { && let ty = cx.typeck_results().expr_ty(receiver) && owns_allocation(cx.tcx, ty) && let Some(fn_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) - && find_attr!(cx.tcx, fn_id, RustcAsPtr) + && find_attr!(cx.tcx, fn_id, LintAsPtr) { cx.tcx.emit_node_span_lint( DANGLING_POINTERS_FROM_TEMPORARIES, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index bea48e553d236..f986205427b08 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -267,6 +267,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::LinkName { .. } => (), AttributeKind::LinkOrdinal { .. } => (), AttributeKind::LinkSection { .. } => (), + AttributeKind::LintAsPtr => (), AttributeKind::LoopMatch(..) => (), AttributeKind::MacroEscape => (), AttributeKind::MacroExport { .. } => (), @@ -308,7 +309,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcAllocatorZeroedVariant { .. } => (), AttributeKind::RustcAllowIncoherentImpl(..) => (), AttributeKind::RustcAllowLifetimeDependentSpecialization => (), - AttributeKind::RustcAsPtr => (), AttributeKind::RustcAutodiff(..) => (), AttributeKind::RustcBodyStability { .. } => (), AttributeKind::RustcBuiltinMacro { .. } => (), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index a003f20e3512d..8814f8c573350 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -449,6 +449,7 @@ symbols! { arm_target_feature, array, as_dash_needed: "as-needed", + as_ptr, as_ref, asm, asm_cfg, @@ -1250,6 +1251,7 @@ symbols! { linker_messages, linkonce, linkonce_odr, + lint, lint_reasons, literal, little, big, @@ -1808,7 +1810,6 @@ symbols! { rustc_allow_lifetime_dependent_specialization, rustc_allowed_through_unstable_modules, rustc_always_gca, - rustc_as_ptr, rustc_attrs, rustc_autodiff, rustc_builtin_macro, diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index 6477858f14b83..c58d992be61fd 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1765,7 +1765,7 @@ impl Box { #[must_use] #[stable(feature = "box_as_ptr", since = "1.98.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline] pub fn as_mut_ptr(b: &mut Self) -> *mut T { // This is a primitive deref, not going through `DerefMut`, and therefore not materializing @@ -1814,7 +1814,7 @@ impl Box { #[must_use] #[stable(feature = "box_as_ptr", since = "1.98.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline] pub fn as_ptr(b: &Self) -> *const T { // This is a primitive deref, not going through `DerefMut`, and therefore not materializing @@ -1857,7 +1857,7 @@ impl Box { /// [`as_non_null`]: Self::as_non_null #[must_use] #[unstable(feature = "box_as_non_null", issue = "157345")] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline] pub fn as_non_null(b: &mut Self) -> NonNull { // SAFETY: `Box` is guaranteed to be non-null. diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 4fb34ed5b2668..f606fff5c726f 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -161,6 +161,7 @@ #![feature(ptr_metadata)] #![feature(random)] #![feature(raw_os_error_ty)] +#![feature(register_tool)] #![feature(rev_into_inner)] #![feature(seek_stream_len)] #![feature(set_ptr_value)] @@ -219,7 +220,11 @@ #![feature(with_negative_coherence)] #![rustc_preserve_ub_checks] // tidy-alphabetical-end -// + +// tidy-alphabetical-start +#![register_tool(lint)] +// tidy-alphabetical-end + // Rustdoc features: #![feature(doc_cfg)] #![feature(doc_notable_trait)] diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 8bcad62226a0b..5bf5bc76a6be9 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1954,7 +1954,7 @@ impl Vec { #[stable(feature = "vec_as_ptr", since = "1.37.0")] #[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline] pub const fn as_ptr(&self) -> *const T { // We shadow the slice method of the same name to avoid going through @@ -2038,7 +2038,7 @@ impl Vec { #[stable(feature = "vec_as_ptr", since = "1.37.0")] #[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline] pub const fn as_mut_ptr(&mut self) -> *mut T { // We shadow the slice method of the same name to avoid going through @@ -2104,7 +2104,7 @@ impl Vec { /// [`as_non_null`]: Vec::as_non_null #[unstable(feature = "vec_as_non_null", issue = "157843")] #[rustc_const_unstable(feature = "vec_as_non_null", issue = "157843")] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline] pub const fn as_non_null(&mut self) -> NonNull { self.buf.non_null() diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 3dcf033bbd757..1fddb9ea1aa54 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -598,7 +598,7 @@ impl Cell { #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] #[rustc_const_stable(feature = "const_cell_as_ptr", since = "1.32.0")] - #[rustc_as_ptr] + #[lint::as_ptr] #[rustc_never_returns_null_ptr] pub const fn as_ptr(&self) -> *mut T { self.value.get() @@ -1289,7 +1289,7 @@ impl RefCell { /// ``` #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] - #[rustc_as_ptr] + #[lint::as_ptr] #[rustc_never_returns_null_ptr] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] pub const fn as_ptr(&self) -> *mut T { @@ -2428,7 +2428,7 @@ impl UnsafeCell { #[inline(always)] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")] - #[rustc_as_ptr] + #[lint::as_ptr] #[rustc_never_returns_null_ptr] #[rustc_should_not_be_called_on_const_items] pub const fn get(&self) -> *mut T { @@ -2635,7 +2635,7 @@ impl SyncUnsafeCell { /// when casting to `&mut T`, and ensure that there are no mutations /// or mutable aliases going on when casting to `&T` #[inline] - #[rustc_as_ptr] + #[lint::as_ptr] #[rustc_never_returns_null_ptr] #[rustc_should_not_be_called_on_const_items] pub const fn get(&self) -> *mut T { diff --git a/library/core/src/cell/covariant_unsafe_cell.rs b/library/core/src/cell/covariant_unsafe_cell.rs index 11ac9b58bbb90..0da207137afd0 100644 --- a/library/core/src/cell/covariant_unsafe_cell.rs +++ b/library/core/src/cell/covariant_unsafe_cell.rs @@ -83,7 +83,7 @@ impl CovariantUnsafeCell { /// let ptr: NonNull = uc.get(); /// ``` #[inline(always)] - #[rustc_as_ptr] + #[lint::as_ptr] #[rustc_should_not_be_called_on_const_items] #[unstable(feature = "covariant_unsafe_cell", issue = "159735")] #[rustc_const_unstable(feature = "covariant_unsafe_cell", issue = "159735")] diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index d79af3afbc56e..d45660aa6ec0c 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -486,7 +486,7 @@ impl CStr { #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0")] - #[rustc_as_ptr] + #[lint::as_ptr] #[rustc_never_returns_null_ptr] pub const fn as_ptr(&self) -> *const c_char { self.inner.as_ptr() diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 788140e0fca7c..c4b860f8e072b 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -149,6 +149,7 @@ #![feature(pattern_types)] #![feature(pin_macro_internals)] #![feature(prelude_import)] +#![feature(register_tool)] #![feature(repr_simd)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] @@ -185,6 +186,10 @@ #![feature(x86_amx_intrinsics)] // tidy-alphabetical-end +// tidy-alphabetical-start +#![register_tool(lint)] +// tidy-alphabetical-end + // tidy-alphabetical-start #![expect(clippy::partialeq_ne_impl, reason = "we need to implement ne for a lot of core types")] // tidy-alphabetical-end diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 94703940baa1f..3a5b9b62675b1 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -612,7 +612,7 @@ impl MaybeUninit { /// until they are, it is advisable to avoid them.) #[stable(feature = "maybe_uninit", since = "1.36.0")] #[rustc_const_stable(feature = "const_maybe_uninit_as_ptr", since = "1.59.0")] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline(always)] pub const fn as_ptr(&self) -> *const T { // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. @@ -654,7 +654,7 @@ impl MaybeUninit { /// until they are, it is advisable to avoid them.) #[stable(feature = "maybe_uninit", since = "1.36.0")] #[rustc_const_stable(feature = "const_maybe_uninit_as_mut_ptr", since = "1.83.0")] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline(always)] pub const fn as_mut_ptr(&mut self) -> *mut T { // `MaybeUninit` and `ManuallyDrop` are both `repr(transparent)` so we can cast the pointer. diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 6deba9ce9752e..ecfd8602fa670 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -724,7 +724,7 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline(always)] #[must_use] pub const fn as_ptr(&self) -> *const T { @@ -755,7 +755,7 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[inline(always)] #[must_use] #[rustc_no_writable] diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 017d3f50eba32..5ac1590eedc58 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -583,7 +583,7 @@ impl str { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rustc_str_as_ptr", since = "1.32.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[must_use] #[inline(always)] pub const fn as_ptr(&self) -> *const u8 { @@ -601,7 +601,7 @@ impl str { #[stable(feature = "str_as_mut_ptr", since = "1.36.0")] #[rustc_const_stable(feature = "const_str_as_mut", since = "1.83.0")] #[rustc_never_returns_null_ptr] - #[rustc_as_ptr] + #[lint::as_ptr] #[must_use] #[inline(always)] #[rustc_no_writable] diff --git a/tests/ui/README.md b/tests/ui/README.md index 27995e0ab4cd5..5fa539e1589f5 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -848,6 +848,10 @@ See: - [Lints | The rustc book](https://doc.rust-lang.org/rustc/lints/index.html) - [Lint reasons | Reference](https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-reasons) +## `tests/ui/lint_helper_namespace/` + +Tests for lint helper attributes such as `#[lint::as_ptr]`. + ## `tests/ui/liveness/` Tests exercising analysis for unused variables, unreachable statements, functions which are supposed to return a value but do not, as well as values moved elsewhere before they could be used by a function. diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index e27516d5a60d8..51bf19fd85fb0 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -47,8 +47,9 @@ //~| ERROR attribute cannot be used on #[repr] //~^ ERROR malformed -#[rustc_as_ptr = 5] +#[lint::as_ptr = 5] //~^ ERROR malformed +//~| ERROR cannot find module or crate `lint` in this scope #[inline = 5] //~^ ERROR valid forms for the attribute are //~| WARN this was previously accepted by the compiler diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index 72e7776e09209..aafffbdc76862 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -1,5 +1,5 @@ error[E0539]: malformed `cfg` attribute input - --> $DIR/malformed-attrs.rs:109:3 + --> $DIR/malformed-attrs.rs:110:3 | LL | #[cfg] | ^^^ expected this to be a list @@ -11,7 +11,7 @@ LL | #[cfg(predicate)] | +++++++++++ error[E0539]: malformed `cfg_attr` attribute input - --> $DIR/malformed-attrs.rs:111:3 + --> $DIR/malformed-attrs.rs:112:3 | LL | #[cfg_attr] | ^^^^^^^^ expected this to be a list @@ -23,13 +23,13 @@ LL | #[cfg_attr(predicate, attr1, attr2, ...)] | ++++++++++++++++++++++++++++++ error[E0463]: can't find crate for `wloop` - --> $DIR/malformed-attrs.rs:213:1 + --> $DIR/malformed-attrs.rs:214:1 | LL | extern crate wloop; | ^^^^^^^^^^^^^^^^^^^ can't find crate error: malformed `allow` attribute input - --> $DIR/malformed-attrs.rs:179:1 + --> $DIR/malformed-attrs.rs:180:1 | LL | #[allow] | ^^^^^^^^ @@ -45,7 +45,7 @@ LL | #[allow(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input - --> $DIR/malformed-attrs.rs:181:1 + --> $DIR/malformed-attrs.rs:182:1 | LL | #[expect] | ^^^^^^^^^ @@ -61,7 +61,7 @@ LL | #[expect(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input - --> $DIR/malformed-attrs.rs:183:1 + --> $DIR/malformed-attrs.rs:184:1 | LL | #[warn] | ^^^^^^^ @@ -77,7 +77,7 @@ LL | #[warn(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input - --> $DIR/malformed-attrs.rs:185:1 + --> $DIR/malformed-attrs.rs:186:1 | LL | #[deny] | ^^^^^^^ @@ -93,7 +93,7 @@ LL | #[deny(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input - --> $DIR/malformed-attrs.rs:187:1 + --> $DIR/malformed-attrs.rs:188:1 | LL | #[forbid] | ^^^^^^^^^ @@ -109,23 +109,29 @@ LL | #[forbid(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ error: the `proc_macro` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:106:3 + --> $DIR/malformed-attrs.rs:107:3 | LL | #[proc_macro = 18] | ^^^^^^^^^^ error: the `proc_macro_attribute` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:123:3 + --> $DIR/malformed-attrs.rs:124:3 | LL | #[proc_macro_attribute = 19] | ^^^^^^^^^^^^^^^^^^^^ error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:130:3 + --> $DIR/malformed-attrs.rs:131:3 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^ +error[E0433]: cannot find module or crate `lint` in this scope + --> $DIR/malformed-attrs.rs:50:3 + | +LL | #[lint::as_ptr = 5] + | ^^^^ use of unresolved module or unlinked crate `lint` + error[E0539]: malformed `windows_subsystem` attribute input --> $DIR/malformed-attrs.rs:26:4 | @@ -221,22 +227,22 @@ LL | #[repr] | = note: for more information, visit -error[E0565]: malformed `rustc_as_ptr` attribute input +error[E0565]: malformed `lint::as_ptr` attribute input --> $DIR/malformed-attrs.rs:50:3 | -LL | #[rustc_as_ptr = 5] +LL | #[lint::as_ptr = 5] | ^^^^^^^^^^^^^--- | | | didn't expect any arguments here | help: must be of the form | -LL - #[rustc_as_ptr = 5] -LL + #[rustc_as_ptr] +LL - #[lint::as_ptr = 5] +LL + #[lint::as_ptr] | error[E0539]: malformed `rustc_align` attribute input - --> $DIR/malformed-attrs.rs:55:3 + --> $DIR/malformed-attrs.rs:56:3 | LL | #[rustc_align] | ^^^^^^^^^^^ expected this to be a list @@ -247,7 +253,7 @@ LL | #[rustc_align()] | ++++++++++++++++++++++ error[E0539]: malformed `optimize` attribute input - --> $DIR/malformed-attrs.rs:57:3 + --> $DIR/malformed-attrs.rs:58:3 | LL | #[optimize] | ^^^^^^^^ expected this to be a list @@ -262,7 +268,7 @@ LL | #[optimize(speed)] | +++++++ error[E0805]: malformed `optimize` attribute input - --> $DIR/malformed-attrs.rs:59:3 + --> $DIR/malformed-attrs.rs:60:3 | LL | #[optimize(none, none)] | ^^^^^^^^------------ @@ -282,7 +288,7 @@ LL + #[optimize(speed)] | error[E0805]: malformed `optimize` attribute input - --> $DIR/malformed-attrs.rs:61:3 + --> $DIR/malformed-attrs.rs:62:3 | LL | #[optimize(none, speed)] | ^^^^^^^^------------- @@ -302,7 +308,7 @@ LL + #[optimize(speed)] | error[E0565]: malformed `cold` attribute input - --> $DIR/malformed-attrs.rs:63:3 + --> $DIR/malformed-attrs.rs:64:3 | LL | #[cold = 1] | ^^^^^--- @@ -316,7 +322,7 @@ LL + #[cold] | error[E0539]: malformed `must_use` attribute input - --> $DIR/malformed-attrs.rs:65:3 + --> $DIR/malformed-attrs.rs:66:3 | LL | #[must_use()] | ^^^^^^^^-- @@ -334,7 +340,7 @@ LL + #[must_use = "reason"] | error[E0565]: malformed `no_mangle` attribute input - --> $DIR/malformed-attrs.rs:67:3 + --> $DIR/malformed-attrs.rs:68:3 | LL | #[no_mangle = 1] | ^^^^^^^^^^--- @@ -348,7 +354,7 @@ LL + #[no_mangle] | error[E0565]: malformed `naked` attribute input - --> $DIR/malformed-attrs.rs:69:3 + --> $DIR/malformed-attrs.rs:70:3 | LL | #[unsafe(naked())] | ^^^^^^^^^^^^--^ @@ -362,7 +368,7 @@ LL + #[unsafe(naked)] | error[E0565]: malformed `track_caller` attribute input - --> $DIR/malformed-attrs.rs:71:3 + --> $DIR/malformed-attrs.rs:72:3 | LL | #[track_caller()] | ^^^^^^^^^^^^-- @@ -376,7 +382,7 @@ LL + #[track_caller] | error[E0539]: malformed `export_name` attribute input - --> $DIR/malformed-attrs.rs:73:3 + --> $DIR/malformed-attrs.rs:74:3 | LL | #[export_name()] | ^^^^^^^^^^^^^ @@ -388,7 +394,7 @@ LL + #[export_name = "name"] | error[E0805]: malformed `used` attribute input - --> $DIR/malformed-attrs.rs:75:3 + --> $DIR/malformed-attrs.rs:76:3 | LL | #[used()] | ^^^^-- @@ -406,7 +412,7 @@ LL | #[used(linker)] | ++++++ error: the `used` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:75:3 + --> $DIR/malformed-attrs.rs:76:3 | LL | #[used()] | ^^^^ @@ -414,7 +420,7 @@ LL | #[used()] = help: the `used` attribute can only be applied to statics error[E0539]: malformed `crate_name` attribute input - --> $DIR/malformed-attrs.rs:78:3 + --> $DIR/malformed-attrs.rs:79:3 | LL | #[crate_name] | ^^^^^^^^^^ @@ -425,7 +431,7 @@ LL | #[crate_name = "name"] | ++++++++ error[E0539]: malformed `target_feature` attribute input - --> $DIR/malformed-attrs.rs:81:3 + --> $DIR/malformed-attrs.rs:82:3 | LL | #[target_feature] | ^^^^^^^^^^^^^^ expected this to be a list @@ -436,7 +442,7 @@ LL | #[target_feature(enable = "feat1, feat2")] | +++++++++++++++++++++++++ error[E0565]: malformed `export_stable` attribute input - --> $DIR/malformed-attrs.rs:83:3 + --> $DIR/malformed-attrs.rs:84:3 | LL | #[export_stable = 1] | ^^^^^^^^^^^^^^--- @@ -450,7 +456,7 @@ LL + #[export_stable] | error[E0539]: malformed `link` attribute input - --> $DIR/malformed-attrs.rs:85:3 + --> $DIR/malformed-attrs.rs:86:3 | LL | #[link] | ^^^^ expected this to be a list @@ -458,7 +464,7 @@ LL | #[link] = note: for more information, visit error[E0539]: malformed `link_name` attribute input - --> $DIR/malformed-attrs.rs:89:3 + --> $DIR/malformed-attrs.rs:90:3 | LL | #[link_name] | ^^^^^^^^^ @@ -470,7 +476,7 @@ LL | #[link_name = "name"] | ++++++++ error[E0539]: malformed `link_section` attribute input - --> $DIR/malformed-attrs.rs:93:3 + --> $DIR/malformed-attrs.rs:94:3 | LL | #[link_section] | ^^^^^^^^^^^^ @@ -482,7 +488,7 @@ LL | #[link_section = "name"] | ++++++++ error[E0539]: malformed `coverage` attribute input - --> $DIR/malformed-attrs.rs:95:3 + --> $DIR/malformed-attrs.rs:96:3 | LL | #[coverage] | ^^^^^^^^ expected this to be a list @@ -495,13 +501,13 @@ LL | #[coverage(on)] | ++++ error[E0539]: malformed `sanitize` attribute input - --> $DIR/malformed-attrs.rs:97:3 + --> $DIR/malformed-attrs.rs:98:3 | LL | #[sanitize] | ^^^^^^^^ expected this to be a list error[E0565]: malformed `no_implicit_prelude` attribute input - --> $DIR/malformed-attrs.rs:102:3 + --> $DIR/malformed-attrs.rs:103:3 | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^^---- @@ -515,7 +521,7 @@ LL + #[no_implicit_prelude] | error[E0565]: malformed `proc_macro` attribute input - --> $DIR/malformed-attrs.rs:106:3 + --> $DIR/malformed-attrs.rs:107:3 | LL | #[proc_macro = 18] | ^^^^^^^^^^^---- @@ -529,7 +535,7 @@ LL + #[proc_macro] | error[E0539]: malformed `instruction_set` attribute input - --> $DIR/malformed-attrs.rs:113:3 + --> $DIR/malformed-attrs.rs:114:3 | LL | #[instruction_set] | ^^^^^^^^^^^^^^^ expected this to be a list @@ -541,7 +547,7 @@ LL | #[instruction_set(set)] | +++++ error[E0539]: malformed `patchable_function_entry` attribute input - --> $DIR/malformed-attrs.rs:115:3 + --> $DIR/malformed-attrs.rs:116:3 | LL | #[patchable_function_entry] | ^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -552,7 +558,7 @@ LL | #[patchable_function_entry(prefix_nops = m, entry_nops = n, section = "sect | ++++++++++++++++++++++++++++++++++++++++++++++++++++++ error[E0565]: malformed `coroutine` attribute input - --> $DIR/malformed-attrs.rs:118:7 + --> $DIR/malformed-attrs.rs:119:7 | LL | #[coroutine = 63] || {} | ^^^^^^^^^^---- @@ -566,7 +572,7 @@ LL + #[coroutine] || {} | error[E0565]: malformed `proc_macro_attribute` attribute input - --> $DIR/malformed-attrs.rs:123:3 + --> $DIR/malformed-attrs.rs:124:3 | LL | #[proc_macro_attribute = 19] | ^^^^^^^^^^^^^^^^^^^^^---- @@ -580,7 +586,7 @@ LL + #[proc_macro_attribute] | error[E0539]: malformed `must_use` attribute input - --> $DIR/malformed-attrs.rs:126:3 + --> $DIR/malformed-attrs.rs:127:3 | LL | #[must_use = 1] | ^^^^^^^^^^^- @@ -598,7 +604,7 @@ LL + #[must_use = "reason"] | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/malformed-attrs.rs:130:3 + --> $DIR/malformed-attrs.rs:131:3 | LL | #[proc_macro_derive] | ^^^^^^^^^^^^^^^^^ expected this to be a list @@ -612,7 +618,7 @@ LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] | ++++++++++++++++++++++++++++++++++++++++++ error[E0539]: malformed `must_not_suspend` attribute input - --> $DIR/malformed-attrs.rs:135:3 + --> $DIR/malformed-attrs.rs:136:3 | LL | #[must_not_suspend()] | ^^^^^^^^^^^^^^^^-- @@ -628,7 +634,7 @@ LL | #[must_not_suspend(count)] | +++++ error[E0539]: malformed `cfi_encoding` attribute input - --> $DIR/malformed-attrs.rs:137:3 + --> $DIR/malformed-attrs.rs:138:3 | LL | #[cfi_encoding = ""] | ^^^^^^^^^^^^^^^-- @@ -641,7 +647,7 @@ LL | #[cfi_encoding = "encoding"] | ++++++++ error[E0565]: malformed `marker` attribute input - --> $DIR/malformed-attrs.rs:156:3 + --> $DIR/malformed-attrs.rs:157:3 | LL | #[marker = 3] | ^^^^^^^--- @@ -655,7 +661,7 @@ LL + #[marker] | error[E0565]: malformed `fundamental` attribute input - --> $DIR/malformed-attrs.rs:158:3 + --> $DIR/malformed-attrs.rs:159:3 | LL | #[fundamental()] | ^^^^^^^^^^^-- @@ -669,7 +675,7 @@ LL + #[fundamental] | error[E0565]: malformed `ffi_pure` attribute input - --> $DIR/malformed-attrs.rs:166:7 + --> $DIR/malformed-attrs.rs:167:7 | LL | #[unsafe(ffi_pure = 1)] | ^^^^^^^^^^^^^^^^---^ @@ -683,7 +689,7 @@ LL + #[unsafe(ffi_pure)] | error[E0539]: malformed `link_ordinal` attribute input - --> $DIR/malformed-attrs.rs:168:7 + --> $DIR/malformed-attrs.rs:169:7 | LL | #[link_ordinal] | ^^^^^^^^^^^^ expected this to be a list @@ -695,7 +701,7 @@ LL | #[link_ordinal(ordinal)] | +++++++++ error[E0565]: malformed `ffi_const` attribute input - --> $DIR/malformed-attrs.rs:172:7 + --> $DIR/malformed-attrs.rs:173:7 | LL | #[unsafe(ffi_const = 1)] | ^^^^^^^^^^^^^^^^^---^ @@ -709,13 +715,13 @@ LL + #[unsafe(ffi_const)] | error[E0539]: malformed `linkage` attribute input - --> $DIR/malformed-attrs.rs:174:7 + --> $DIR/malformed-attrs.rs:175:7 | LL | #[linkage] | ^^^^^^^ expected this to be of the form `linkage = "..."` error[E0539]: malformed `debugger_visualizer` attribute input - --> $DIR/malformed-attrs.rs:189:3 + --> $DIR/malformed-attrs.rs:190:3 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^ expected this to be a list @@ -727,7 +733,7 @@ LL | #[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")] | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0565]: malformed `automatically_derived` attribute input - --> $DIR/malformed-attrs.rs:191:3 + --> $DIR/malformed-attrs.rs:192:3 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^^---- @@ -741,7 +747,7 @@ LL + #[automatically_derived] | error[E0565]: malformed `non_exhaustive` attribute input - --> $DIR/malformed-attrs.rs:199:3 + --> $DIR/malformed-attrs.rs:200:3 | LL | #[non_exhaustive = 1] | ^^^^^^^^^^^^^^^--- @@ -755,7 +761,7 @@ LL + #[non_exhaustive] | error[E0565]: malformed `thread_local` attribute input - --> $DIR/malformed-attrs.rs:205:3 + --> $DIR/malformed-attrs.rs:206:3 | LL | #[thread_local()] | ^^^^^^^^^^^^-- @@ -769,7 +775,7 @@ LL + #[thread_local] | error[E0565]: malformed `no_link` attribute input - --> $DIR/malformed-attrs.rs:209:3 + --> $DIR/malformed-attrs.rs:210:3 | LL | #[no_link()] | ^^^^^^^-- @@ -783,7 +789,7 @@ LL + #[no_link] | error[E0539]: malformed `macro_use` attribute input - --> $DIR/malformed-attrs.rs:211:3 + --> $DIR/malformed-attrs.rs:212:3 | LL | #[macro_use = 1] | ^^^^^^^^^^--- @@ -801,7 +807,7 @@ LL + #[macro_use(name1, name2, ...)] | error[E0539]: malformed `macro_export` attribute input - --> $DIR/malformed-attrs.rs:216:3 + --> $DIR/malformed-attrs.rs:217:3 | LL | #[macro_export = 18] | ^^^^^^^^^^^^^---- @@ -818,7 +824,7 @@ LL + #[macro_export(local_inner_macros)] | error[E0658]: the `allow_internal_unsafe` attribute side-steps the `unsafe_code` lint - --> $DIR/malformed-attrs.rs:218:3 + --> $DIR/malformed-attrs.rs:219:3 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^ @@ -827,7 +833,7 @@ LL | #[allow_internal_unsafe = 1] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0565]: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:218:3 + --> $DIR/malformed-attrs.rs:219:3 | LL | #[allow_internal_unsafe = 1] | ^^^^^^^^^^^^^^^^^^^^^^--- @@ -871,7 +877,7 @@ LL | #[doc()] | ^^^^^ error: valid forms for the attribute are `inline`, `inline(always)`, and `inline(never)` - --> $DIR/malformed-attrs.rs:52:3 + --> $DIR/malformed-attrs.rs:53:3 | LL | #[inline = 5] | ^^^^^^^^^^ @@ -881,13 +887,13 @@ LL | #[inline = 5] = note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![crate_name]` - --> $DIR/malformed-attrs.rs:78:1 + --> $DIR/malformed-attrs.rs:79:1 | LL | #[crate_name] | ^^^^^^^^^^^^^ | note: this attribute does not have an `!`, which means it is applied to this function - --> $DIR/malformed-attrs.rs:117:1 + --> $DIR/malformed-attrs.rs:118:1 | LL | / fn test() { LL | | #[coroutine = 63] || {} @@ -897,7 +903,7 @@ LL | | } = note: requested on the command line with `-W unused-attributes` warning: the `link` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:85:3 + --> $DIR/malformed-attrs.rs:86:3 | LL | #[link] | ^^^^ @@ -906,7 +912,7 @@ LL | #[link] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: the `link_name` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:89:3 + --> $DIR/malformed-attrs.rs:90:3 | LL | #[link_name] | ^^^^^^^^^ @@ -915,7 +921,7 @@ LL | #[link_name] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: valid forms for the attribute are `ignore` and `ignore = "reason"` - --> $DIR/malformed-attrs.rs:99:3 + --> $DIR/malformed-attrs.rs:100:3 | LL | #[ignore()] | ^^^^^^^^ @@ -924,7 +930,7 @@ LL | #[ignore()] = note: for more information, see issue #57571 warning: the `no_implicit_prelude` attribute cannot be used on functions - --> $DIR/malformed-attrs.rs:102:3 + --> $DIR/malformed-attrs.rs:103:3 | LL | #[no_implicit_prelude = 23] | ^^^^^^^^^^^^^^^^^^^ @@ -933,7 +939,7 @@ LL | #[no_implicit_prelude = 23] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! warning: missing options for `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:141:1 + --> $DIR/malformed-attrs.rs:142:1 | LL | #[diagnostic::on_unimplemented] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -942,7 +948,7 @@ LL | #[diagnostic::on_unimplemented] = note: `#[warn(malformed_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default warning: malformed `diagnostic::on_unimplemented` attribute - --> $DIR/malformed-attrs.rs:143:1 + --> $DIR/malformed-attrs.rs:144:1 | LL | #[diagnostic::on_unimplemented = 1] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid option found here @@ -950,13 +956,13 @@ LL | #[diagnostic::on_unimplemented = 1] = help: only `message`, `note` and `label` are allowed as options warning: `#[diagnostic::do_not_recommend]` does not expect any arguments - --> $DIR/malformed-attrs.rs:150:1 + --> $DIR/malformed-attrs.rs:151:1 | LL | #[diagnostic::do_not_recommend()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: the `automatically_derived` attribute cannot be used on modules - --> $DIR/malformed-attrs.rs:191:3 + --> $DIR/malformed-attrs.rs:192:3 | LL | #[automatically_derived = 18] | ^^^^^^^^^^^^^^^^^^^^^ @@ -965,7 +971,7 @@ LL | #[automatically_derived = 18] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! error: valid forms for the attribute are `ignore` and `ignore = "reason"` - --> $DIR/malformed-attrs.rs:225:3 + --> $DIR/malformed-attrs.rs:226:3 | LL | #[ignore = 1] | ^^^^^^^^^^ @@ -974,7 +980,7 @@ LL | #[ignore = 1] = note: for more information, see issue #57571 error[E0308]: mismatched types - --> $DIR/malformed-attrs.rs:118:23 + --> $DIR/malformed-attrs.rs:119:23 | LL | fn test() { | - help: a return type might be missing here: `-> _` @@ -982,15 +988,15 @@ LL | #[coroutine = 63] || {} | ^^^^^ expected `()`, found coroutine | = note: expected unit type `()` - found coroutine `{coroutine@$DIR/malformed-attrs.rs:118:23: 118:25}` + found coroutine `{coroutine@$DIR/malformed-attrs.rs:119:23: 119:25}` -error: aborting due to 74 previous errors; 8 warnings emitted +error: aborting due to 75 previous errors; 8 warnings emitted -Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. +Some errors have detailed explanations: E0308, E0433, E0463, E0539, E0565, E0658, E0805. For more information about an error, try `rustc --explain E0308`. Future incompatibility report: Future breakage diagnostic: error: valid forms for the attribute are `inline`, `inline(always)`, and `inline(never)` - --> $DIR/malformed-attrs.rs:52:3 + --> $DIR/malformed-attrs.rs:53:3 | LL | #[inline = 5] | ^^^^^^^^^^ @@ -1001,7 +1007,7 @@ LL | #[inline = 5] Future breakage diagnostic: error: valid forms for the attribute are `ignore` and `ignore = "reason"` - --> $DIR/malformed-attrs.rs:99:3 + --> $DIR/malformed-attrs.rs:100:3 | LL | #[ignore()] | ^^^^^^^^ @@ -1012,7 +1018,7 @@ LL | #[ignore()] Future breakage diagnostic: error: valid forms for the attribute are `ignore` and `ignore = "reason"` - --> $DIR/malformed-attrs.rs:225:3 + --> $DIR/malformed-attrs.rs:226:3 | LL | #[ignore = 1] | ^^^^^^^^^^ diff --git a/tests/ui/lint_helper_namespace/feature_gates.rs b/tests/ui/lint_helper_namespace/feature_gates.rs new file mode 100644 index 0000000000000..11bb8d91ba43e --- /dev/null +++ b/tests/ui/lint_helper_namespace/feature_gates.rs @@ -0,0 +1,8 @@ +#![crate_type = "lib"] +#![feature(register_tool)] +#![register_tool(lint)] + +#[lint::as_ptr] //~ ERROR use of an internal attribute +fn cast(x: &u8) -> *const u8 { + x +} diff --git a/tests/ui/lint_helper_namespace/feature_gates.stderr b/tests/ui/lint_helper_namespace/feature_gates.stderr new file mode 100644 index 0000000000000..b597afab19442 --- /dev/null +++ b/tests/ui/lint_helper_namespace/feature_gates.stderr @@ -0,0 +1,12 @@ +error[E0658]: use of an internal attribute + --> $DIR/feature_gates.rs:5:3 + | +LL | #[lint::as_ptr] + | ^^^^^^^^^^^^ + | + = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable + = note: the `lint::as_ptr` attribute is an internal implementation detail that will never be stable + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/lint_helper_namespace/registered_invalid.rs b/tests/ui/lint_helper_namespace/registered_invalid.rs new file mode 100644 index 0000000000000..9295d74c2519a --- /dev/null +++ b/tests/ui/lint_helper_namespace/registered_invalid.rs @@ -0,0 +1,6 @@ +#![crate_type = "lib"] +#![feature(register_tool)] +#![register_tool(lint)] + +#[lint::bogus] //~ ERROR the `lint::bogus` attribute is not recognized +struct Foo; diff --git a/tests/ui/lint_helper_namespace/registered_invalid.stderr b/tests/ui/lint_helper_namespace/registered_invalid.stderr new file mode 100644 index 0000000000000..216c1659ed21d --- /dev/null +++ b/tests/ui/lint_helper_namespace/registered_invalid.stderr @@ -0,0 +1,8 @@ +error: the `lint::bogus` attribute is not recognized + --> $DIR/registered_invalid.rs:5:3 + | +LL | #[lint::bogus] + | ^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/lint_helper_namespace/registered_resolve_as_macro.rs b/tests/ui/lint_helper_namespace/registered_resolve_as_macro.rs new file mode 100644 index 0000000000000..49c17fffe9975 --- /dev/null +++ b/tests/ui/lint_helper_namespace/registered_resolve_as_macro.rs @@ -0,0 +1,18 @@ +//@check-pass + +#![crate_type = "lib"] + +#![feature(decl_macro)] +#![feature(macro_attr)] +#![feature(register_tool)] +#![register_tool(lint)] + +#[lint::as_ptr] +struct Foo; + +mod lint { + // On stable rust, this could be a re-exported proc macro + pub macro as_ptr { + attr() { $($tt:tt)* } => { $($tt)* } + } +} diff --git a/tests/ui/lint_helper_namespace/unregistered.rs b/tests/ui/lint_helper_namespace/unregistered.rs new file mode 100644 index 0000000000000..8c26a9307b476 --- /dev/null +++ b/tests/ui/lint_helper_namespace/unregistered.rs @@ -0,0 +1,4 @@ +#![crate_type = "lib"] + +#[lint::mac] //~ ERROR cannot find module or crate `lint` in this scope +struct Foo; diff --git a/tests/ui/lint_helper_namespace/unregistered.stderr b/tests/ui/lint_helper_namespace/unregistered.stderr new file mode 100644 index 0000000000000..59fc106db6521 --- /dev/null +++ b/tests/ui/lint_helper_namespace/unregistered.stderr @@ -0,0 +1,9 @@ +error[E0433]: cannot find module or crate `lint` in this scope + --> $DIR/unregistered.rs:3:3 + | +LL | #[lint::mac] + | ^^^^ use of unresolved module or unlinked crate `lint` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/lint_helper_namespace/unregistered_resolve_as_macro.rs b/tests/ui/lint_helper_namespace/unregistered_resolve_as_macro.rs new file mode 100644 index 0000000000000..603996bb0f9c2 --- /dev/null +++ b/tests/ui/lint_helper_namespace/unregistered_resolve_as_macro.rs @@ -0,0 +1,16 @@ +//@check-pass + +#![feature(decl_macro)] +#![feature(macro_attr)] + +#![crate_type = "lib"] + +#[lint::as_ptr] +struct Foo; + +mod lint { + // On stable rust, this could be a re-exported proc macro + pub macro as_ptr { + attr() { $($tt:tt)* } => { $($tt)* } + } +} From 013d5031824413f652f9a357f1351d16dc546274 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:28:11 +0200 Subject: [PATCH 2/4] port over `rustc_never_returns_null_ptr` to lint helper namespace --- compiler/rustc_attr_ir/src/data_structures.rs | 6 +++--- compiler/rustc_attr_ir/src/encode_cross_crate.rs | 4 ++-- .../src/attributes/lint_helpers.rs | 16 ++++++++++++++++ .../src/attributes/rustc_internal.rs | 16 ---------------- compiler/rustc_attr_parsing/src/context.rs | 2 +- compiler/rustc_feature/src/builtin_attrs.rs | 1 - compiler/rustc_lint/src/ptr_nulls.rs | 6 +++--- compiler/rustc_passes/src/check_attr.rs | 3 +-- compiler/rustc_span/src/symbol.rs | 2 +- library/alloc/src/boxed.rs | 9 +++++---- library/alloc/src/rcs/arc.rs | 4 ++-- library/alloc/src/rcs/rc.rs | 4 ++-- library/alloc/src/vec/mod.rs | 7 ++++--- library/core/src/cell.rs | 10 +++++----- library/core/src/ffi/c_str.rs | 2 +- library/core/src/ptr/mod.rs | 4 ++-- library/core/src/ptr/non_null.rs | 4 ++-- library/core/src/slice/mod.rs | 6 +++--- library/core/src/str/mod.rs | 8 ++++---- library/core/src/sync/atomic.rs | 6 +++--- tests/ui/lint_helper_namespace/feature_gates.rs | 1 + .../lint_helper_namespace/feature_gates.stderr | 11 ++++++++++- 22 files changed, 71 insertions(+), 61 deletions(-) diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index cb721509316f0..4bf0726d4c379 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -935,6 +935,9 @@ pub enum AttributeKind { /// Represents `#[lint::as_ptr]` (used by the `dangling_pointers_from_temporaries` lint). LintAsPtr, + /// Represents `#[lint::never_returns_null_ptr]` (used by the `useless_ptr_null_checks` lint). + LintNeverReturnsNullPtr, + /// Represents `#[loop_match]`. LoopMatch(Span), @@ -1333,9 +1336,6 @@ pub enum AttributeKind { /// Represents `#[rustc_must_match_exhaustively]` RustcMustMatchExhaustively(Span), - /// Represents `#[rustc_never_returns_null_ptr]` - RustcNeverReturnsNullPtr, - /// Represents `#[rustc_no_implicit_autorefs]` RustcNoImplicitAutorefs, diff --git a/compiler/rustc_attr_ir/src/encode_cross_crate.rs b/compiler/rustc_attr_ir/src/encode_cross_crate.rs index 4c039709c8376..3d226b9701b76 100644 --- a/compiler/rustc_attr_ir/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_ir/src/encode_cross_crate.rs @@ -59,6 +59,7 @@ impl AttributeKind { LinkSection { .. } => Yes, // Needed for rustdoc Linkage(..) => No, LintAsPtr => Yes, + LintNeverReturnsNullPtr => Yes, LoopMatch(..) => No, MacroEscape => No, MacroExport { .. } => Yes, @@ -165,7 +166,6 @@ impl AttributeKind { RustcMir(..) => Yes, RustcMustImplementOneOf { .. } => No, RustcMustMatchExhaustively(..) => Yes, - RustcNeverReturnsNullPtr => Yes, RustcNoImplicitAutorefs => Yes, RustcNoImplicitBounds => No, RustcNoMirInline => Yes, @@ -273,6 +273,7 @@ impl AttributeKind { | crate::Linkage::WeakODR => true, }, LintAsPtr => false, + LintNeverReturnsNullPtr => false, LoopMatch(..) => false, MacroEscape => false, MacroExport { .. } => false, @@ -379,7 +380,6 @@ impl AttributeKind { RustcMir(..) => false, RustcMustImplementOneOf { .. } => false, RustcMustMatchExhaustively(..) => false, - RustcNeverReturnsNullPtr => false, RustcNoImplicitAutorefs => false, RustcNoImplicitBounds => false, RustcNoMirInline => false, diff --git a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs index 6c1c91eadfb53..725e458c99c5e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs @@ -18,6 +18,22 @@ impl NoArgsAttributeParser for LintAsPtrParser { const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::LintAsPtr; } +pub(crate) struct LintNeverReturnsNullPtrParser; + +impl NoArgsAttributeParser for LintNeverReturnsNullPtrParser { + const PATH: &[Symbol] = &[sym::lint, sym::never_returns_null_ptr]; + const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ + Allow(Target::Fn), + Allow(Target::Method(MethodKind::Inherent)), + Allow(Target::Method(MethodKind::Trait { body: false })), + Allow(Target::Method(MethodKind::Trait { body: true })), + Allow(Target::Method(MethodKind::TraitImpl)), + ]); + const STABILITY: AttributeStability = unstable!(rustc_attrs); + + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::LintNeverReturnsNullPtr; +} + pub(crate) struct RustcPubTransparentParser; impl NoArgsAttributeParser for RustcPubTransparentParser { const PATH: &[Symbol] = &[sym::rustc_pub_transparent]; diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index bb982184772e7..6cd5294161134 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -88,22 +88,6 @@ impl SingleAttributeParser for RustcMustImplementOneOfParser { } } -pub(crate) struct RustcNeverReturnsNullPtrParser; - -impl NoArgsAttributeParser for RustcNeverReturnsNullPtrParser { - const PATH: &[Symbol] = &[sym::rustc_never_returns_null_ptr]; - const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ - Allow(Target::Fn), - Allow(Target::Method(MethodKind::Inherent)), - Allow(Target::Method(MethodKind::Trait { body: false })), - Allow(Target::Method(MethodKind::Trait { body: true })), - Allow(Target::Method(MethodKind::TraitImpl)), - ]); - const STABILITY: AttributeStability = unstable!(rustc_attrs); - - const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNeverReturnsNullPtr; -} - pub(crate) struct RustcPanicsWhenZeroParser; impl NoArgsAttributeParser for RustcPanicsWhenZeroParser { diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 15467029be970..4ddc15d4eccf2 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -272,6 +272,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, @@ -332,7 +333,6 @@ attribute_parsers!( Single>, Single>, Single>, - Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index f1c0b0ff1c121..c063e36c66c50 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -348,7 +348,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ sym::lang, sym::rustc_should_not_be_called_on_const_items, sym::rustc_pass_by_value, - sym::rustc_never_returns_null_ptr, sym::rustc_no_implicit_autorefs, sym::rustc_coherence_is_core, sym::rustc_coinductive, diff --git a/compiler/rustc_lint/src/ptr_nulls.rs b/compiler/rustc_lint/src/ptr_nulls.rs index c231bd4cc3b30..0010022aa4f9d 100644 --- a/compiler/rustc_lint/src/ptr_nulls.rs +++ b/compiler/rustc_lint/src/ptr_nulls.rs @@ -62,7 +62,7 @@ declare_lint_pass!(PtrNullChecks => [USELESS_PTR_NULL_CHECKS, INVALID_NULL_ARGUM /// This function checks if the expression is from a series of consecutive casts, /// i.e. `(my_fn as *const _ as *mut _).cast_mut()` and whether the original expression is either /// a fn ptr, a reference, or a function call whose definition is -/// annotated with `#![rustc_never_returns_null_ptr]`. +/// annotated with `#[lint::never_returns_null_ptr]`. /// If this situation is present, the function returns the appropriate diagnostic. fn useless_check<'a, 'tcx: 'a>( cx: &'a LateContext<'tcx>, @@ -73,14 +73,14 @@ fn useless_check<'a, 'tcx: 'a>( e = e.peel_blocks(); if let ExprKind::MethodCall(_, _expr, [], _) = e.kind && let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) - && find_attr!(cx.tcx, def_id, RustcNeverReturnsNullPtr) + && find_attr!(cx.tcx, def_id, LintNeverReturnsNullPtr) && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) { return Some(UselessPtrNullChecksDiag::FnRet { fn_name }); } else if let ExprKind::Call(path, _args) = e.kind && let ExprKind::Path(ref qpath) = path.kind && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() - && find_attr!(cx.tcx, def_id, RustcNeverReturnsNullPtr) + && find_attr!(cx.tcx, def_id, LintNeverReturnsNullPtr) && let Some(fn_name) = cx.tcx.opt_item_ident(def_id) { return Some(UselessPtrNullChecksDiag::FnRet { fn_name }); diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index f986205427b08..b947007b50135 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -268,6 +268,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::LinkOrdinal { .. } => (), AttributeKind::LinkSection { .. } => (), AttributeKind::LintAsPtr => (), + AttributeKind::LintNeverReturnsNullPtr => (), AttributeKind::LoopMatch(..) => (), AttributeKind::MacroEscape => (), AttributeKind::MacroExport { .. } => (), @@ -363,7 +364,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcMain => (), AttributeKind::RustcMir(_) => (), AttributeKind::RustcMustMatchExhaustively(..) => (), - AttributeKind::RustcNeverReturnsNullPtr => (), AttributeKind::RustcNoImplicitAutorefs => (), AttributeKind::RustcNoImplicitBounds => (), AttributeKind::RustcNoMirInline => (), @@ -387,7 +387,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcShouldNotBeCalledOnConstItems => (), AttributeKind::RustcSimdMonomorphizeLaneLimit(..) => (), AttributeKind::RustcSkipDuringMethodDispatch { .. } => (), - AttributeKind::RustcSpecializationTrait => (), AttributeKind::RustcStdInternalSymbol => (), AttributeKind::RustcStrictCoherence(..) => (), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8814f8c573350..c1a4e7a2e5e49 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1444,6 +1444,7 @@ symbols! { nested, never, never_patterns, + never_returns_null_ptr, never_type, never_type_fallback, new, @@ -1872,7 +1873,6 @@ symbols! { rustc_mir, rustc_must_implement_one_of, rustc_must_match_exhaustively, - rustc_never_returns_null_ptr, rustc_no_implicit_autorefs, rustc_no_implicit_bounds, rustc_no_mir_inline, diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index c58d992be61fd..cdeec3a95a4dd 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -1764,9 +1764,9 @@ impl Box { /// [`as_non_null`]: Self::as_non_null #[must_use] #[stable(feature = "box_as_ptr", since = "1.98.0")] - #[rustc_never_returns_null_ptr] - #[lint::as_ptr] #[inline] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] pub fn as_mut_ptr(b: &mut Self) -> *mut T { // This is a primitive deref, not going through `DerefMut`, and therefore not materializing // any references. @@ -1813,9 +1813,10 @@ impl Box { /// [`as_non_null`]: Self::as_non_null #[must_use] #[stable(feature = "box_as_ptr", since = "1.98.0")] - #[rustc_never_returns_null_ptr] - #[lint::as_ptr] #[inline] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] + pub fn as_ptr(b: &Self) -> *const T { // This is a primitive deref, not going through `DerefMut`, and therefore not materializing // any references. diff --git a/library/alloc/src/rcs/arc.rs b/library/alloc/src/rcs/arc.rs index 5b42173da5a3a..89a91ebd3170c 100644 --- a/library/alloc/src/rcs/arc.rs +++ b/library/alloc/src/rcs/arc.rs @@ -1725,7 +1725,7 @@ impl Arc { /// ``` #[must_use = "losing the pointer will leak memory"] #[stable(feature = "rc_raw", since = "1.17.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub fn into_raw(this: Self) -> *const T { let this = ManuallyDrop::new(this); Self::as_ptr(&*this) @@ -1922,7 +1922,7 @@ impl Arc { /// ``` #[must_use] #[stable(feature = "rc_as_ptr", since = "1.45.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr); diff --git a/library/alloc/src/rcs/rc.rs b/library/alloc/src/rcs/rc.rs index d928e42f71e20..fe052ded63330 100644 --- a/library/alloc/src/rcs/rc.rs +++ b/library/alloc/src/rcs/rc.rs @@ -1566,7 +1566,7 @@ impl Rc { /// ``` #[must_use = "losing the pointer will leak memory"] #[stable(feature = "rc_raw", since = "1.17.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub fn into_raw(this: Self) -> *const T { let this = ManuallyDrop::new(this); Self::as_ptr(&*this) @@ -1747,7 +1747,7 @@ impl Rc { /// assert_eq!(unsafe { *x_ptr }, 0); /// ``` #[stable(feature = "weak_into_raw", since = "1.45.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut RcInner = NonNull::as_ptr(this.ptr); diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 5bf5bc76a6be9..1e5c963b455ac 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1953,9 +1953,10 @@ impl Vec { /// [`as_non_null`]: Vec::as_non_null #[stable(feature = "vec_as_ptr", since = "1.37.0")] #[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")] - #[rustc_never_returns_null_ptr] - #[lint::as_ptr] #[inline] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] + pub const fn as_ptr(&self) -> *const T { // We shadow the slice method of the same name to avoid going through // `deref`, which creates an intermediate reference. @@ -2037,8 +2038,8 @@ impl Vec { /// [`ManuallyDrop`]: core::mem::ManuallyDrop #[stable(feature = "vec_as_ptr", since = "1.37.0")] #[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")] - #[rustc_never_returns_null_ptr] #[lint::as_ptr] + #[lint::never_returns_null_ptr] #[inline] pub const fn as_mut_ptr(&mut self) -> *mut T { // We shadow the slice method of the same name to avoid going through diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 1fddb9ea1aa54..c6e08e2bf5261 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -599,7 +599,7 @@ impl Cell { #[stable(feature = "cell_as_ptr", since = "1.12.0")] #[rustc_const_stable(feature = "const_cell_as_ptr", since = "1.32.0")] #[lint::as_ptr] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *mut T { self.value.get() } @@ -1289,9 +1289,9 @@ impl RefCell { /// ``` #[inline] #[stable(feature = "cell_as_ptr", since = "1.12.0")] - #[lint::as_ptr] - #[rustc_never_returns_null_ptr] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *mut T { self.value.get() } @@ -2429,7 +2429,7 @@ impl UnsafeCell { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")] #[lint::as_ptr] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] #[rustc_should_not_be_called_on_const_items] pub const fn get(&self) -> *mut T { // We can just cast the pointer from `UnsafeCell` to `T` because of @@ -2636,7 +2636,7 @@ impl SyncUnsafeCell { /// or mutable aliases going on when casting to `&T` #[inline] #[lint::as_ptr] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] #[rustc_should_not_be_called_on_const_items] pub const fn get(&self) -> *mut T { self.value.get() diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index d45660aa6ec0c..f0dc1485838ec 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -487,7 +487,7 @@ impl CStr { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_str_as_ptr", since = "1.32.0")] #[lint::as_ptr] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *const c_char { self.inner.as_ptr() } diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 9019e3a486921..8a6324249b8e7 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -1120,7 +1120,7 @@ pub const fn with_exposed_provenance_mut(addr: usize) -> *mut T { #[must_use] #[stable(feature = "ptr_from_ref", since = "1.76.0")] #[rustc_const_stable(feature = "ptr_from_ref", since = "1.76.0")] -#[rustc_never_returns_null_ptr] +#[lint::never_returns_null_ptr] #[rustc_diagnostic_item = "ptr_from_ref"] pub const fn from_ref(r: &T) -> *const T { r @@ -1171,7 +1171,7 @@ pub const fn from_ref(r: &T) -> *const T { #[must_use] #[stable(feature = "ptr_from_ref", since = "1.76.0")] #[rustc_const_stable(feature = "ptr_from_ref", since = "1.76.0")] -#[rustc_never_returns_null_ptr] +#[lint::never_returns_null_ptr] pub const fn from_mut(r: &mut T) -> *mut T { r } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index a279c373dea4a..c88a43e2530d7 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -405,9 +405,9 @@ impl NonNull { /// ``` #[stable(feature = "nonnull", since = "1.25.0")] #[rustc_const_stable(feature = "const_nonnull_as_ptr", since = "1.32.0")] - #[rustc_never_returns_null_ptr] #[must_use] #[inline(always)] + #[lint::never_returns_null_ptr] pub const fn as_ptr(self) -> *mut T { // This is a transmute for the same reasons as `NonZero::get`. @@ -1468,7 +1468,7 @@ impl NonNull<[T]> { #[inline] #[must_use] #[unstable(feature = "slice_ptr_get", issue = "74265")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub const fn as_mut_ptr(self) -> *mut T { self.as_non_null_ptr().as_ptr() } diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index ecfd8602fa670..3bb82b762223e 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -723,10 +723,10 @@ impl [T] { /// [`as_mut_ptr`]: slice::as_mut_ptr #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")] - #[rustc_never_returns_null_ptr] - #[lint::as_ptr] #[inline(always)] #[must_use] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *const T { self as *const [T] as *const T } @@ -754,8 +754,8 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_ptr_offset", since = "1.61.0")] - #[rustc_never_returns_null_ptr] #[lint::as_ptr] + #[lint::never_returns_null_ptr] #[inline(always)] #[must_use] #[rustc_no_writable] diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 5ac1590eedc58..9013107804931 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -582,10 +582,10 @@ impl str { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "rustc_str_as_ptr", since = "1.32.0")] - #[rustc_never_returns_null_ptr] - #[lint::as_ptr] #[must_use] #[inline(always)] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *const u8 { self as *const str as *const u8 } @@ -600,11 +600,11 @@ impl str { /// modified in a way that it remains valid UTF-8. #[stable(feature = "str_as_mut_ptr", since = "1.36.0")] #[rustc_const_stable(feature = "const_str_as_mut", since = "1.83.0")] - #[rustc_never_returns_null_ptr] - #[lint::as_ptr] #[must_use] #[inline(always)] #[rustc_no_writable] + #[lint::as_ptr] + #[lint::never_returns_null_ptr] pub const fn as_mut_ptr(&mut self) -> *mut u8 { self as *mut str as *mut u8 } diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 14e33019a45ff..0925659a028ff 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -1415,7 +1415,7 @@ impl AtomicBool { #[inline] #[stable(feature = "atomic_as_ptr", since = "1.70.0")] #[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] #[rustc_should_not_be_called_on_const_items] pub const fn as_ptr(&self) -> *mut bool { self.v.get().cast() @@ -2747,7 +2747,7 @@ impl AtomicPtr { #[inline] #[stable(feature = "atomic_as_ptr", since = "1.70.0")] #[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *mut *mut T { self.v.get().cast() } @@ -4009,7 +4009,7 @@ macro_rules! atomic_int { #[inline] #[stable(feature = "atomic_as_ptr", since = "1.70.0")] #[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")] - #[rustc_never_returns_null_ptr] + #[lint::never_returns_null_ptr] pub const fn as_ptr(&self) -> *mut $int_type { self.v.get().cast() } diff --git a/tests/ui/lint_helper_namespace/feature_gates.rs b/tests/ui/lint_helper_namespace/feature_gates.rs index 11bb8d91ba43e..d5e1008f89f57 100644 --- a/tests/ui/lint_helper_namespace/feature_gates.rs +++ b/tests/ui/lint_helper_namespace/feature_gates.rs @@ -3,6 +3,7 @@ #![register_tool(lint)] #[lint::as_ptr] //~ ERROR use of an internal attribute +#[lint::never_returns_null_ptr] //~ ERROR use of an internal attribute fn cast(x: &u8) -> *const u8 { x } diff --git a/tests/ui/lint_helper_namespace/feature_gates.stderr b/tests/ui/lint_helper_namespace/feature_gates.stderr index b597afab19442..0bed2a048ab23 100644 --- a/tests/ui/lint_helper_namespace/feature_gates.stderr +++ b/tests/ui/lint_helper_namespace/feature_gates.stderr @@ -7,6 +7,15 @@ LL | #[lint::as_ptr] = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable = note: the `lint::as_ptr` attribute is an internal implementation detail that will never be stable -error: aborting due to 1 previous error +error[E0658]: use of an internal attribute + --> $DIR/feature_gates.rs:6:3 + | +LL | #[lint::never_returns_null_ptr] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable + = note: the `lint::never_returns_null_ptr` attribute is an internal implementation detail that will never be stable + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`. From 50ca13e1c5852ac92bb8b4e0584b0faef0d50b93 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Thu, 1 Oct 2026 23:08:59 +0200 Subject: [PATCH 3/4] Port over `rustc_should_not_be_called_on_const_items` to lint helper namespace --- compiler/rustc_attr_ir/src/data_structures.rs | 7 +- .../rustc_attr_ir/src/encode_cross_crate.rs | 5 +- .../src/attributes/lint_helpers.rs | 8 +- compiler/rustc_attr_parsing/src/context.rs | 2 +- compiler/rustc_feature/src/builtin_attrs.rs | 1 - .../rustc_lint/src/interior_mutable_consts.rs | 2 +- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_span/src/symbol.rs | 2 +- library/core/src/cell.rs | 34 +++---- .../core/src/cell/covariant_unsafe_cell.rs | 2 +- library/core/src/cell/lazy.rs | 2 +- library/core/src/cell/once.rs | 8 +- library/core/src/sync/atomic.rs | 96 +++++++++---------- library/std/src/lib.rs | 5 + library/std/src/sync/lazy_lock.rs | 4 +- library/std/src/sync/once.rs | 8 +- library/std/src/sync/once_lock.rs | 12 +-- library/std/src/sync/poison/condvar.rs | 14 +-- library/std/src/sync/poison/mutex.rs | 10 +- library/std/src/sync/poison/rwlock.rs | 12 +-- .../ui/lint_helper_namespace/feature_gates.rs | 13 ++- .../feature_gates.stderr | 23 +++-- 22 files changed, 146 insertions(+), 126 deletions(-) diff --git a/compiler/rustc_attr_ir/src/data_structures.rs b/compiler/rustc_attr_ir/src/data_structures.rs index 4bf0726d4c379..c54704c0c51b7 100644 --- a/compiler/rustc_attr_ir/src/data_structures.rs +++ b/compiler/rustc_attr_ir/src/data_structures.rs @@ -938,6 +938,10 @@ pub enum AttributeKind { /// Represents `#[lint::never_returns_null_ptr]` (used by the `useless_ptr_null_checks` lint). LintNeverReturnsNullPtr, + /// Represents `#[lint::should_not_be_called_on_const_items]` (used by the + /// `const_item_interior_mutations` lint). + LintShouldNotBeCalledOnConstItems, + /// Represents `#[loop_match]`. LoopMatch(Span), @@ -1404,9 +1408,6 @@ pub enum AttributeKind { element_count: Option, }, - /// Represents `#[rustc_should_not_be_called_on_const_items]` - RustcShouldNotBeCalledOnConstItems, - /// Represents `#[rustc_simd_monomorphize_lane_limit = "N"]`. RustcSimdMonomorphizeLaneLimit(Limit), diff --git a/compiler/rustc_attr_ir/src/encode_cross_crate.rs b/compiler/rustc_attr_ir/src/encode_cross_crate.rs index 3d226b9701b76..bf718bf0173a8 100644 --- a/compiler/rustc_attr_ir/src/encode_cross_crate.rs +++ b/compiler/rustc_attr_ir/src/encode_cross_crate.rs @@ -60,6 +60,7 @@ impl AttributeKind { Linkage(..) => No, LintAsPtr => Yes, LintNeverReturnsNullPtr => Yes, + LintShouldNotBeCalledOnConstItems => Yes, LoopMatch(..) => No, MacroEscape => No, MacroExport { .. } => Yes, @@ -186,7 +187,6 @@ impl AttributeKind { RustcReallocator => No, RustcRegions => No, RustcScalableVector { .. } => Yes, - RustcShouldNotBeCalledOnConstItems => Yes, RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate RustcSkipDuringMethodDispatch { .. } => No, RustcSpecializationTrait => No, @@ -274,6 +274,7 @@ impl AttributeKind { }, LintAsPtr => false, LintNeverReturnsNullPtr => false, + LintShouldNotBeCalledOnConstItems => false, LoopMatch(..) => false, MacroEscape => false, MacroExport { .. } => false, @@ -400,7 +401,7 @@ impl AttributeKind { RustcReallocator => false, RustcRegions => false, RustcScalableVector { .. } => false, - RustcShouldNotBeCalledOnConstItems => false, + RustcSimdMonomorphizeLaneLimit(..) => false, RustcSkipDuringMethodDispatch { .. } => false, RustcSpecializationTrait => false, diff --git a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs index 725e458c99c5e..416f0386c52e2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs +++ b/compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs @@ -69,15 +69,15 @@ impl NoArgsAttributeParser for RustcPassByValueParser { const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcPassByValue; } -pub(crate) struct RustcShouldNotBeCalledOnConstItemsParser; -impl NoArgsAttributeParser for RustcShouldNotBeCalledOnConstItemsParser { - const PATH: &[Symbol] = &[sym::rustc_should_not_be_called_on_const_items]; +pub(crate) struct LintShouldNotBeCalledOnConstItemsParser; +impl NoArgsAttributeParser for LintShouldNotBeCalledOnConstItemsParser { + const PATH: &[Symbol] = &[sym::lint, sym::should_not_be_called_on_const_items]; const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[ Allow(Target::Method(MethodKind::Inherent)), Allow(Target::Method(MethodKind::TraitImpl)), ]); const STABILITY: AttributeStability = unstable!(rustc_attrs); - const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcShouldNotBeCalledOnConstItems; + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::LintShouldNotBeCalledOnConstItems; } pub(crate) struct AutomaticallyDerivedParser; diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 4ddc15d4eccf2..11500c1c97f26 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -273,6 +273,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, @@ -350,7 +351,6 @@ attribute_parsers!( Single>, Single>, Single>, - Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index c063e36c66c50..9f3e0b3e944e2 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -346,7 +346,6 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ // Internal attributes, Misc: // ========================================================================== sym::lang, - sym::rustc_should_not_be_called_on_const_items, sym::rustc_pass_by_value, sym::rustc_no_implicit_autorefs, sym::rustc_coherence_is_core, diff --git a/compiler/rustc_lint/src/interior_mutable_consts.rs b/compiler/rustc_lint/src/interior_mutable_consts.rs index 4d0557d5e9b54..f006979ab50bc 100644 --- a/compiler/rustc_lint/src/interior_mutable_consts.rs +++ b/compiler/rustc_lint/src/interior_mutable_consts.rs @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for InteriorMutableConsts { // Let's do the attribute check after the other checks for perf reasons && find_attr!( cx.tcx, method_did, - RustcShouldNotBeCalledOnConstItems + LintShouldNotBeCalledOnConstItems ) && let Some(method_name) = cx.tcx.opt_item_ident(method_did) && let Some(const_name) = cx.tcx.opt_item_ident(const_did) diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index b947007b50135..824dee98adb0d 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -269,6 +269,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::LinkSection { .. } => (), AttributeKind::LintAsPtr => (), AttributeKind::LintNeverReturnsNullPtr => (), + AttributeKind::LintShouldNotBeCalledOnConstItems => (), AttributeKind::LoopMatch(..) => (), AttributeKind::MacroEscape => (), AttributeKind::MacroExport { .. } => (), @@ -384,7 +385,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::RustcReallocator => (), AttributeKind::RustcRegions => (), AttributeKind::RustcScalableVector { .. } => (), - AttributeKind::RustcShouldNotBeCalledOnConstItems => (), AttributeKind::RustcSimdMonomorphizeLaneLimit(..) => (), AttributeKind::RustcSkipDuringMethodDispatch { .. } => (), AttributeKind::RustcSpecializationTrait => (), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index c1a4e7a2e5e49..20d71f2623de4 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1902,7 +1902,6 @@ symbols! { rustc_reallocator, rustc_regions, rustc_scalable_vector, - rustc_should_not_be_called_on_const_items, rustc_simd_monomorphize_lane_limit, rustc_skip_during_method_dispatch, rustc_specialization_trait, @@ -1954,6 +1953,7 @@ symbols! { shl, shl_assign, shorter_tail_lifetimes, + should_not_be_called_on_const_items, should_panic, show, shr, diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index c6e08e2bf5261..fa3837177fe0f 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -432,7 +432,7 @@ impl Cell { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn set(&self, val: T) where T: [const] Destruct, @@ -464,7 +464,7 @@ impl Cell { /// ``` #[inline] #[stable(feature = "move_cell", since = "1.17.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn swap(&self, other: &Self) { // This function documents that it *will* panic, and intrinsics::is_nonoverlapping doesn't // do the check in const, so trying to use it here would be inviting unnecessary fragility. @@ -509,7 +509,7 @@ impl Cell { #[stable(feature = "move_cell", since = "1.17.0")] #[rustc_const_stable(feature = "const_cell", since = "1.88.0")] #[rustc_confusables("swap")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn replace(&self, val: T) -> T { // SAFETY: This can cause data races if called from a separate thread, // but `Cell` is `!Sync` so this won't happen. @@ -551,7 +551,7 @@ impl Cell { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_stable(feature = "const_cell", since = "1.88.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn get(&self) -> T { // SAFETY: This can cause data races if called from a separate thread, // but `Cell` is `!Sync` so this won't happen. @@ -572,7 +572,7 @@ impl Cell { #[inline] #[stable(feature = "cell_update", since = "1.88.0")] #[rustc_const_unstable(feature = "const_cell_traits", issue = "147787")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn update(&self, f: impl [const] FnOnce(T) -> T) where // FIXME(const-hack): `Copy` should imply `const Destruct` @@ -1024,7 +1024,7 @@ impl RefCell { #[track_caller] #[rustc_confusables("swap")] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn replace(&self, t: T) -> T { mem::replace(&mut self.borrow_mut(), t) } @@ -1048,7 +1048,7 @@ impl RefCell { #[inline] #[stable(feature = "refcell_replace_swap", since = "1.35.0")] #[track_caller] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn replace_with T>(&self, f: F) -> T { let mut_borrow = &mut *self.borrow_mut(); let replacement = f(mut_borrow); @@ -1078,7 +1078,7 @@ impl RefCell { #[inline] #[stable(feature = "refcell_swap", since = "1.24.0")] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn swap(&self, other: &Self) { mem::swap(&mut *self.borrow_mut(), &mut *other.borrow_mut()) } @@ -1120,7 +1120,7 @@ impl RefCell { #[inline] #[track_caller] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn borrow(&self) -> Ref<'_, T> { match self.try_borrow() { Ok(b) => b, @@ -1157,7 +1157,7 @@ impl RefCell { #[inline] #[cfg_attr(feature = "debug_refcell", track_caller)] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn try_borrow(&self) -> Result, BorrowError> { match BorrowRef::new(&self.borrow) { Some(b) => { @@ -1220,7 +1220,7 @@ impl RefCell { #[inline] #[track_caller] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn borrow_mut(&self) -> RefMut<'_, T> { match self.try_borrow_mut() { Ok(b) => b, @@ -1254,7 +1254,7 @@ impl RefCell { #[inline] #[cfg_attr(feature = "debug_refcell", track_caller)] #[rustc_const_unstable(feature = "const_ref_cell", issue = "137844")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn try_borrow_mut(&self) -> Result, BorrowMutError> { match BorrowRefMut::new(&self.borrow) { Some(b) => { @@ -2378,7 +2378,7 @@ impl UnsafeCell { #[inline] #[stable(feature = "unsafe_cell_access", since = "1.100.0")] #[rustc_const_stable(feature = "unsafe_cell_access", since = "1.100.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const unsafe fn replace(&self, value: T) -> T { // SAFETY: pointer comes from `&self` so naturally satisfies invariants. unsafe { ptr::replace(self.get(), value) } @@ -2430,7 +2430,7 @@ impl UnsafeCell { #[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")] #[lint::as_ptr] #[lint::never_returns_null_ptr] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn get(&self) -> *mut T { // We can just cast the pointer from `UnsafeCell` to `T` because of // #[repr(transparent)]. @@ -2520,7 +2520,7 @@ impl UnsafeCell { #[inline] #[stable(feature = "unsafe_cell_access", since = "1.100.0")] #[rustc_const_stable(feature = "unsafe_cell_access", since = "1.100.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const unsafe fn as_ref_unchecked(&self) -> &T { // SAFETY: pointer comes from `&self` so naturally satisfies ptr-to-ref invariants. unsafe { self.get().as_ref_unchecked() } @@ -2549,7 +2549,7 @@ impl UnsafeCell { #[stable(feature = "unsafe_cell_access", since = "1.100.0")] #[rustc_const_stable(feature = "unsafe_cell_access", since = "1.100.0")] #[allow(clippy::mut_from_ref)] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const unsafe fn as_mut_unchecked(&self) -> &mut T { // SAFETY: pointer comes from `&self` so naturally satisfies ptr-to-ref invariants. unsafe { self.get().as_mut_unchecked() } @@ -2637,7 +2637,7 @@ impl SyncUnsafeCell { #[inline] #[lint::as_ptr] #[lint::never_returns_null_ptr] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn get(&self) -> *mut T { self.value.get() } diff --git a/library/core/src/cell/covariant_unsafe_cell.rs b/library/core/src/cell/covariant_unsafe_cell.rs index 0da207137afd0..e88bcef61da2a 100644 --- a/library/core/src/cell/covariant_unsafe_cell.rs +++ b/library/core/src/cell/covariant_unsafe_cell.rs @@ -84,7 +84,7 @@ impl CovariantUnsafeCell { /// ``` #[inline(always)] #[lint::as_ptr] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] #[unstable(feature = "covariant_unsafe_cell", issue = "159735")] #[rustc_const_unstable(feature = "covariant_unsafe_cell", issue = "159735")] pub const fn get(&self) -> NonNull { diff --git a/library/core/src/cell/lazy.rs b/library/core/src/cell/lazy.rs index ba32fff2284fd..854a1ea5c17b4 100644 --- a/library/core/src/cell/lazy.rs +++ b/library/core/src/cell/lazy.rs @@ -134,7 +134,7 @@ impl T> LazyCell { /// ``` #[inline] #[stable(feature = "lazy_cell", since = "1.80.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn force(this: &LazyCell) -> &T { // SAFETY: // This invalidates any mutable references to the data. The resulting diff --git a/library/core/src/cell/once.rs b/library/core/src/cell/once.rs index 01ba604e67949..f1468065512f2 100644 --- a/library/core/src/cell/once.rs +++ b/library/core/src/cell/once.rs @@ -113,7 +113,7 @@ impl OnceCell { /// ``` #[inline] #[stable(feature = "once_cell", since = "1.70.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn set(&self, value: T) -> Result<(), T> { match self.try_insert(value) { Ok(_) => Ok(()), @@ -146,7 +146,7 @@ impl OnceCell { /// ``` #[inline] #[unstable(feature = "once_cell_try_insert", issue = "116693")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_insert(&self, value: T) -> Result<&T, (&T, T)> { if let Some(old) = self.get() { return Err((old, value)); @@ -184,7 +184,7 @@ impl OnceCell { /// ``` #[inline] #[stable(feature = "once_cell", since = "1.70.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn get_or_init(&self, f: F) -> &T where F: FnOnce() -> T, @@ -259,7 +259,7 @@ impl OnceCell { /// assert_eq!(cell.get(), Some(&92)) /// ``` #[unstable(feature = "once_cell_try", issue = "109737")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn get_or_try_init(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result, diff --git a/library/core/src/sync/atomic.rs b/library/core/src/sync/atomic.rs index 0925659a028ff..d388c9d6cd142 100644 --- a/library/core/src/sync/atomic.rs +++ b/library/core/src/sync/atomic.rs @@ -831,7 +831,7 @@ impl AtomicBool { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn store(&self, val: bool, order: Ordering) { // SAFETY: any data races are prevented by atomic intrinsics and the raw // pointer passed in is valid because we got it from a reference. @@ -865,7 +865,7 @@ impl AtomicBool { #[unstable(feature = "atomic_volatile", issue = "158947")] #[rustc_const_unstable(feature = "atomic_volatile", issue = "158947")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const unsafe fn store_volatile(self: *const Self, val: bool, order: Ordering) { // SAFETY: follows from our own safety requirements. unsafe { @@ -898,7 +898,7 @@ impl AtomicBool { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn swap(&self, val: bool, order: Ordering) -> bool { if EMULATE_ATOMIC_BOOL { if val { self.fetch_or(true, order) } else { self.fetch_and(false, order) } @@ -967,7 +967,7 @@ impl AtomicBool { )] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn compare_and_swap(&self, current: bool, new: bool, order: Ordering) -> bool { match self.compare_exchange(current, new, order, strongest_failure_ordering(order)) { Ok(x) => x, @@ -1030,7 +1030,7 @@ impl AtomicBool { #[doc(alias = "compare_and_swap")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn compare_exchange( &self, current: bool, @@ -1133,7 +1133,7 @@ impl AtomicBool { #[doc(alias = "compare_and_swap")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn compare_exchange_weak( &self, current: bool, @@ -1197,7 +1197,7 @@ impl AtomicBool { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_and(&self, val: bool, order: Ordering) -> bool { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_and(self.v.get().cast::(), val as u8, order) != 0 } @@ -1241,7 +1241,7 @@ impl AtomicBool { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_nand(&self, val: bool, order: Ordering) -> bool { // We can't use atomic_nand here because it can result in a bool with // an invalid value. This happens because the atomic operation is done @@ -1295,7 +1295,7 @@ impl AtomicBool { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_or(&self, val: bool, order: Ordering) -> bool { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_or(self.v.get().cast::(), val as u8, order) != 0 } @@ -1338,7 +1338,7 @@ impl AtomicBool { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_xor(&self, val: bool, order: Ordering) -> bool { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_xor(self.v.get().cast::(), val as u8, order) != 0 } @@ -1377,7 +1377,7 @@ impl AtomicBool { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_not(&self, order: Ordering) -> bool { self.fetch_xor(true, order) } @@ -1416,7 +1416,7 @@ impl AtomicBool { #[stable(feature = "atomic_as_ptr", since = "1.70.0")] #[rustc_const_stable(feature = "atomic_as_ptr", since = "1.70.0")] #[lint::never_returns_null_ptr] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn as_ptr(&self) -> *mut bool { self.v.get().cast() } @@ -1426,7 +1426,7 @@ impl AtomicBool { #[stable(feature = "atomic_fetch_update", since = "1.53.0")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] #[deprecated( since = "1.99.0", note = "renamed to `try_update` for consistency", @@ -1495,7 +1495,7 @@ impl AtomicBool { #[stable(feature = "atomic_try_update", since = "1.95.0")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_update( &self, set_order: Ordering, @@ -1558,7 +1558,7 @@ impl AtomicBool { #[stable(feature = "atomic_try_update", since = "1.95.0")] #[cfg(target_has_atomic = "8")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn update( &self, set_order: Ordering, @@ -1946,7 +1946,7 @@ impl AtomicPtr { #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn store(&self, ptr: *mut T, order: Ordering) { // SAFETY: data races are prevented by atomic intrinsics. unsafe { @@ -2007,7 +2007,7 @@ impl AtomicPtr { #[unstable(feature = "atomic_volatile", issue = "158947")] #[rustc_const_unstable(feature = "atomic_volatile", issue = "158947")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const unsafe fn store_volatile(self: *const Self, ptr: *mut T, order: Ordering) { // SAFETY: follows from our own safety requirements. unsafe { @@ -2042,7 +2042,7 @@ impl AtomicPtr { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn swap(&self, ptr: *mut T, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_swap(self.as_ptr(), ptr, order) } @@ -2105,7 +2105,7 @@ impl AtomicPtr { )] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn compare_and_swap(&self, current: *mut T, new: *mut T, order: Ordering) -> *mut T { match self.compare_exchange(current, new, order, strongest_failure_ordering(order)) { Ok(x) => x, @@ -2160,7 +2160,7 @@ impl AtomicPtr { #[stable(feature = "extended_compare_and_swap", since = "1.10.0")] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn compare_exchange( &self, current: *mut T, @@ -2224,7 +2224,7 @@ impl AtomicPtr { #[stable(feature = "extended_compare_and_swap", since = "1.10.0")] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn compare_exchange_weak( &self, current: *mut T, @@ -2244,7 +2244,7 @@ impl AtomicPtr { #[stable(feature = "atomic_fetch_update", since = "1.53.0")] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] #[deprecated( since = "1.99.0", note = "renamed to `try_update` for consistency", @@ -2322,7 +2322,7 @@ impl AtomicPtr { #[stable(feature = "atomic_try_update", since = "1.95.0")] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_update( &self, set_order: Ordering, @@ -2390,7 +2390,7 @@ impl AtomicPtr { #[stable(feature = "atomic_try_update", since = "1.95.0")] #[cfg(target_has_atomic = "ptr")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn update( &self, set_order: Ordering, @@ -2442,7 +2442,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_ptr_add(&self, val: usize, order: Ordering) -> *mut T { self.fetch_byte_add(val.wrapping_mul(size_of::()), order) } @@ -2487,7 +2487,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_ptr_sub(&self, val: usize, order: Ordering) -> *mut T { self.fetch_byte_sub(val.wrapping_mul(size_of::()), order) } @@ -2522,7 +2522,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_byte_add(&self, val: usize, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_add(self.as_ptr(), val, order).cast() } @@ -2558,7 +2558,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_byte_sub(&self, val: usize, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_sub(self.as_ptr(), val, order).cast() } @@ -2609,7 +2609,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_or(&self, val: usize, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_or(self.as_ptr(), val, order).cast() } @@ -2659,7 +2659,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_and(&self, val: usize, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_and(self.as_ptr(), val, order).cast() } @@ -2707,7 +2707,7 @@ impl AtomicPtr { #[cfg(target_has_atomic = "ptr")] #[stable(feature = "strict_provenance_atomic_ptr", since = "1.91.0")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn fetch_xor(&self, val: usize, order: Ordering) -> *mut T { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_xor(self.as_ptr(), val, order).cast() } @@ -3216,7 +3216,7 @@ macro_rules! atomic_int { #[$stable] #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn store(&self, val: $int_type, order: Ordering) { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_store::<_, /* VOLATILE */ false>(self.as_ptr(), val, order); } @@ -3261,7 +3261,7 @@ macro_rules! atomic_int { #[unstable(feature = "atomic_volatile", issue = "158947")] #[rustc_const_unstable(feature = "atomic_volatile", issue = "158947")] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const unsafe fn store_volatile(self: *const Self, val: $int_type, order: Ordering) { // SAFETY: follows from our own safety requirements. unsafe { @@ -3294,7 +3294,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn swap(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_swap(self.as_ptr(), val, order) } @@ -3361,7 +3361,7 @@ macro_rules! atomic_int { ] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn compare_and_swap(&self, current: $int_type, new: $int_type, @@ -3432,7 +3432,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn compare_exchange(&self, current: $int_type, new: $int_type, @@ -3498,7 +3498,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn compare_exchange_weak(&self, current: $int_type, new: $int_type, @@ -3537,7 +3537,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_add(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_add(self.as_ptr(), val, order) } @@ -3570,7 +3570,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_sub(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_sub(self.as_ptr(), val, order) } @@ -3606,7 +3606,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_and(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_and(self.as_ptr(), val, order) } @@ -3642,7 +3642,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_nand(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_nand(self.as_ptr(), val, order) } @@ -3678,7 +3678,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_or(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_or(self.as_ptr(), val, order) } @@ -3714,7 +3714,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_xor(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { atomic_xor(self.as_ptr(), val, order) } @@ -3727,7 +3727,7 @@ macro_rules! atomic_int { #[stable(feature = "no_more_cas", since = "1.45.0")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] #[deprecated( since = "1.99.0", note = "renamed to `try_update` for consistency", @@ -3793,7 +3793,7 @@ macro_rules! atomic_int { #[stable(feature = "atomic_try_update", since = "1.95.0")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_update( &self, set_order: Ordering, @@ -3860,7 +3860,7 @@ macro_rules! atomic_int { #[stable(feature = "atomic_try_update", since = "1.95.0")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn update( &self, set_order: Ordering, @@ -3918,7 +3918,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_max(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { $max_fn(self.as_ptr(), val, order) } @@ -3968,7 +3968,7 @@ macro_rules! atomic_int { #[rustc_const_unstable(feature = "const_atomic", issue = "160078")] #[cfg(any($cfg_cas, doc))] #[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub const fn fetch_min(&self, val: $int_type, order: Ordering) -> $int_type { // SAFETY: data races are prevented by atomic intrinsics. unsafe { $min_fn(self.as_ptr(), val, order) } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index baa9f8d769c82..9f77f20acce37 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -376,6 +376,7 @@ #![feature(ptr_mask)] #![feature(random)] #![feature(raw_os_error_ty)] +#![feature(register_tool)] #![feature(seek_io_take_position)] #![feature(seek_stream_len)] #![feature(share_trait)] @@ -451,6 +452,10 @@ link = "https://github.com/rust-lang/rust/issues/29599#issuecomment-2986866250", since = "1.90.0" )] +// tidy-alphabetical-start +#![register_tool(lint)] +// tidy-alphabetical-end +// // The Rust prelude // The compiler expects the prelude definition to be defined before its use statement. diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index d1e5fd0af66f1..7d96e65a3860f 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -237,7 +237,7 @@ impl T> LazyLock { /// ``` #[inline] #[stable(feature = "lazy_cell", since = "1.80.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn force(this: &LazyLock) -> &T { this.once.call_once_force(|state| { if state.is_poisoned() { @@ -307,7 +307,7 @@ impl LazyLock { /// ``` #[inline] #[stable(feature = "lazy_get", since = "1.94.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn get(this: &LazyLock) -> Option<&T> { if this.once.is_completed() { // SAFETY: diff --git a/library/std/src/sync/once.rs b/library/std/src/sync/once.rs index 9b7dd3b78eac7..6834b9b486371 100644 --- a/library/std/src/sync/once.rs +++ b/library/std/src/sync/once.rs @@ -153,7 +153,7 @@ impl Once { #[inline] #[stable(feature = "rust1", since = "1.0.0")] #[track_caller] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn call_once(&self, f: F) where F: FnOnce(), @@ -213,7 +213,7 @@ impl Once { /// ``` #[inline] #[stable(feature = "once_poison", since = "1.51.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn call_once_force(&self, f: F) where F: FnOnce(&OnceState), @@ -299,7 +299,7 @@ impl Once { /// if this behavior is not desired. #[inline] #[stable(feature = "once_wait", since = "1.86.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait(&self) { if !self.inner.is_completed() { self.inner.wait(false); @@ -313,7 +313,7 @@ impl Once { /// becomes completed, unlike [`Once::wait()`], which panics in this case. #[inline] #[stable(feature = "once_wait", since = "1.86.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait_force(&self) { if !self.inner.is_completed() { self.inner.wait(true); diff --git a/library/std/src/sync/once_lock.rs b/library/std/src/sync/once_lock.rs index e8e8f869dd038..b1af66e9d6e5c 100644 --- a/library/std/src/sync/once_lock.rs +++ b/library/std/src/sync/once_lock.rs @@ -180,7 +180,7 @@ impl OnceLock { /// This method never blocks. #[inline] #[stable(feature = "once_cell", since = "1.70.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn get(&self) -> Option<&T> { if self.initialized() { // Safe b/c checked initialized @@ -228,7 +228,7 @@ impl OnceLock { /// ``` #[inline] #[stable(feature = "once_wait", since = "1.86.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait(&self) -> &T { self.once.wait_force(); @@ -263,7 +263,7 @@ impl OnceLock { /// ``` #[inline] #[stable(feature = "once_cell", since = "1.70.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn set(&self, value: T) -> Result<(), T> { match self.try_insert(value) { Ok(_) => Ok(()), @@ -303,7 +303,7 @@ impl OnceLock { /// ``` #[inline] #[unstable(feature = "once_cell_try_insert", issue = "116693")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_insert(&self, value: T) -> Result<&T, (&T, T)> { let mut value = Some(value); let res = self.get_or_init(|| value.take().unwrap()); @@ -342,7 +342,7 @@ impl OnceLock { /// ``` #[inline] #[stable(feature = "once_cell", since = "1.70.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn get_or_init(&self, f: F) -> &T where F: FnOnce() -> T, @@ -423,7 +423,7 @@ impl OnceLock { /// ``` #[inline] #[unstable(feature = "once_cell_try", issue = "109737")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn get_or_try_init(&self, f: F) -> Result<&T, E> where F: FnOnce() -> Result, diff --git a/library/std/src/sync/poison/condvar.rs b/library/std/src/sync/poison/condvar.rs index fa9e1caada59b..68961ced741ea 100644 --- a/library/std/src/sync/poison/condvar.rs +++ b/library/std/src/sync/poison/condvar.rs @@ -121,7 +121,7 @@ impl Condvar { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait<'a, T>(&self, guard: MutexGuard<'a, T>) -> LockResult> { let poisoned = unsafe { let lock = mutex::guard_lock(&guard); @@ -178,7 +178,7 @@ impl Condvar { /// let _guard = cvar.wait_while(lock.lock().unwrap(), |pending| { *pending }).unwrap(); /// ``` #[stable(feature = "wait_until", since = "1.42.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait_while<'a, T, F>( &self, mut guard: MutexGuard<'a, T>, @@ -247,7 +247,7 @@ impl Condvar { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] #[deprecated(since = "1.6.0", note = "replaced by `std::sync::Condvar::wait_timeout`")] pub fn wait_timeout_ms<'a, T>( &self, @@ -319,7 +319,7 @@ impl Condvar { /// } /// ``` #[stable(feature = "wait_timeout", since = "1.5.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait_timeout<'a, T>( &self, guard: MutexGuard<'a, T>, @@ -386,7 +386,7 @@ impl Condvar { /// // access the locked mutex via result.0 /// ``` #[stable(feature = "wait_timeout_until", since = "1.42.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn wait_timeout_while<'a, T, F>( &self, mut guard: MutexGuard<'a, T>, @@ -447,7 +447,7 @@ impl Condvar { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn notify_one(&self) { self.inner.notify_one() } @@ -488,7 +488,7 @@ impl Condvar { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn notify_all(&self) { self.inner.notify_all() } diff --git a/library/std/src/sync/poison/mutex.rs b/library/std/src/sync/poison/mutex.rs index 42c5fcf3e27c0..879329a174224 100644 --- a/library/std/src/sync/poison/mutex.rs +++ b/library/std/src/sync/poison/mutex.rs @@ -401,7 +401,7 @@ impl Mutex { /// assert_eq!(mutex.get_cloned().unwrap(), 11); /// ``` #[unstable(feature = "lock_value_accessors", issue = "133407")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn set(&self, value: T) -> Result<(), PoisonError> { if mem::needs_drop::() { // If the contained value has non-trivial destructor, we @@ -439,7 +439,7 @@ impl Mutex { /// assert_eq!(mutex.get_cloned().unwrap(), 11); /// ``` #[unstable(feature = "lock_value_accessors", issue = "133407")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn replace(&self, value: T) -> LockResult { match self.lock() { Ok(mut guard) => Ok(mem::replace(&mut *guard, value)), @@ -486,7 +486,7 @@ impl Mutex { /// assert_eq!(*mutex.lock().unwrap(), 10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn lock(&self) -> LockResult> { unsafe { self.inner.lock(); @@ -535,7 +535,7 @@ impl Mutex { /// assert_eq!(*mutex.lock().unwrap(), 10); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_lock(&self) -> TryLockResult> { unsafe { if self.inner.try_lock() { @@ -606,7 +606,7 @@ impl Mutex { /// ``` #[inline] #[stable(feature = "mutex_unpoison", since = "1.77.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn clear_poison(&self) { self.poison.clear(); } diff --git a/library/std/src/sync/poison/rwlock.rs b/library/std/src/sync/poison/rwlock.rs index de1fedf88f63a..0dd7db0501d1d 100644 --- a/library/std/src/sync/poison/rwlock.rs +++ b/library/std/src/sync/poison/rwlock.rs @@ -311,7 +311,7 @@ impl RwLock { /// assert_eq!(lock.get_cloned().unwrap(), 11); /// ``` #[unstable(feature = "lock_value_accessors", issue = "133407")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn set(&self, value: T) -> Result<(), PoisonError> { if mem::needs_drop::() { // If the contained value has non-trivial destructor, we @@ -350,7 +350,7 @@ impl RwLock { /// assert_eq!(lock.get_cloned().unwrap(), 11); /// ``` #[unstable(feature = "lock_value_accessors", issue = "133407")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn replace(&self, value: T) -> LockResult { match self.write() { Ok(mut guard) => Ok(mem::replace(&mut *guard, value)), @@ -404,7 +404,7 @@ impl RwLock { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn read(&self) -> LockResult> { unsafe { self.inner.read(); @@ -451,7 +451,7 @@ impl RwLock { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_read(&self) -> TryLockResult> { unsafe { if self.inner.try_read() { @@ -497,7 +497,7 @@ impl RwLock { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn write(&self) -> LockResult> { unsafe { self.inner.write(); @@ -545,7 +545,7 @@ impl RwLock { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_should_not_be_called_on_const_items] + #[lint::should_not_be_called_on_const_items] pub fn try_write(&self) -> TryLockResult> { unsafe { if self.inner.try_write() { diff --git a/tests/ui/lint_helper_namespace/feature_gates.rs b/tests/ui/lint_helper_namespace/feature_gates.rs index d5e1008f89f57..045b75104c68c 100644 --- a/tests/ui/lint_helper_namespace/feature_gates.rs +++ b/tests/ui/lint_helper_namespace/feature_gates.rs @@ -2,8 +2,13 @@ #![feature(register_tool)] #![register_tool(lint)] -#[lint::as_ptr] //~ ERROR use of an internal attribute -#[lint::never_returns_null_ptr] //~ ERROR use of an internal attribute -fn cast(x: &u8) -> *const u8 { - x +struct X; + +impl X { + #[lint::as_ptr] //~ ERROR use of an internal attribute + #[lint::never_returns_null_ptr] //~ ERROR use of an internal attribute + #[lint::should_not_be_called_on_const_items] //~ ERROR use of an internal attribute + fn cast(x: &u8) -> *const u8 { + x + } } diff --git a/tests/ui/lint_helper_namespace/feature_gates.stderr b/tests/ui/lint_helper_namespace/feature_gates.stderr index 0bed2a048ab23..9200a09a93db5 100644 --- a/tests/ui/lint_helper_namespace/feature_gates.stderr +++ b/tests/ui/lint_helper_namespace/feature_gates.stderr @@ -1,21 +1,30 @@ error[E0658]: use of an internal attribute - --> $DIR/feature_gates.rs:5:3 + --> $DIR/feature_gates.rs:8:7 | -LL | #[lint::as_ptr] - | ^^^^^^^^^^^^ +LL | #[lint::as_ptr] + | ^^^^^^^^^^^^ | = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable = note: the `lint::as_ptr` attribute is an internal implementation detail that will never be stable error[E0658]: use of an internal attribute - --> $DIR/feature_gates.rs:6:3 + --> $DIR/feature_gates.rs:9:7 | -LL | #[lint::never_returns_null_ptr] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[lint::never_returns_null_ptr] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable = note: the `lint::never_returns_null_ptr` attribute is an internal implementation detail that will never be stable -error: aborting due to 2 previous errors +error[E0658]: use of an internal attribute + --> $DIR/feature_gates.rs:10:7 + | +LL | #[lint::should_not_be_called_on_const_items] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add `#![feature(rustc_attrs)]` to the crate attributes to enable + = note: the `lint::should_not_be_called_on_const_items` attribute is an internal implementation detail that will never be stable + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. From 1656f72160d2ead9adf9777e72cf2e69e97c3938 Mon Sep 17 00:00:00 2001 From: mejrs <59372212+mejrs@users.noreply.github.com> Date: Fri, 2 Oct 2026 18:32:41 +0200 Subject: [PATCH 4/4] Remove duplicate symbol --- src/tools/clippy/clippy_utils/src/sym.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tools/clippy/clippy_utils/src/sym.rs b/src/tools/clippy/clippy_utils/src/sym.rs index a86603dd545a1..4ad3c23614838 100644 --- a/src/tools/clippy/clippy_utils/src/sym.rs +++ b/src/tools/clippy/clippy_utils/src/sym.rs @@ -142,7 +142,6 @@ generate! { as_mut_ptr, as_mut_slice, as_path, - as_ptr, as_slice, as_str, assert_failed,