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 1 commit intorust-lang:mainfrom
Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| self.dcx(), | ||
| inner_span, | ||
| E0492, | ||
| "interior mutable shared borrows of temporaries that have their \ |
There was a problem hiding this comment.
I don't think it's a good idea to duplicate the message with
rust/compiler/rustc_const_eval/src/errors.rs
Line 296 in 1948ee1
There was a problem hiding this comment.
Please put the issue number in a file title and the link in the comment for reference.
|
|
||
| // Emit E0492 for `&const { expr }` when `expr` has | ||
| // interior mutability, since that's what actually prevents promotion. | ||
| if let Some(expr) = self.find_expr(proper_span) |
There was a problem hiding this comment.
I guess we could expand the fix for a similar case where promotion failed because the value is not Freeze, like:
use std::cell::Cell;
struct Mutable(Cell<u32>);
impl Mutable {
const fn new(a: u32) -> Self { Self(Cell::new(a)) }
}
fn foo() -> &'static Mutable {
&const { Mutable::new(0) }
}
fn main() {}The current only addresses the case issue mentioned, I guess it's kinda ad hoc. These cases should have the same diagnostics for consistency.
When &const { expr } is borrowed for 'static but expr has interior mutability (is not Freeze), emit E0492 instead
of E0716
Closes #154382