Skip to content

Commit 0eb575c

Browse files
committed
Auto merge of #33303 - Aatch:mir-coercion-cast, r=arielb1
[MIR] Handle coercion casts properly when building the MIR Coercion casts (`expr as T` where the type of `expr` can be coerced to `T`) are essentially no-ops, as the actual work is done by a coercion. Previously a check for type equality was used to avoid emitting the redundant cast in the MIR, but this failed for coercion casts of function items that had lifetime parameters. The MIR trans code doesn't handle `FnPtr -> FnPtr` casts and produced an error. Also fixes a bug with type ascription expressions not having any adjustments applied. Fixes #33295 /cc @eddyb
2 parents e1a575c + 3906aef commit 0eb575c

File tree

4 files changed

+448
-394
lines changed

4 files changed

+448
-394
lines changed

src/librustc_mir/build/expr/as_rvalue.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,9 @@ impl<'a,'tcx> Builder<'a,'tcx> {
8787
}
8888
ExprKind::Cast { source } => {
8989
let source = this.hir.mirror(source);
90-
if source.ty == expr.ty {
91-
this.expr_as_rvalue(block, source)
92-
} else {
93-
let source = unpack!(block = this.as_operand(block, source));
94-
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
95-
}
90+
91+
let source = unpack!(block = this.as_operand(block, source));
92+
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
9693
}
9794
ExprKind::ReifyFnPointer { source } => {
9895
let source = unpack!(block = this.as_operand(block, source));

0 commit comments

Comments
 (0)