Skip to content

Commit 2868404

Browse files
committed
Normalize associated types in the type_is_newtype_immediate pass. Fixes #21010.
1 parent ff6085f commit 2868404

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/librustc_trans/trans/common.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,15 @@ pub fn type_needs_drop<'tcx>(cx: &ty::ctxt<'tcx>,
217217
ty::type_contents(cx, ty).needs_drop(cx)
218218
}
219219

220-
fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
221-
ty: Ty<'tcx>) -> bool {
220+
fn type_is_newtype_immediate<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
222221
match ty.sty {
223222
ty::ty_struct(def_id, substs) => {
224-
let fields = ty::struct_fields(ccx.tcx(), def_id, substs);
225-
fields.len() == 1 && type_is_immediate(ccx, fields[0].mt.ty)
223+
let fields = ty::lookup_struct_fields(ccx.tcx(), def_id);
224+
fields.len() == 1 && {
225+
let ty = ty::lookup_field_type(ccx.tcx(), def_id, fields[0].id, substs);
226+
let ty = monomorphize::normalize_associated_type(ccx.tcx(), &ty);
227+
type_is_immediate(ccx, ty)
228+
}
226229
}
227230
_ => false
228231
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
// Regression test for issue #21010: Normalize associated types in
12+
// various special paths in the `type_is_immediate` function.
13+
14+
#![allow(unstable)]
15+
16+
pub trait OffsetState: Sized {}
17+
pub trait Offset { type State: OffsetState; }
18+
19+
#[derive(Copy)] pub struct X;
20+
impl Offset for X { type State = Y; }
21+
22+
#[derive(Copy)] pub struct Y;
23+
impl OffsetState for Y {}
24+
25+
pub fn now() -> DateTime<X> { from_utc(Y) }
26+
27+
pub struct DateTime<Off: Offset> { pub offset: Off::State }
28+
pub fn from_utc<Off: Offset>(offset: Off::State) -> DateTime<Off> { DateTime { offset: offset } }
29+
30+
pub fn main() {
31+
let _x = now();
32+
}

0 commit comments

Comments
 (0)