From 82af6d6c2fdfeac83c52b752557ffe766673d42b Mon Sep 17 00:00:00 2001 From: Stuart Pernsteiner Date: Tue, 29 Aug 2023 15:18:31 -0700 Subject: [PATCH] analyze: fix deconstruct_hir_ty adt/path case --- c2rust-analyze/src/rewrite/ty.rs | 5 ++++- c2rust-analyze/tests/filecheck.rs | 1 + c2rust-analyze/tests/filecheck/type_alias.rs | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 c2rust-analyze/tests/filecheck/type_alias.rs diff --git a/c2rust-analyze/src/rewrite/ty.rs b/c2rust-analyze/src/rewrite/ty.rs index ef3552316d..d8ead346ec 100644 --- a/c2rust-analyze/src/rewrite/ty.rs +++ b/c2rust-analyze/src/rewrite/ty.rs @@ -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 diff --git a/c2rust-analyze/tests/filecheck.rs b/c2rust-analyze/tests/filecheck.rs index f3cdfc2ede..1d5a2ce118 100644 --- a/c2rust-analyze/tests/filecheck.rs +++ b/c2rust-analyze/tests/filecheck.rs @@ -61,6 +61,7 @@ define_tests! { statics, test_attrs, trivial, + type_alias, type_annotation_rewrite, unrewritten_calls, unrewritten_calls_shim_fail, diff --git a/c2rust-analyze/tests/filecheck/type_alias.rs b/c2rust-analyze/tests/filecheck/type_alias.rs new file mode 100644 index 0000000000..a8aea0c9a4 --- /dev/null +++ b/c2rust-analyze/tests/filecheck/type_alias.rs @@ -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` 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, +}