Skip to content

Commit 3a44107

Browse files
debuginfo: Fix issue with associated types and struct fields
1 parent 6869645 commit 3a44107

File tree

2 files changed

+159
-1
lines changed

2 files changed

+159
-1
lines changed

src/librustc_trans/trans/debuginfo.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2068,7 +2068,13 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
20682068
unique_type_id,
20692069
containing_scope);
20702070

2071-
let fields = ty::struct_fields(cx.tcx(), def_id, substs);
2071+
let mut fields = ty::struct_fields(cx.tcx(), def_id, substs);
2072+
2073+
// The `Ty` values returned by `ty::struct_fields` can still contain
2074+
// `ty_projection` variants, so normalize those away.
2075+
for field in fields.iter_mut() {
2076+
field.mt.ty = monomorphize::normalize_associated_type(cx.tcx(), &field.mt.ty);
2077+
}
20722078

20732079
create_and_register_recursive_type_forward_declaration(
20742080
cx,
+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
// Copyright 2013-2014 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+
// ignore-android: FIXME(#10381)
12+
// min-lldb-version: 310
13+
14+
// compile-flags:-g
15+
16+
// === GDB TESTS ===================================================================================
17+
// gdb-command:run
18+
19+
// gdb-command:print arg
20+
// gdb-check:$1 = {b = -1, b1 = 0}
21+
// gdb-command:continue
22+
23+
// gdb-command:print inferred
24+
// gdb-check:$2 = 1
25+
// gdb-command:print explicitly
26+
// gdb-check:$3 = 1
27+
// gdb-command:continue
28+
29+
// gdb-command:print arg
30+
// gdb-check:$4 = 2
31+
// gdb-command:continue
32+
33+
// gdb-command:print arg
34+
// gdb-check:$5 = {4, 5}
35+
// gdb-command:continue
36+
37+
// gdb-command:print a
38+
// gdb-check:$6 = 6
39+
// gdb-command:print b
40+
// gdb-check:$7 = 7
41+
// gdb-command:continue
42+
43+
// gdb-command:print a
44+
// gdb-check:$8 = 8
45+
// gdb-command:print b
46+
// gdb-check:$9 = 9
47+
// gdb-command:continue
48+
49+
// === LLDB TESTS ==================================================================================
50+
// lldb-command:run
51+
52+
// lldb-command:print arg
53+
// lldb-check:[...]$0 = Struct<i32> { b: -1, b1: 0 }
54+
// lldb-command:continue
55+
56+
// lldb-command:print inferred
57+
// lldb-check:[...]$1 = 1
58+
// lldb-command:print explicitly
59+
// lldb-check:[...]$2 = 1
60+
// lldb-command:continue
61+
62+
// lldb-command:print arg
63+
// lldb-check:[...]$3 = 2
64+
// lldb-command:continue
65+
66+
// lldb-command:print arg
67+
// lldb-check:[...]$4 = (4, 5)
68+
// lldb-command:continue
69+
70+
// lldb-command:print a
71+
// lldb-check:[...]$5 = 6
72+
// lldb-command:print b
73+
// lldb-check:[...]$6 = 7
74+
// lldb-command:continue
75+
76+
// lldb-command:print a
77+
// lldb-check:[...]$7 = 8
78+
// lldb-command:print b
79+
// lldb-check:[...]$8 = 9
80+
// lldb-command:continue
81+
82+
#![allow(unused_variables)]
83+
#![allow(dead_code)]
84+
#![omit_gdb_pretty_printer_section]
85+
86+
trait TraitWithAssocType {
87+
type Type;
88+
89+
fn get_value(&self) -> Self::Type;
90+
}
91+
impl TraitWithAssocType for i32 {
92+
type Type = i64;
93+
94+
fn get_value(&self) -> i64 { *self as i64 }
95+
}
96+
97+
struct Struct<T: TraitWithAssocType> {
98+
b: T,
99+
b1: T::Type,
100+
}
101+
102+
enum Enum<T: TraitWithAssocType> {
103+
Variant1(T, T::Type),
104+
Variant2(T::Type, T)
105+
}
106+
107+
fn assoc_struct<T: TraitWithAssocType>(arg: Struct<T>) {
108+
zzz(); // #break
109+
}
110+
111+
fn assoc_local<T: TraitWithAssocType>(x: T) {
112+
let inferred = x.get_value();
113+
let explicitly: T::Type = x.get_value();
114+
115+
zzz(); // #break
116+
}
117+
118+
fn assoc_arg<T: TraitWithAssocType>(arg: T::Type) {
119+
zzz(); // #break
120+
}
121+
122+
fn assoc_return_value<T: TraitWithAssocType>(arg: T) -> T::Type {
123+
return arg.get_value();
124+
}
125+
126+
fn assoc_tuple<T: TraitWithAssocType>(arg: (T, T::Type)) {
127+
zzz(); // #break
128+
}
129+
130+
fn assoc_enum<T: TraitWithAssocType>(arg: Enum<T>) {
131+
132+
match arg {
133+
Enum::Variant1(a, b) => {
134+
zzz(); // #break
135+
}
136+
Enum::Variant2(a, b) => {
137+
zzz(); // #break
138+
}
139+
}
140+
}
141+
142+
fn main() {
143+
assoc_struct(Struct { b: -1i32, b1: 0i64 });
144+
assoc_local(1i32);
145+
assoc_arg::<i32>(2i64);
146+
assoc_return_value(3i32);
147+
assoc_tuple((4i32, 5i64));
148+
assoc_enum(Enum::Variant1(6i32, 7i64));
149+
assoc_enum(Enum::Variant2(8i64, 9i32));
150+
}
151+
152+
fn zzz() { () }

0 commit comments

Comments
 (0)