Skip to content

Commit f56a313

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

File tree

7 files changed

+48
-43
lines changed

7 files changed

+48
-43
lines changed

compiler/rustc_lint/src/builtin.rs

+9-9
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,
@@ -3008,14 +3008,14 @@ declare_lint! {
30083008
///
30093009
/// Returning a pointer to memory refering to a local variable will always
30103010
/// end up in a dangling pointer after returning.
3011-
pub RETURN_LOCAL_VARIABLE_PTR,
3011+
pub RETURNING_POINTERS_TO_LOCAL_VARIABLES,
30123012
Warn,
30133013
"returning a pointer to stack memory associated with a local variable",
30143014
}
30153015

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

3018-
impl<'tcx> LateLintPass<'tcx> for ReturnLocalVariablePointer {
3018+
impl<'tcx> LateLintPass<'tcx> for ReturningPointersToLocalVariables {
30193019
fn check_fn(
30203020
&mut self,
30213021
cx: &LateContext<'tcx>,
@@ -3061,7 +3061,7 @@ impl<'tcx> LateLintPass<'tcx> for ReturnLocalVariablePointer {
30613061
}
30623062
}
30633063

3064-
impl ReturnLocalVariablePointer {
3064+
impl ReturningPointersToLocalVariables {
30653065
/// Evaluates the return expression of a function and emits a lint if it
30663066
/// returns a pointer to a local variable.
30673067
fn maybe_lint_return_expr<'tcx>(cx: &LateContext<'tcx>, return_expr: &hir::Expr<'tcx>) {
@@ -3078,9 +3078,9 @@ impl ReturnLocalVariablePointer {
30783078
) = addr_expr.kind
30793079
{
30803080
cx.emit_span_lint(
3081-
RETURN_LOCAL_VARIABLE_PTR,
3081+
RETURNING_POINTERS_TO_LOCAL_VARIABLES,
30823082
return_expr.span,
3083-
BuiltinLocalVariablePointerImpl,
3083+
BuiltinReturningPointersToLocalVariables,
30843084
);
30853085
}
30863086
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ pub(crate) enum BuiltinSpecialModuleNameUsed {
533533

534534
#[derive(LintDiagnostic)]
535535
#[diag(lint_builtin_return_local_variable_ptr)]
536-
pub(crate) struct BuiltinLocalVariablePointerImpl;
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 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)