about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2015-01-22 18:09:59 -0500
committerSteve Klabnik <steve@steveklabnik.com>2015-01-22 18:09:59 -0500
commit07fb31a0991cd9e92bea23d215392a812837fd36 (patch)
tree3b4934ad2bc324a6ce6acc9d8a3a66c45f71bacc
parent1644978616e5c950eb345dc6773e8eb5a3e0c25a (diff)
parent3a44107f9eb70342c0b2cac56c0b6ebc0f94f253 (diff)
downloadrust-07fb31a0991cd9e92bea23d215392a812837fd36.tar.gz
rust-07fb31a0991cd9e92bea23d215392a812837fd36.zip
Rollup merge of #21471 - michaelwoerister:associated-types, r=alexcrichton
This should fix issue #20797 (but I don't want to close it automatically).
As the actual fix is very small this would be a perfect candidate for a rollup.
-rw-r--r--src/librustc_trans/trans/debuginfo.rs8
-rw-r--r--src/test/debuginfo/associated-types.rs152
2 files changed, 159 insertions, 1 deletions
diff --git a/src/librustc_trans/trans/debuginfo.rs b/src/librustc_trans/trans/debuginfo.rs
index 9df1b236fe8..39413d63482 100644
--- a/src/librustc_trans/trans/debuginfo.rs
+++ b/src/librustc_trans/trans/debuginfo.rs
@@ -2088,7 +2088,13 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
                                                   unique_type_id,
                                                   containing_scope);
 
-    let fields = ty::struct_fields(cx.tcx(), def_id, substs);
+    let mut fields = ty::struct_fields(cx.tcx(), def_id, substs);
+
+    // The `Ty` values returned by `ty::struct_fields` can still contain
+    // `ty_projection` variants, so normalize those away.
+    for field in fields.iter_mut() {
+        field.mt.ty = monomorphize::normalize_associated_type(cx.tcx(), &field.mt.ty);
+    }
 
     create_and_register_recursive_type_forward_declaration(
         cx,
diff --git a/src/test/debuginfo/associated-types.rs b/src/test/debuginfo/associated-types.rs
new file mode 100644
index 00000000000..6a624e39e32
--- /dev/null
+++ b/src/test/debuginfo/associated-types.rs
@@ -0,0 +1,152 @@
+// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// ignore-android: FIXME(#10381)
+// min-lldb-version: 310
+
+// compile-flags:-g
+
+// === GDB TESTS ===================================================================================
+// gdb-command:run
+
+// gdb-command:print arg
+// gdb-check:$1 = {b = -1, b1 = 0}
+// gdb-command:continue
+
+// gdb-command:print inferred
+// gdb-check:$2 = 1
+// gdb-command:print explicitly
+// gdb-check:$3 = 1
+// gdb-command:continue
+
+// gdb-command:print arg
+// gdb-check:$4 = 2
+// gdb-command:continue
+
+// gdb-command:print arg
+// gdb-check:$5 = {4, 5}
+// gdb-command:continue
+
+// gdb-command:print a
+// gdb-check:$6 = 6
+// gdb-command:print b
+// gdb-check:$7 = 7
+// gdb-command:continue
+
+// gdb-command:print a
+// gdb-check:$8 = 8
+// gdb-command:print b
+// gdb-check:$9 = 9
+// gdb-command:continue
+
+// === LLDB TESTS ==================================================================================
+// lldb-command:run
+
+// lldb-command:print arg
+// lldb-check:[...]$0 = Struct<i32> { b: -1, b1: 0 }
+// lldb-command:continue
+
+// lldb-command:print inferred
+// lldb-check:[...]$1 = 1
+// lldb-command:print explicitly
+// lldb-check:[...]$2 = 1
+// lldb-command:continue
+
+// lldb-command:print arg
+// lldb-check:[...]$3 = 2
+// lldb-command:continue
+
+// lldb-command:print arg
+// lldb-check:[...]$4 = (4, 5)
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$5 = 6
+// lldb-command:print b
+// lldb-check:[...]$6 = 7
+// lldb-command:continue
+
+// lldb-command:print a
+// lldb-check:[...]$7 = 8
+// lldb-command:print b
+// lldb-check:[...]$8 = 9
+// lldb-command:continue
+
+#![allow(unused_variables)]
+#![allow(dead_code)]
+#![omit_gdb_pretty_printer_section]
+
+trait TraitWithAssocType {
+    type Type;
+
+    fn get_value(&self) -> Self::Type;
+}
+impl TraitWithAssocType for i32 {
+    type Type = i64;
+
+    fn get_value(&self) -> i64 { *self as i64 }
+}
+
+struct Struct<T: TraitWithAssocType> {
+    b: T,
+    b1: T::Type,
+}
+
+enum Enum<T: TraitWithAssocType> {
+    Variant1(T, T::Type),
+    Variant2(T::Type, T)
+}
+
+fn assoc_struct<T: TraitWithAssocType>(arg: Struct<T>) {
+    zzz(); // #break
+}
+
+fn assoc_local<T: TraitWithAssocType>(x: T) {
+    let inferred = x.get_value();
+    let explicitly: T::Type = x.get_value();
+
+    zzz(); // #break
+}
+
+fn assoc_arg<T: TraitWithAssocType>(arg: T::Type) {
+    zzz(); // #break
+}
+
+fn assoc_return_value<T: TraitWithAssocType>(arg: T) -> T::Type {
+    return arg.get_value();
+}
+
+fn assoc_tuple<T: TraitWithAssocType>(arg: (T, T::Type)) {
+    zzz(); // #break
+}
+
+fn assoc_enum<T: TraitWithAssocType>(arg: Enum<T>) {
+
+    match arg {
+        Enum::Variant1(a, b) => {
+            zzz(); // #break
+        }
+        Enum::Variant2(a, b) => {
+            zzz(); // #break
+        }
+    }
+}
+
+fn main() {
+    assoc_struct(Struct { b: -1i32, b1: 0i64 });
+    assoc_local(1i32);
+    assoc_arg::<i32>(2i64);
+    assoc_return_value(3i32);
+    assoc_tuple((4i32, 5i64));
+    assoc_enum(Enum::Variant1(6i32, 7i64));
+    assoc_enum(Enum::Variant2(8i64, 9i32));
+}
+
+fn zzz() { () }
\ No newline at end of file