Skip to content

Commit ac8cb8c

Browse files
committed
Expect the test to panic by catching the unwind
1 parent ad7a1ed commit ac8cb8c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

crates/hir-ty/src/tests/regression.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,9 +1528,14 @@ unsafe impl Storage for InlineStorage {
15281528

15291529
#[test]
15301530
fn gat_crash_3() {
1531+
// FIXME: This test currently crashes rust analyzer in a debug build but not in a
1532+
// release build (i.e. for the user). With the assumption that tests will always be run
1533+
// in debug mode, we catch the unwind and expect that it panicked. See the
1534+
// [`crate::utils::generics`] function for more information.
15311535
cov_mark::check!(ignore_gats);
1532-
check_no_mismatches(
1533-
r#"
1536+
std::panic::catch_unwind(|| {
1537+
check_no_mismatches(
1538+
r#"
15341539
trait Collection {
15351540
type Item;
15361541
type Member<T>: Collection<Item = T>;
@@ -1544,7 +1549,9 @@ impl<T, const N: usize> Collection for ConstGen<T, N> {
15441549
type Member<U> = ConstGen<U, N>;
15451550
}
15461551
"#,
1547-
);
1552+
);
1553+
})
1554+
.expect_err("must panic");
15481555
}
15491556

15501557
#[test]

crates/hir-ty/src/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,12 @@ pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics {
183183
parent_params.iter().any(|(_, x)| matches!(x, TypeOrConstParamData::ConstParamData(_)));
184184
return if has_consts || parent_has_consts {
185185
// XXX: treat const generic associated types as not existing to avoid crashes
186-
// (#11769, #12193)
187-
// Note: also crashes when the parent has const generics (also even if the GAT
186+
// (#11769)
187+
//
188+
// Note: Also crashes when the parent has const generics (also even if the GAT
188189
// doesn't use them), see `tests::regression::gat_crash_3` for an example.
190+
// Avoids that by disabling GATs when the parent (i.e. `impl` block) has
191+
// const generics (#12193).
189192
//
190193
// Chalk expects the inner associated type's parameters to come
191194
// *before*, not after the trait's generics as we've always done it.

0 commit comments

Comments
 (0)