Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Jun 7, 2024
1 parent 72cbb8b commit 9461852
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tests/ui-fulldeps/stable-mir/check_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn test_stable_mir() -> ControlFlow<()> {
// Get all items and split generic vs monomorphic items.
let (generic, mono): (Vec<_>, Vec<_>) =
items.into_iter().partition(|item| item.requires_monomorphization());
assert_eq!(mono.len(), 3, "Expected 2 mono functions and one constant");
assert_eq!(mono.len(), 4, "Expected 2 mono functions and one constant");
assert_eq!(generic.len(), 2, "Expected 2 generic functions");

// For all monomorphic items, get the correspondent instances.
Expand All @@ -57,8 +57,9 @@ fn test_body(body: mir::Body) {
for term in body.blocks.iter().map(|bb| &bb.terminator) {
match &term.kind {
Call { func, .. } => {
let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else { unreachable!
() };
let TyKind::RigidTy(ty) = func.ty(body.locals()).unwrap().kind() else {
unreachable!()
};
let RigidTy::FnDef(def, args) = ty else { unreachable!() };
let instance = Instance::resolve(def, &args).unwrap();
let mangled_name = instance.mangled_name();
Expand Down Expand Up @@ -102,6 +103,9 @@ fn generate_input(path: &str) -> std::io::Result<()> {
write!(
file,
r#"
struct Foo(());
pub fn ty_param<T>(t: &T) -> T where T: Clone {{
t.clone()
}}
Expand All @@ -116,6 +120,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
}}
pub fn monomorphic() {{
Foo(());
let v = vec![10];
let dup = ty_param(&v);
assert_eq!(v, dup);
Expand Down

0 comments on commit 9461852

Please sign in to comment.