Lint for returning a pointer to stack memory associated with a local variable #134215
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
Current output
rustc doesn't currently warn about this.
Desired output
A warning that this pointer is referencing a local variable and is going to be dangling immediately. E.g.
Rationale and extra context
This code is very unlikely to be correct, which is exactly why a warning should be emitted. This would be similar to Clang's
-Wreturn-stack-address
warning.In case of returning a reference, rustc would catch this and emit a compiler error. While it is fine to create such a pointer, it is very unlikely that the code should be written that way.
Rust Version
Anything else?
If this becomes a
Warn
lint it will start warning immediately and potentially break users that configured warnings as errors. So maybe this should beAllow
for the beginning?The text was updated successfully, but these errors were encountered: