Skip to content

Fix ICE on type alias in recursion #108168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2023
Merged
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
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::dep_graph::DepKind;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def::{DefKind, Res};
use rustc_middle::ty::Representability;
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
use rustc_query_system::query::QueryInfo;
Expand Down Expand Up @@ -199,7 +199,8 @@ fn find_item_ty_spans(
) {
match ty.kind {
hir::TyKind::Path(hir::QPath::Resolved(_, path)) => {
if let Some(def_id) = path.res.opt_def_id() {
if let Res::Def(kind, def_id) = path.res
&& kind != DefKind::TyAlias {
let check_params = def_id.as_local().map_or(true, |def_id| {
if def_id == needle {
spans.push(ty.span);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/infinite/auxiliary/alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub struct W<T>(T);
pub type Wrapper<T> = W<T>;
9 changes: 9 additions & 0 deletions tests/ui/infinite/infinite-alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// aux-build: alias.rs
// regression test for 108160

extern crate alias;

use alias::Wrapper;
struct Rec(Wrapper<Rec>); //~ ERROR recursive type `Rec` has infinite

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/infinite/infinite-alias.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0072]: recursive type `Rec` has infinite size
--> $DIR/infinite-alias.rs:7:1
|
LL | struct Rec(Wrapper<Rec>);
| ^^^^^^^^^^ ------------ recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL | struct Rec(Box<Wrapper<Rec>>);
| ++++ +

error: aborting due to previous error

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