Skip to content

Commit 019f486

Browse files
committed
fix: Paper over GAT panic
TIL that Chalk expects the arguments to a generic associated type to come *before* the ones for the parent trait, not *after* as we have been doing with all other nested generics. Fixing this requires a larger refactoring, so for now this just papers over the problem by completely ignoring parameters of associated types. Fixes #11769.
1 parent 63c4d6b commit 019f486

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

crates/hir_ty/src/tests/regression.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1497,3 +1497,22 @@ fn regression_11688_3() {
14971497
"#,
14981498
);
14991499
}
1500+
1501+
#[test]
1502+
fn gat_crash() {
1503+
cov_mark::check!(ignore_gats);
1504+
check_no_mismatches(
1505+
r#"
1506+
trait ATrait {}
1507+
1508+
trait Crash {
1509+
type Member<const N: usize>: ATrait;
1510+
fn new<const N: usize>() -> Self::Member<N>;
1511+
}
1512+
1513+
fn test<T: Crash>() {
1514+
T::new();
1515+
}
1516+
"#,
1517+
);
1518+
}

crates/hir_ty/src/utils.rs

+9
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ pub(super) fn associated_type_by_name_including_super_traits(
175175

176176
pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics {
177177
let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def)));
178+
if parent_generics.is_some() && matches!(def, GenericDefId::TypeAliasId(_)) {
179+
// XXX: treat generic associated types as not existing to avoid crashes (#)
180+
//
181+
// Chalk expects the inner associated type's parameters to come
182+
// *before*, not after the trait's generics as we've always done it.
183+
// Adapting to this requires a larger refactoring
184+
cov_mark::hit!(ignore_gats);
185+
return Generics { def, params: Interned::new(Default::default()), parent_generics };
186+
}
178187
Generics { def, params: db.generic_params(def), parent_generics }
179188
}
180189

0 commit comments

Comments
 (0)