adds better error message for temporary value does not live long enough - #154810
adds better error message for temporary value does not live long enough#154810Hiryxx wants to merge 4 commits into
Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
089360f to
a91dbb5
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
I had to pull the detection into a span variable up top and reuse it as a flag, this makes it a little verbose for the error output but I couldn't find a better since the alternatives where worse. Let me know what you think @JohnTitor. |
|
☔ The latest upstream changes (presumably #159170) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
| let borrowed_ty = self.body.local_decls[borrow.borrowed_place.local].ty; | ||
| let typing_env = self.infcx.typing_env(self.infcx.param_env); | ||
| let tcx = self.infcx.tcx; | ||
| if !borrowed_ty.is_freeze(tcx, typing_env) { |
There was a problem hiding this comment.
Checking interior mutability with !Freeze can be false-positive, it isn't equal that promotion failure is due to it.
Maybe we should use the existing mechanism like https://doc.rust-lang.org/nightly/nightly-rustc/rustc_const_eval/check_consts/qualifs/struct.HasMutInterior.html to harden the checker.
I think the current is fine 👍 |
When &const { expr } is borrowed for 'static but expr has interior mutability (is not Freeze), emit E0492 instead
of E0716
Closes #154382