Skip to content

Commit 4e7732c

Browse files
committed
Rename the lint and fix the tests
1 parent e162e89 commit 4e7732c

File tree

8 files changed

+53
-50
lines changed

8 files changed

+53
-50
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ lint_builtin_overridden_symbol_name =
135135
lint_builtin_overridden_symbol_section =
136136
the program's behavior with overridden link sections on items is unpredictable and Rust cannot provide guarantees when you manually override them
137137
138-
lint_builtin_return_local_variable_ptr = returning a pointer to stack memory associated with a local variable
138+
lint_builtin_returning_pointers_to_local_variables = returning a pointer to stack memory associated with a local variable
139139
140140
lint_builtin_special_module_name_used_lib = found module declaration for lib.rs
141141
.note = lib.rs is the root of this crate's library target

compiler/rustc_lint/src/builtin.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ use crate::lints::{
5454
BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives,
5555
BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures,
5656
BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
57-
BuiltinLocalVariablePointerImpl, BuiltinMissingCopyImpl, BuiltinMissingDebugImpl,
58-
BuiltinMissingDoc, BuiltinMutablesTransmutes, BuiltinNoMangleGeneric,
59-
BuiltinNonShorthandFieldPatterns, BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds,
57+
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc, BuiltinMutablesTransmutes,
58+
BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
59+
BuiltinReturningPointersToLocalVariables, BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds,
6060
BuiltinTypeAliasBounds, BuiltinUngatedAsyncFnTrackCaller, BuiltinUnpermittedTypeInit,
6161
BuiltinUnpermittedTypeInitSub, BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures,
6262
BuiltinUnusedDocComment, BuiltinUnusedDocCommentSub, BuiltinWhileTrue, InvalidAsmLabel,
@@ -2987,9 +2987,9 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
29872987
}
29882988

29892989
declare_lint! {
2990-
/// The `return_local_variable_ptr` lint detects when pointer to stack
2991-
/// memory associated with a local variable is returned. That pointer
2992-
/// is immediately dangling.
2990+
/// The `returning_pointers_to_local_variables` lint detects when pointer
2991+
/// to stack memory associated with a local variable is returned. That
2992+
/// pointer is immediately dangling.
29932993
///
29942994
/// ### Example
29952995
///
@@ -3000,22 +3000,20 @@ declare_lint! {
30003000
/// }
30013001
/// ```
30023002
///
3003-
/// This will produce:
3004-
///
30053003
/// {{produces}}
30063004
///
30073005
/// ### Explanation
30083006
///
30093007
/// Returning a pointer to memory refering to a local variable will always
30103008
/// end up in a dangling pointer after returning.
3011-
pub RETURN_LOCAL_VARIABLE_PTR,
3009+
pub RETURNING_POINTERS_TO_LOCAL_VARIABLES,
30123010
Warn,
30133011
"returning a pointer to stack memory associated with a local variable",
30143012
}
30153013

3016-
declare_lint_pass!(ReturnLocalVariablePointer => [RETURN_LOCAL_VARIABLE_PTR]);
3014+
declare_lint_pass!(ReturningPointersToLocalVariables => [RETURNING_POINTERS_TO_LOCAL_VARIABLES]);
30173015

3018-
impl<'tcx> LateLintPass<'tcx> for ReturnLocalVariablePointer {
3016+
impl<'tcx> LateLintPass<'tcx> for ReturningPointersToLocalVariables {
30193017
fn check_fn(
30203018
&mut self,
30213019
cx: &LateContext<'tcx>,
@@ -3061,7 +3059,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnLocalVariablePointer {
30613059
}
30623060
}
30633061

3064-
impl ReturnLocalVariablePointer {
3062+
impl ReturningPointersToLocalVariables {
30653063
/// Evaluates the return expression of a function and emits a lint if it
30663064
/// returns a pointer to a local variable.
30673065
fn maybe_lint_return_expr<'tcx>(cx: &LateContext<'tcx>, return_expr: &hir::Expr<'tcx>) {
@@ -3078,9 +3076,9 @@ impl ReturnLocalVariablePointer {
30783076
) = addr_expr.kind
30793077
{
30803078
cx.emit_span_lint(
3081-
RETURN_LOCAL_VARIABLE_PTR,
3079+
RETURNING_POINTERS_TO_LOCAL_VARIABLES,
30823080
return_expr.span,
3083-
BuiltinLocalVariablePointerImpl,
3081+
BuiltinReturningPointersToLocalVariables,
30843082
);
30853083
}
30863084
}

compiler/rustc_lint/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ late_lint_methods!(
241241
IfLetRescope: IfLetRescope::default(),
242242
StaticMutRefs: StaticMutRefs,
243243
UnqualifiedLocalImports: UnqualifiedLocalImports,
244-
ReturnLocalVariablePointer : ReturnLocalVariablePointer,
244+
ReturningPointersToLocalVariables : ReturningPointersToLocalVariables,
245245
]
246246
]
247247
);

compiler/rustc_lint/src/lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,8 @@ pub(crate) enum BuiltinSpecialModuleNameUsed {
532532
}
533533

534534
#[derive(LintDiagnostic)]
535-
#[diag(lint_builtin_return_local_variable_ptr)]
536-
pub(crate) struct BuiltinLocalVariablePointerImpl;
535+
#[diag(lint_builtin_returning_pointers_to_local_variables)]
536+
pub(crate) struct BuiltinReturningPointersToLocalVariables;
537537

538538
// deref_into_dyn_supertrait.rs
539539
#[derive(LintDiagnostic)]

src/tools/miri/tests/fail/validity/dangling_ref3.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Make sure we catch this even without Stacked Borrows
22
//@compile-flags: -Zmiri-disable-stacked-borrows
3+
#![allow(returning_pointers_to_local_variables)]
34
use std::mem;
45

56
fn dangling() -> *const u8 {

tests/ui/lint/lint-return-local-variable-ptr.rs

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ check-pass
2+
3+
#![warn(returning_pointers_to_local_variables)]
4+
5+
fn foo() -> *const u32 {
6+
let empty = 42u32;
7+
return &empty as *const _;
8+
//~^ WARN returning a pointer to stack memory associated with a local variable
9+
}
10+
11+
fn bar() -> *const u32 {
12+
let empty = 42u32;
13+
&empty as *const _
14+
//~^ WARN returning a pointer to stack memory associated with a local variable
15+
}
16+
17+
fn baz() -> *const u32 {
18+
let empty = 42u32;
19+
return &empty;
20+
//~^ WARN returning a pointer to stack memory associated with a local variable
21+
}
22+
23+
fn faa() -> *const u32 {
24+
let empty = 42u32;
25+
&empty
26+
//~^ WARN returning a pointer to stack memory associated with a local variable
27+
}
28+
29+
fn main() {}

tests/ui/lint/lint-return-local-variable-ptr.stderr renamed to tests/ui/lint/lint-returning-pointers-to-local-variables.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
warning: returning a pointer to stack memory associated with a local variable
2-
--> $DIR/lint-return-local-variable-ptr.rs:7:12
2+
--> $DIR/lint-returning-pointers-to-local-variables.rs:7:12
33
|
44
LL | return &empty as *const _;
55
| ^^^^^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> $DIR/lint-return-local-variable-ptr.rs:3:9
8+
--> $DIR/lint-returning-pointers-to-local-variables.rs:3:9
99
|
10-
LL | #![warn(return_local_variable_ptr)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
10+
LL | #![warn(returning_pointers_to_local_variables)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
warning: returning a pointer to stack memory associated with a local variable
14-
--> $DIR/lint-return-local-variable-ptr.rs:12:5
14+
--> $DIR/lint-returning-pointers-to-local-variables.rs:13:5
1515
|
1616
LL | &empty as *const _
1717
| ^^^^^^^^^^^^^^^^^^
1818

1919
warning: returning a pointer to stack memory associated with a local variable
20-
--> $DIR/lint-return-local-variable-ptr.rs:17:12
20+
--> $DIR/lint-returning-pointers-to-local-variables.rs:19:12
2121
|
2222
LL | return &empty;
2323
| ^^^^^^
2424

2525
warning: returning a pointer to stack memory associated with a local variable
26-
--> $DIR/lint-return-local-variable-ptr.rs:22:5
26+
--> $DIR/lint-returning-pointers-to-local-variables.rs:25:5
2727
|
2828
LL | &empty
2929
| ^^^^^^

0 commit comments

Comments
 (0)