Skip to content

Commit 8dd3f4f

Browse files
committed
Do not ICE on AnonConsts in diagnostic_hir_wf_check
1 parent 426a698 commit 8dd3f4f

File tree

4 files changed

+434
-14
lines changed

4 files changed

+434
-14
lines changed

compiler/rustc_hir_analysis/src/hir_wf_check.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,17 @@ fn diagnostic_hir_wf_check<'tcx>(
163163
kind: hir::GenericParamKind::Type { default: Some(ty), .. },
164164
..
165165
}) => vec![*ty],
166-
hir::Node::AnonConst(_)
167-
if let Some(const_param_id) =
168-
tcx.hir().opt_const_param_default_param_def_id(hir_id)
166+
hir::Node::AnonConst(_) => {
167+
if let Some(const_param_id) = tcx.hir().opt_const_param_default_param_def_id(hir_id)
169168
&& let hir::Node::GenericParam(hir::GenericParam {
170169
kind: hir::GenericParamKind::Const { ty, .. },
171170
..
172-
}) = tcx.hir_node_by_def_id(const_param_id) =>
173-
{
174-
vec![*ty]
171+
}) = tcx.hir_node_by_def_id(const_param_id)
172+
{
173+
vec![*ty]
174+
} else {
175+
vec![]
176+
}
175177
}
176178
ref node => bug!("Unexpected node {:?}", node),
177179
},

tests/crashes/122989.rs

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Regression test for ICE #122989
2+
trait Traitor<const N: N<2> = 1, const N: N<2> = N> {
3+
//~^ ERROR the name `N` is already used for a generic parameter in this item's generic parameters
4+
//~| ERROR cycle detected when computing type of `Traitor::N`
5+
//~| ERROR cycle detected when computing type of `Traitor::N`
6+
//~| ERROR the trait `Traitor` cannot be made into an object
7+
//~| ERROR the trait `Traitor` cannot be made into an object
8+
//~| ERROR the trait `Traitor` cannot be made into an object
9+
//~| ERROR the trait `Traitor` cannot be made into an object
10+
//~| ERROR `(dyn N<2> + 'static)` is forbidden as the type of a const generic parameter
11+
//~| ERROR `(dyn N<2> + 'static)` is forbidden as the type of a const generic parameter
12+
//~| WARN trait objects without an explicit `dyn` are deprecated
13+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
14+
//~| WARN trait objects without an explicit `dyn` are deprecated
15+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
16+
//~| WARN trait objects without an explicit `dyn` are deprecated
17+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
18+
fn N(&N) -> N<2> {
19+
//~^ ERROR the trait `Traitor` cannot be made into an object
20+
//~| WARN anonymous parameters are deprecated and will be removed in the next edition
21+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
22+
//~| WARN trait objects without an explicit `dyn` are deprecated
23+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
24+
//~| WARN trait objects without an explicit `dyn` are deprecated
25+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
26+
M
27+
//~^ ERROR cannot find value `M` in this scope
28+
}
29+
}
30+
31+
trait N<const N: Traitor<2> = 12> {}
32+
//~^ ERROR cycle detected when computing type of `N::N`
33+
//~| ERROR cycle detected when computing type of `N::N`
34+
//~| ERROR the trait `Traitor` cannot be made into an object
35+
//~| ERROR the trait `Traitor` cannot be made into an object
36+
//~| ERROR `(dyn Traitor<2, {const error}> + 'static)` is forbidden as the type of a const generic parameter
37+
//~| WARN trait objects without an explicit `dyn` are deprecated
38+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
39+
//~| WARN trait objects without an explicit `dyn` are deprecated
40+
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
41+
42+
fn main() {}

0 commit comments

Comments
 (0)