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

analyze: fix deconstruct_hir_ty adt/path case #1023

Merged
merged 1 commit into from
Sep 8, 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: 4 additions & 1 deletion c2rust-analyze/src/rewrite/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,10 @@ fn deconstruct_hir_ty<'a, 'tcx>(
}
}

(&ty::TyKind::Adt(adt_def, substs), &hir::TyKind::Path(..)) => {
(
&ty::TyKind::Adt(adt_def, substs),
&hir::TyKind::Path(hir::QPath::Resolved(_, ref path)),
) if path.res.def_id() == adt_def.did() => {
hir_generic_ty_args(hir_ty).map(|type_args| {
if type_args.len() < substs.types().count() {
// this situation occurs when there are hidden type arguments
Expand Down
1 change: 1 addition & 0 deletions c2rust-analyze/tests/filecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ define_tests! {
statics,
test_attrs,
trivial,
type_alias,
type_annotation_rewrite,
unrewritten_calls,
unrewritten_calls_shim_fail,
Expand Down
11 changes: 11 additions & 0 deletions c2rust-analyze/tests/filecheck/type_alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Regression test: previously, type aliases for `Option<*const T>` caused a panic, as
// `deconstruct_hir_ty` would match the HIR alias with the MIR type `Option<T>` and then get
// confused due to the mismatched number of type arguments.
type AliasOption = Option<*const u8>;

// CHECK: struct UseAliasOption<'h0>
struct UseAliasOption {
// FIXME: should be `Option<&'h0 u8>`
// CHECK: x: std::option::Option<&u8>
x: AliasOption,
}