Skip to content

Commit 45001c0

Browse files
committed
Auto merge of #25773 - dotdash:deref_dst, r=eddyb
Fat pointers aren't immediate, so in a datum, they're not actually ByValue but ByRef. Fixes #24589
2 parents 38c943f + efd3e75 commit 45001c0

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/librustc_trans/trans/expr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,9 @@ fn auto_ref<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
21802180
// Construct the resulting datum, using what was the "by ref"
21812181
// ValueRef of type `referent_ty` to be the "by value" ValueRef
21822182
// of type `&referent_ty`.
2183-
DatumBlock::new(bcx, Datum::new(llref, ptr_ty, RvalueExpr(Rvalue::new(ByValue))))
2183+
// Pointers to DST types are non-immediate, and therefore still use ByRef.
2184+
let kind = if type_is_sized(bcx.tcx(), referent_ty) { ByValue } else { ByRef };
2185+
DatumBlock::new(bcx, Datum::new(llref, ptr_ty, RvalueExpr(Rvalue::new(kind))))
21842186
}
21852187

21862188
fn deref_multiple<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 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+
pub struct _X([u8]);
12+
13+
impl std::ops::Deref for _X {
14+
type Target = [u8];
15+
16+
fn deref(&self) -> &[u8] {
17+
&self.0
18+
}
19+
}
20+
21+
pub fn _g(x: &_X) -> &[u8] {
22+
x
23+
}
24+
25+
fn main() {
26+
}

0 commit comments

Comments
 (0)