Skip to content

Commit 9611d97

Browse files
committed
temporary_as_ptr: rename to instantly_dangling_pointer
1 parent 1575165 commit 9611d97

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ lint_incomplete_include =
405405
406406
lint_inner_macro_attribute_unstable = inner macro attributes are unstable
407407
408+
lint_instantly_dangling = this pointer will immediately dangle
409+
.ptr_label = this pointer will be invalid
410+
.temporary_label = this `{$ty}` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
411+
.note = pointers do not have a lifetime; when calling `{$method}` the `{$ty}` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
412+
.help = for more information, see https://doc.rust-lang.org/reference/destructors.html
413+
408414
lint_invalid_asm_label_binary = avoid using labels containing only the digits `0` and `1` in inline assembly
409415
.label = use a different label that doesn't start with `0` or `1`
410416
.help = start numbering with `2` instead
@@ -752,12 +758,6 @@ lint_suspicious_double_ref_clone =
752758
lint_suspicious_double_ref_deref =
753759
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
754760
755-
lint_temporary_as_ptr = getting the inner pointer of a temporary `{$ty}`
756-
.as_ptr_label = this pointer will be invalid
757-
.temporary_label = this `{$ty}` is deallocated at the end of the statement, bind it to a variable to extend its lifetime
758-
.note = pointers do not have a lifetime; when calling `{$method}` the `{$ty}` will be deallocated at the end of the statement because nothing is referencing it as far as the type system is concerned
759-
.help = for more information, see https://doc.rust-lang.org/reference/destructors.html
760-
761761
lint_trailing_semi_macro = trailing semicolon in macro used in expression position
762762
.note1 = macro invocations at the end of a block are treated as expressions
763763
.note2 = to ignore the value produced by the macro, add a semicolon after the invocation of `{$name}`

compiler/rustc_lint/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ late_lint_methods!(
223223
UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller,
224224
ShadowedIntoIter: ShadowedIntoIter,
225225
DropTraitConstraints: DropTraitConstraints,
226-
TemporaryCStringAsPtr: TemporaryCStringAsPtr,
226+
InstantlyDanglingPtr: InstantlyDanglingPtr,
227227
NonPanicFmt: NonPanicFmt,
228228
NoopMethodCall: NoopMethodCall,
229229
EnumIntrinsicsNonEnums: EnumIntrinsicsNonEnums,

compiler/rustc_lint/src/lints.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,14 +1126,14 @@ pub struct IgnoredUnlessCrateSpecified<'a> {
11261126

11271127
// methods.rs
11281128
#[derive(LintDiagnostic)]
1129-
#[diag(lint_temporary_as_ptr)]
1129+
#[diag(lint_instantly_dangling)]
11301130
#[note]
11311131
#[help]
1132-
pub struct TemporaryAsPtr {
1132+
pub struct InstantlyDangling {
11331133
pub method: Symbol,
11341134
pub ty: String,
1135-
#[label(lint_as_ptr_label)]
1136-
pub as_ptr_span: Span,
1135+
#[label(lint_ptr_label)]
1136+
pub ptr_span: Span,
11371137
#[label(lint_temporary_label)]
11381138
pub temporary_span: Span,
11391139
}

compiler/rustc_lint/src/methods.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_middle::ty::Ty;
33
use rustc_session::{declare_lint, declare_lint_pass};
44
use rustc_span::symbol::{sym, Ident};
55

6-
use crate::lints::TemporaryAsPtr;
6+
use crate::lints::InstantlyDangling;
77
use crate::{LateContext, LateLintPass, LintContext};
88

99
declare_lint! {
@@ -32,16 +32,17 @@ declare_lint! {
3232
"detects getting the inner pointer of a temporary `CString`"
3333
}
3434

35+
// FIXME: does not catch UnsafeCell::get
36+
// FIXME: does not catch getting a ref to a temporary and then converting it to a ptr
3537
declare_lint! {
36-
/// TODO
37-
pub TEMPORARY_AS_PTR,
38+
pub INSTANTLY_DANGLING_POINTER,
3839
Warn,
39-
"detects getting the inner pointer of a temporary container"
40+
"detects getting a pointer that will immediately dangle"
4041
}
4142

42-
declare_lint_pass!(TemporaryCStringAsPtr => [TEMPORARY_CSTRING_AS_PTR, TEMPORARY_AS_PTR]);
43+
declare_lint_pass!(InstantlyDanglingPtr => [TEMPORARY_CSTRING_AS_PTR, INSTANTLY_DANGLING_POINTER]);
4344

44-
impl<'tcx> LateLintPass<'tcx> for TemporaryCStringAsPtr {
45+
impl<'tcx> LateLintPass<'tcx> for InstantlyDanglingPtr {
4546
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
4647
// We have a method call.
4748
let ExprKind::MethodCall(method, receiver, _args, _span) = expr.kind else {
@@ -70,17 +71,17 @@ impl<'tcx> LateLintPass<'tcx> for TemporaryCStringAsPtr {
7071
};
7172

7273
let span = method.ident.span;
73-
let decorator = TemporaryAsPtr {
74+
let decorator = InstantlyDangling {
7475
method: method_name,
7576
ty: ty.to_string(),
76-
as_ptr_span: method_span,
77+
ptr_span: method_span,
7778
temporary_span: receiver.span,
7879
};
7980

8081
if is_cstring {
8182
cx.emit_span_lint(TEMPORARY_CSTRING_AS_PTR, span, decorator);
8283
} else {
83-
cx.emit_span_lint(TEMPORARY_AS_PTR, span, decorator);
84+
cx.emit_span_lint(INSTANTLY_DANGLING_POINTER, span, decorator);
8485
};
8586
}
8687
}

0 commit comments

Comments
 (0)