Skip to content

Commit de0d123

Browse files
Rollup merge of rust-lang#41923 - eddyb:issue-41744, r=arielb1
rustc_trans: do not attempt to truncate an i1 const to i1. Fixes rust-lang#41744 by skipping the truncation when it'd be a noop anyway.
2 parents 629f801 + 68c1ce9 commit de0d123

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/librustc_trans/mir/constant.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,11 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
415415
Value(base));
416416
}
417417
if projected_ty.is_bool() {
418-
unsafe {
419-
val = llvm::LLVMConstTrunc(val, Type::i1(self.ccx).to_ref());
418+
let i1_type = Type::i1(self.ccx);
419+
if val_ty(val) != i1_type {
420+
unsafe {
421+
val = llvm::LLVMConstTrunc(val, i1_type.to_ref());
422+
}
420423
}
421424
}
422425
(Base::Value(val), extra)

src/test/run-pass/issue-41744.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Tc {}
12+
impl Tc for bool {}
13+
14+
fn main() {
15+
let _: &[&Tc] = &[&true];
16+
}

0 commit comments

Comments
 (0)