Skip to content

Commit 09e6a98

Browse files
committed
Fix issue #36036.
We were treating an associated type as unsized even when the concrete instantiation was actually sized. Fix is to normalize before checking if it is sized.
1 parent 86995dc commit 09e6a98

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/librustc/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,10 @@ impl<'a, 'gcx, 'tcx> Layout {
856856
ty::TyRef(_, ty::TypeAndMut { ty: pointee, .. }) |
857857
ty::TyRawPtr(ty::TypeAndMut { ty: pointee, .. }) => {
858858
let non_zero = !ty.is_unsafe_ptr();
859+
let pointee = normalize_associated_type(infcx, pointee);
859860
if pointee.is_sized(tcx, &infcx.parameter_environment, DUMMY_SP) {
860861
Scalar { value: Pointer, non_zero: non_zero }
861862
} else {
862-
let pointee = normalize_associated_type(infcx, pointee);
863863
let unsized_part = tcx.struct_tail(pointee);
864864
let meta = match unsized_part.sty {
865865
ty::TySlice(_) | ty::TyStr => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
// Issue 36036: computing the layout of a type composed from another
12+
// trait's associated type caused compiler to ICE when the associated
13+
// type was allowed to be unsized, even though the known instantiated
14+
// type is itself sized.
15+
16+
#![allow(dead_code)]
17+
18+
trait Context {
19+
type Container: ?Sized;
20+
}
21+
22+
impl Context for u16 {
23+
type Container = u8;
24+
}
25+
26+
struct Wrapper<C: Context+'static> {
27+
container: &'static C::Container
28+
}
29+
30+
fn foobar(_: Wrapper<u16>) {}
31+
32+
static VALUE: u8 = 0;
33+
34+
fn main() {
35+
foobar(Wrapper { container: &VALUE });
36+
}

0 commit comments

Comments
 (0)