Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,16 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
self.fcx.set_tainted_by_errors(guar);
}
}
Ok(Some(impl_source)) => queue.extend(impl_source.nested_obligations()),
Ok(Some(impl_source)) => {
let nested = impl_source.nested_obligations();
if nested.len() == 1 && &obligation == &nested[0] {
// Avoid hang when expanding the current obligation to the same obligation.
// This doesn't occur under normal circumstances, only on incorrect
// recursive type definitions. Issue #148653.
} else {
queue.extend(nested);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Issue #148653.
struct Vec<T> { //~ ERROR recursive type `Vec` has infinite size
data: Vec<T>, //~ ERROR type parameter `T` is only used recursively
}
impl<T> Vec<T> {
pub fn push(&mut self) -> &mut Self {
self
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error: type parameter `T` is only used recursively
--> $DIR/148653-recursive-struct-infinte-cycle.rs:3:15
|
LL | struct Vec<T> {
| - type parameter must be used non-recursively in the definition
LL | data: Vec<T>,
| ^
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= note: all type parameters must be used in a non-recursive way in order to constrain their variance

error[E0072]: recursive type `Vec` has infinite size
--> $DIR/148653-recursive-struct-infinte-cycle.rs:2:1
|
LL | struct Vec<T> {
| ^^^^^^^^^^^^^
LL | data: Vec<T>,
| ------ recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | data: Box<Vec<T>>,
| ++++ +

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0072`.
Loading