Skip to content

adds better error message for temporary value does not live long enough - #154810

Open
Hiryxx wants to merge 4 commits into
rust-lang:mainfrom
Hiryxx:fix-inline-const-e0492
Open

adds better error message for temporary value does not live long enough#154810
Hiryxx wants to merge 4 commits into
rust-lang:mainfrom
Hiryxx:fix-inline-const-e0492

Conversation

@Hiryxx

@Hiryxx Hiryxx commented Apr 4, 2026

Copy link
Copy Markdown

When &const { expr } is borrowed for 'static but expr has interior mutability (is not Freeze), emit E0492 instead
of E0716

Closes #154382

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 4, 2026
@rustbot

rustbot commented Apr 4, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 9 candidates

Comment thread compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
Comment thread tests/ui/inline-const/interior-mutable-borrow.rs Outdated
Comment thread compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
@JohnTitor JohnTitor added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2026
@rust-log-analyzer

This comment has been minimized.

@Hiryxx
Hiryxx requested a review from JohnTitor April 14, 2026 14:02
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2026
Comment thread compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated
@JohnTitor JohnTitor added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 29, 2026
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot

This comment has been minimized.

@Hiryxx
Hiryxx force-pushed the fix-inline-const-e0492 branch from 089360f to a91dbb5 Compare June 26, 2026 13:38
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

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.

@Hiryxx
Hiryxx requested a review from JohnTitor June 26, 2026 15:19
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 26, 2026
@Hiryxx

Hiryxx commented Jun 26, 2026

Copy link
Copy Markdown
Author

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.

@rust-bors

rust-bors Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

☔ 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) {

@JohnTitor JohnTitor Jul 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

@JohnTitor

Copy link
Copy Markdown
Member

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.

I think the current is fine 👍

@JohnTitor JohnTitor removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 31, 2026
@JohnTitor JohnTitor added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Confusing error when trying to promote a const to a static item

4 participants