mark THIR use as candidate for constness check

This commit is contained in:
Ding Xiang Fei 2025-09-25 01:53:34 +08:00 committed by Xiangfei Ding
parent 120162e30f
commit b77de834c0
No known key found for this signature in database
GPG key ID: 3CD748647EEF6359
2 changed files with 12 additions and 1 deletions

View file

@ -661,8 +661,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// operations that can be const-folded today.
fn check_constness(&self, mut kind: &'a ExprKind<'tcx>) -> bool {
loop {
debug!(?kind, "check_constness");
match kind {
&ExprKind::PointerCoercion {
&ExprKind::ValueTypeAscription { source: eid, user_ty: _, user_ty_span: _ }
| &ExprKind::Use { source: eid }
| &ExprKind::PointerCoercion {
cast: PointerCoercion::Unsize,
source: eid,
is_from_as_cast: _,

View file

@ -29,6 +29,7 @@ const Y: X<'static, i32> = X { f: &0 };
fn main() {
let _: [X<'static, dyn Display>; 0] = [Y; 0];
coercion_on_weak_in_const();
coercion_on_weak_as_cast();
}
fn coercion_on_weak_in_const() {
@ -36,3 +37,10 @@ fn coercion_on_weak_in_const() {
const Y: [Weak<dyn Send>; 0] = [X; 0];
let _ = Y;
}
fn coercion_on_weak_as_cast() {
const Y: X<'static, i32> = X { f: &0 };
// What happens in the following code is that
// a constant is explicitly coerced into
let _a: [X<'static, dyn Display>; 0] = [Y as X<'static, dyn Display>; 0];
}