Skip to content

Commit 21bcd2e

Browse files
committedFeb 17, 2023
Fix ICE on type alias in recursion
1 parent f4f5fc3 commit 21bcd2e

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed
 

‎compiler/rustc_middle/src/values.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::dep_graph::DepKind;
22
use rustc_data_structures::fx::FxHashSet;
33
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
44
use rustc_hir as hir;
5-
use rustc_hir::def::DefKind;
5+
use rustc_hir::def::{DefKind, Res};
66
use rustc_middle::ty::Representability;
77
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
88
use rustc_query_system::query::QueryInfo;
@@ -199,7 +199,8 @@ fn find_item_ty_spans(
199199
) {
200200
match ty.kind {
201201
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
202-
if let Some(def_id) = path.res.opt_def_id() {
202+
if let Res::Def(kind, def_id) = path.res
203+
&& kind != DefKind::TyAlias {
203204
let check_params = def_id.as_local().map_or(true, |def_id| {
204205
if def_id == needle {
205206
spans.push(ty.span);

‎tests/ui/infinite/auxiliary/alias.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub struct W<T>(T);
2+
pub type Wrapper<T> = W<T>;

‎tests/ui/infinite/infinite-alias.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// aux-build: alias.rs
2+
// regression test for 108160
3+
4+
extern crate alias;
5+
6+
use alias::Wrapper;
7+
struct Rec(Wrapper<Rec>); //~ ERROR recursive type `Rec` has infinite
8+
9+
fn main() {}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0072]: recursive type `Rec` has infinite size
2+
--> $DIR/infinite-alias.rs:7:1
3+
|
4+
LL | struct Rec(Wrapper<Rec>);
5+
| ^^^^^^^^^^ ------------ recursive without indirection
6+
|
7+
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
8+
|
9+
LL | struct Rec(Box<Wrapper<Rec>>);
10+
| ++++ +
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0072`.

0 commit comments

Comments
 (0)
Please sign in to comment.