diff --git a/src/refine.rs b/src/refine.rs index 5a1fd8d3..8669cda4 100644 --- a/src/refine.rs +++ b/src/refine.rs @@ -33,7 +33,7 @@ fn stable_def_id_symbol(tcx: mir_ty::TyCtxt<'_>, did: DefId) -> String { } pub fn datatype_symbol(tcx: mir_ty::TyCtxt<'_>, did: DefId) -> DatatypeSymbol { - DatatypeSymbol::new(tcx.def_path_str(did).replace("::", ".")) + DatatypeSymbol::new(stable_def_id_symbol(tcx, did)) } pub fn user_defined_pred(tcx: mir_ty::TyCtxt<'_>, did: DefId) -> UserDefinedPred { diff --git a/tests/ui/fail/enum_local_in_trait_impl.rs b/tests/ui/fail/enum_local_in_trait_impl.rs new file mode 100644 index 00000000..eccd3611 --- /dev/null +++ b/tests/ui/fail/enum_local_in_trait_impl.rs @@ -0,0 +1,56 @@ +//@error-in-other-file: Unsat +//@compile-flags: -C debug-assertions=off + +trait T { + fn f(b: bool) -> i64; +} + +struct A; +struct B; + +impl thrust_models::Model for A { + type Ty = Self; +} + +impl thrust_models::Model for B { + type Ty = Self; +} + +impl T for A { + fn f(b: bool) -> i64 { + enum E { + X(i64), + Y, + } + impl thrust_models::Model for E { + type Ty = Self; + } + let e = if b { E::X(1) } else { E::Y }; + match e { + E::X(x) => x, + E::Y => 0, + } + } +} + +impl T for B { + fn f(b: bool) -> i64 { + enum E { + Z(bool), + W(i64), + } + impl thrust_models::Model for E { + type Ty = Self; + } + let e = if b { E::Z(true) } else { E::W(5) }; + match e { + E::Z(_) => 10, + E::W(v) => v, + } + } +} + +fn main() { + assert!(A::f(true) == 1); + assert!(B::f(false) == 10); +} diff --git a/tests/ui/pass/enum_local_in_trait_impl.rs b/tests/ui/pass/enum_local_in_trait_impl.rs new file mode 100644 index 00000000..a2644a07 --- /dev/null +++ b/tests/ui/pass/enum_local_in_trait_impl.rs @@ -0,0 +1,56 @@ +//@check-pass +//@compile-flags: -C debug-assertions=off + +trait T { + fn f(b: bool) -> i64; +} + +struct A; +struct B; + +impl thrust_models::Model for A { + type Ty = Self; +} + +impl thrust_models::Model for B { + type Ty = Self; +} + +impl T for A { + fn f(b: bool) -> i64 { + enum E { + X(i64), + Y, + } + impl thrust_models::Model for E { + type Ty = Self; + } + let e = if b { E::X(1) } else { E::Y }; + match e { + E::X(x) => x, + E::Y => 0, + } + } +} + +impl T for B { + fn f(b: bool) -> i64 { + enum E { + Z(bool), + W(i64), + } + impl thrust_models::Model for E { + type Ty = Self; + } + let e = if b { E::Z(true) } else { E::W(5) }; + match e { + E::Z(_) => 10, + E::W(v) => v, + } + } +} + +fn main() { + assert!(A::f(true) == 1); + assert!(B::f(false) == 5); +}