Skip to content

Commit efcc1d1

Browse files
committed
Auto merge of #25797 - eddyb:const-trait-to-trait, r=luqmana
Fixes #24644.
2 parents f56782a + d957e04 commit efcc1d1

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/librustc_trans/trans/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,11 @@ pub fn const_expr<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
342342
let info = expr::unsized_info(cx, pointee_ty, unsized_ty,
343343
old_info, param_substs);
344344

345-
let prev_const = cx.const_unsized().borrow_mut()
346-
.insert(base, llconst);
347-
assert!(prev_const.is_none() || prev_const == Some(llconst));
345+
if old_info.is_none() {
346+
let prev_const = cx.const_unsized().borrow_mut()
347+
.insert(base, llconst);
348+
assert!(prev_const.is_none() || prev_const == Some(llconst));
349+
}
348350
assert_eq!(abi::FAT_PTR_ADDR, 0);
349351
assert_eq!(abi::FAT_PTR_EXTRA, 1);
350352
llconst = C_struct(cx, &[base, info], false);
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Issue #24644 - block causes a &Trait -> &Trait coercion:
12+
trait Trait {}
13+
14+
struct Bar;
15+
impl Trait for Bar {}
16+
17+
fn main() {
18+
let x: &[&Trait] = &[{ &Bar }];
19+
}
20+
21+
// Issue #25748 - the cast causes an &Encoding -> &Encoding coercion:
22+
pub struct UTF8Encoding;
23+
pub const UTF_8: &'static UTF8Encoding = &UTF8Encoding;
24+
pub trait Encoding {}
25+
impl Encoding for UTF8Encoding {}
26+
pub fn f() -> &'static Encoding { UTF_8 as &'static Encoding }
27+
28+
// Root of the problem: &Trait -> &Trait coercions:
29+
const FOO: &'static Trait = &Bar;
30+
const BAR: &'static Trait = FOO;
31+
fn foo() { let _x = BAR; }

0 commit comments

Comments
 (0)