Skip to content

Commit b77de83

Browse files
mark THIR use as candidate for constness check
1 parent 120162e commit b77de83

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
661661
/// operations that can be const-folded today.
662662
fn check_constness(&self, mut kind: &'a ExprKind<'tcx>) -> bool {
663663
loop {
664+
debug!(?kind, "check_constness");
664665
match kind {
665-
&ExprKind::PointerCoercion {
666+
&ExprKind::ValueTypeAscription { source: eid, user_ty: _, user_ty_span: _ }
667+
| &ExprKind::Use { source: eid }
668+
| &ExprKind::PointerCoercion {
666669
cast: PointerCoercion::Unsize,
667670
source: eid,
668671
is_from_as_cast: _,

tests/ui/coercion/no_local_for_coerced_const-issue-143671.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ const Y: X<'static, i32> = X { f: &0 };
2929
fn main() {
3030
let _: [X<'static, dyn Display>; 0] = [Y; 0];
3131
coercion_on_weak_in_const();
32+
coercion_on_weak_as_cast();
3233
}
3334

3435
fn coercion_on_weak_in_const() {
3536
const X: Weak<i32> = Weak::new();
3637
const Y: [Weak<dyn Send>; 0] = [X; 0];
3738
let _ = Y;
3839
}
40+
41+
fn coercion_on_weak_as_cast() {
42+
const Y: X<'static, i32> = X { f: &0 };
43+
// What happens in the following code is that
44+
// a constant is explicitly coerced into
45+
let _a: [X<'static, dyn Display>; 0] = [Y as X<'static, dyn Display>; 0];
46+
}

0 commit comments

Comments
 (0)