Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a60756a

Browse files
committedJun 12, 2024
Remove the box_pointers lint.
As the comment says, this lint "is mostly historical, and not particularly useful". It's not worth keeping it around.
1 parent ebcb862 commit a60756a

File tree

9 files changed

+11
-125
lines changed

9 files changed

+11
-125
lines changed
 

‎compiler/rustc_lint/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ lint_builtin_asm_labels = avoid using named labels in inline assembly
5555
.help = only local labels of the form `<number>:` should be used in inline asm
5656
.note = see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information
5757
58-
lint_builtin_box_pointers = type uses owned (Box type) pointers: {$ty}
59-
6058
lint_builtin_clashing_extern_diff_name = `{$this}` redeclares `{$orig}` with a different signature
6159
.previous_decl_label = `{$orig}` previously declared here
6260
.mismatch_label = this signature doesn't match the previous declaration

‎compiler/rustc_lint/src/builtin.rs

+3-79
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ use crate::fluent_generated as fluent;
2424
use crate::{
2525
errors::BuiltinEllipsisInclusiveRangePatterns,
2626
lints::{
27-
BuiltinAnonymousParams, BuiltinBoxPointers, BuiltinConstNoMangle,
28-
BuiltinDeprecatedAttrLink, BuiltinDeprecatedAttrLinkSuggestion, BuiltinDeprecatedAttrUsed,
29-
BuiltinDerefNullptr, BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives,
27+
BuiltinAnonymousParams, BuiltinConstNoMangle, BuiltinDeprecatedAttrLink,
28+
BuiltinDeprecatedAttrLinkSuggestion, BuiltinDeprecatedAttrUsed, BuiltinDerefNullptr,
29+
BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives,
3030
BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures,
3131
BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
3232
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc,
@@ -56,7 +56,6 @@ use rustc_middle::bug;
5656
use rustc_middle::lint::in_external_macro;
5757
use rustc_middle::ty::layout::LayoutOf;
5858
use rustc_middle::ty::print::with_no_trimmed_paths;
59-
use rustc_middle::ty::GenericArgKind;
6059
use rustc_middle::ty::TypeVisitableExt;
6160
use rustc_middle::ty::Upcast;
6261
use rustc_middle::ty::{self, Ty, TyCtxt, VariantDef};
@@ -134,80 +133,6 @@ impl EarlyLintPass for WhileTrue {
134133
}
135134
}
136135

137-
declare_lint! {
138-
/// The `box_pointers` lints use of the Box type.
139-
///
140-
/// ### Example
141-
///
142-
/// ```rust,compile_fail
143-
/// #![deny(box_pointers)]
144-
/// struct Foo {
145-
/// x: Box<i32>,
146-
/// }
147-
/// ```
148-
///
149-
/// {{produces}}
150-
///
151-
/// ### Explanation
152-
///
153-
/// This lint is mostly historical, and not particularly useful. `Box<T>`
154-
/// used to be built into the language, and the only way to do heap
155-
/// allocation. Today's Rust can call into other allocators, etc.
156-
BOX_POINTERS,
157-
Allow,
158-
"use of owned (Box type) heap memory"
159-
}
160-
161-
declare_lint_pass!(BoxPointers => [BOX_POINTERS]);
162-
163-
impl BoxPointers {
164-
fn check_heap_type(&self, cx: &LateContext<'_>, span: Span, ty: Ty<'_>) {
165-
for leaf in ty.walk() {
166-
if let GenericArgKind::Type(leaf_ty) = leaf.unpack()
167-
&& leaf_ty.is_box()
168-
{
169-
cx.emit_span_lint(BOX_POINTERS, span, BuiltinBoxPointers { ty });
170-
}
171-
}
172-
}
173-
}
174-
175-
impl<'tcx> LateLintPass<'tcx> for BoxPointers {
176-
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
177-
match it.kind {
178-
hir::ItemKind::Fn(..)
179-
| hir::ItemKind::TyAlias(..)
180-
| hir::ItemKind::Enum(..)
181-
| hir::ItemKind::Struct(..)
182-
| hir::ItemKind::Union(..) => self.check_heap_type(
183-
cx,
184-
it.span,
185-
cx.tcx.type_of(it.owner_id).instantiate_identity(),
186-
),
187-
_ => (),
188-
}
189-
190-
// If it's a struct, we also have to check the fields' types
191-
match it.kind {
192-
hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => {
193-
for field in struct_def.fields() {
194-
self.check_heap_type(
195-
cx,
196-
field.span,
197-
cx.tcx.type_of(field.def_id).instantiate_identity(),
198-
);
199-
}
200-
}
201-
_ => (),
202-
}
203-
}
204-
205-
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
206-
let ty = cx.typeck_results().node_type(e.hir_id);
207-
self.check_heap_type(cx, e.span, ty);
208-
}
209-
}
210-
211136
declare_lint! {
212137
/// The `non_shorthand_field_patterns` lint detects using `Struct { x: x }`
213138
/// instead of `Struct { x }` in a pattern.
@@ -1640,7 +1565,6 @@ declare_lint_pass!(
16401565
/// which are used by other parts of the compiler.
16411566
SoftLints => [
16421567
WHILE_TRUE,
1643-
BOX_POINTERS,
16441568
NON_SHORTHAND_FIELD_PATTERNS,
16451569
UNSAFE_CODE,
16461570
MISSING_DOCS,

‎compiler/rustc_lint/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ late_lint_methods!(
185185
ImproperCTypesDefinitions: ImproperCTypesDefinitions,
186186
InvalidFromUtf8: InvalidFromUtf8,
187187
VariantSizeDifferences: VariantSizeDifferences,
188-
BoxPointers: BoxPointers,
189188
PathStatements: PathStatements,
190189
LetUnderscore: LetUnderscore,
191190
InvalidReferenceCasting: InvalidReferenceCasting,
@@ -549,6 +548,10 @@ fn register_builtins(store: &mut LintStore) {
549548
"converted into hard error, see RFC #3535 \
550549
<https://rust-lang.github.io/rfcs/3535-constants-in-patterns.html> for more information",
551550
);
551+
store.register_removed(
552+
"box_pointers",
553+
"it does not detect other kinds of allocations, and existed only for historical reasons",
554+
);
552555
}
553556

554557
fn register_internals(store: &mut LintStore) {

‎compiler/rustc_lint/src/lints.rs

-6
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,6 @@ pub struct BuiltinWhileTrue {
6666
pub replace: String,
6767
}
6868

69-
#[derive(LintDiagnostic)]
70-
#[diag(lint_builtin_box_pointers)]
71-
pub struct BuiltinBoxPointers<'a> {
72-
pub ty: Ty<'a>,
73-
}
74-
7569
#[derive(LintDiagnostic)]
7670
#[diag(lint_builtin_non_shorthand_field_patterns)]
7771
pub struct BuiltinNonShorthandFieldPatterns {

‎src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub const DEFAULT_LINTS: &[Lint] = &[
4949
label: "bindings_with_variant_name",
5050
description: r##"detects pattern bindings with the same name as one of the matched variants"##,
5151
},
52-
Lint { label: "box_pointers", description: r##"use of owned (Box type) heap memory"## },
5352
Lint {
5453
label: "break_with_label_and_loop",
5554
description: r##"`break` expression with label and unlabeled loop as value expression"##,

‎tests/ui/lint/lint-owned-heap-memory.rs

-12
This file was deleted.

‎tests/ui/lint/lint-owned-heap-memory.stderr

-20
This file was deleted.

‎tests/ui/lint/reasons-erroneous.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
1212
//~^ ERROR malformed lint attribute
1313
//~| NOTE bad attribute argument
14-
#![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
14+
#![warn(unsafe_code, blerp = "or in league with robbers have reversed the signposts")]
1515
//~^ ERROR malformed lint attribute
1616
//~| NOTE bad attribute argument
1717
#![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]

‎tests/ui/lint/reasons-erroneous.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides thei
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
1818

1919
error[E0452]: malformed lint attribute input
20-
--> $DIR/reasons-erroneous.rs:14:23
20+
--> $DIR/reasons-erroneous.rs:14:22
2121
|
22-
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
22+
LL | #![warn(unsafe_code, blerp = "or in league with robbers have reversed the signposts")]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
2424

2525
error[E0452]: malformed lint attribute input
2626
--> $DIR/reasons-erroneous.rs:17:36

0 commit comments

Comments
 (0)
Failed to load comments.