Skip to content

Commit

Permalink
Auto merge of #33303 - Aatch:mir-coercion-cast, r=arielb1
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bors committed May 2, 2016
2 parents e1a575c + 3906aef commit 0eb575c
Show file tree
Hide file tree
Showing 4 changed files with 448 additions and 394 deletions.
9 changes: 3 additions & 6 deletions src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,9 @@ impl<'a,'tcx> Builder<'a,'tcx> {
}
ExprKind::Cast { source } => {
let source = this.hir.mirror(source);
if source.ty == expr.ty {
this.expr_as_rvalue(block, source)
} else {
let source = unpack!(block = this.as_operand(block, source));
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
}

let source = unpack!(block = this.as_operand(block, source));
block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty))
}
ExprKind::ReifyFnPointer { source } => {
let source = unpack!(block = this.as_operand(block, source));
Expand Down
Loading

0 comments on commit 0eb575c

Please sign in to comment.