Skip to content
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

fix: Paper over GAT panic #11878

Merged
merged 1 commit into from
Apr 2, 2022
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
19 changes: 19 additions & 0 deletions crates/hir_ty/src/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,3 +1497,22 @@ fn regression_11688_3() {
"#,
);
}

#[test]
fn gat_crash() {
cov_mark::check!(ignore_gats);
check_no_mismatches(
r#"
trait ATrait {}

trait Crash {
type Member<const N: usize>: ATrait;
fn new<const N: usize>() -> Self::Member<N>;
}

fn test<T: Crash>() {
T::new();
}
"#,
);
}
9 changes: 9 additions & 0 deletions crates/hir_ty/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ pub(super) fn associated_type_by_name_including_super_traits(

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

Expand Down