Skip to content

Commit 12e54bb

Browse files
committed
Rollup merge of rust-lang#32430 - sanxiyn:const-trans, r=arielb1
Fix const trans Fix rust-lang#30615. The idea was that when there are N autoderefs, first do N-1 derefs and check for autoref. If there is autoref, done, if not, do one more deref. But when N is zero, doing one more deref is wrong.
2 parents c028b1c + 308dc55 commit 12e54bb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/librustc_trans/trans/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
381381
llconst = addr_of(cx, llconst, type_of::align_of(cx, ty), "autoref");
382382
ty = cx.tcx().mk_imm_ref(cx.tcx().mk_region(ty::ReStatic), ty);
383383
}
384-
} else {
384+
} else if adj.autoderefs > 0 {
385385
let (dv, dt) = const_deref(cx, llconst, ty);
386386
llconst = dv;
387387

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

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2016 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+
fn main() {
12+
&0u8 as *const u8 as *const PartialEq<u8>;
13+
&[0u8] as *const [u8; 1] as *const [u8];
14+
}

0 commit comments

Comments
 (0)