Skip to content

Commit b71e73b

Browse files
pcwaltonemilio
authored andcommitted
Detect and avoid cycles when resolving items.
These can happen in certain cases involving incomplete qualified dependent types. To avoid looping forever, we need to check for them. Closes #2085.
1 parent cf6edbd commit b71e73b

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/ir/context.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2723,8 +2723,16 @@ impl ItemResolver {
27232723
assert!(ctx.collected_typerefs());
27242724

27252725
let mut id = self.id;
2726+
let mut seen_ids = HashSet::default();
27262727
loop {
27272728
let item = ctx.resolve_item(id);
2729+
2730+
// Detect cycles and bail out. These can happen in certain cases
2731+
// involving incomplete qualified dependent types (#2085).
2732+
if !seen_ids.insert(id) {
2733+
return item;
2734+
}
2735+
27282736
let ty_kind = item.as_type().map(|t| t.kind());
27292737
match ty_kind {
27302738
Some(&TypeKind::ResolvedTypeRef(next_id))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![allow(
2+
dead_code,
3+
non_snake_case,
4+
non_camel_case_types,
5+
non_upper_case_globals
6+
)]
7+
8+
#[repr(C)]
9+
#[derive(Debug, Default, Copy, Clone)]
10+
pub struct Foo {
11+
pub _address: u8,
12+
}
13+
#[repr(C)]
14+
#[derive(Debug, Default, Copy, Clone)]
15+
pub struct Bar {
16+
pub _address: u8,
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Issue #2085.
2+
3+
template<typename T>
4+
struct Foo;
5+
6+
template<typename T, typename U>
7+
struct Bar {};
8+
9+
template<typename T>
10+
struct Bar<T, void> {
11+
using BarDependent = typename Foo<T>::Dependent;
12+
void method(const BarDependent &);
13+
};
14+
15+
template<typename T>
16+
void Bar<T, void>::method(const BarDependent &) {}

0 commit comments

Comments
 (0)