Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Positive coverage: prove_predicate / trait well formed

trait well formed
LineCoverageSource
1361(for_all(decls, env, assumptions, &trait_ref.parameters, &prove_wf) => c)
137N/A(let t = decls.trait_decl(&trait_ref.trait_id))
138N/A(let t = t.binder.instantiate_with(&trait_ref.parameters).unwrap())
1392(prove_after(decls, c, assumptions, &t.where_clause) => c)
──────── ("trait well formed")
14149(prove_predicate(decls, env, assumptions, AtomicPredicate::WellFormedTraitRef(trait_ref)) => c)

49 tests exercised this rule:


Source location: tests/basic_tests.rs:58 (all coverage from this test)

#[test]
fn hello_world() {
    FormalityTest::new(crates![crate Foo {
        trait Foo<T> where T: Bar<Self>, Self: Baz {}

        trait Bar<T> where T: Baz {}

        trait Baz {}

        impl Baz for u32 {}

        impl Bar<u32> for u32 {}
        impl<T> Bar<T> for () where T: Baz {}
    }])
    .skip_execute()
    .ok()
}
Proof tree
… (200 of 1573 nodes shown)

Source location: tests/basic_tests.rs:74 (all coverage from this test)

#[test]
fn basic_where_clauses_pass() {
    FormalityTest::new(crates![crate core {
        #![feature(non_lifetime_binders)]
        trait A<T> where T: B { }

        trait B { }

        trait WellFormed where for<T> u32: A<T> { }

        impl <T> B for T {}
    }])
    .skip_execute()
    .ok()
}
Proof tree

Source location: tests/basic_tests.rs:121 (all coverage from this test)

fn foo() -> () where for<T> u32: A<T> { trusted }

impl <T> B for T {}
}])
p_execute()
)
}

#[test]
ifetime_binder_in_fn_where_clause_fail() {
alityTest::new(crates![crate core {
trait A<T> where T: B { }

trait B { }

fn foo() -> () where for<T> u32: A<T> { trusted }
}])
(expect_test::expect![[r#"
the rule "check crate" at (mod.rs) failed because
  non lifetime binders require #![feature(non_lifetime_binders)]"#]])
}

#[test]
ifetime_binder_in_trait_impl_where_clause_pass() {
alityTest::new(crates![crate core {
#![feature(non_lifetime_binders)]
trait A<T> where T: B { }

trait B { }

impl<T> B for T where for<U> u32: A<U> { }
}])
p_execute()
)
}

#[test]
ifetime_binder_in_trait_impl_where_clause_fail() {
alityTest::new(crates![crate core {
trait A<T> where T: B { }

trait B { }

impl<T> B for T where for<U> u32: A<U> { }
}])
(expect_test::expect![[r#"
the rule "check crate" at (mod.rs) failed because
  non lifetime binders require #![feature(non_lifetime_binders)]"#]])
}

#[test]
ifetime_binder_in_neg_trait_impl_where_clause_pass() {
alityTest::new(crates![crate core {
#![feature(non_lifetime_binders)]
trait A<T> where T: B { }

trait B { }

impl<T> !A<T> for u32 where for<U> u32: A<U> { }

impl <T> B for T {}
}])
p_execute()
)
}

#[test]
ifetime_binder_in_neg_trait_impl_where_clause_fail() {
alityTest::new(crates![crate core {
trait A<T> where T: B { }

trait B { }

impl<T> !A<T> for u32 where for<U> u32: A<U> { }
}])
(expect_test::expect![[r#"
the rule "check crate" at (mod.rs) failed because
  non lifetime binders require #![feature(non_lifetime_binders)]"#]])
}

#[test]
ifetime_binder_in_enum_where_clause_pass() {
alityTest::new(crates![crate core {
#![feature(non_lifetime_binders)]
trait A<T> where T: B { }

trait B { }

enum E where for<U> u32: A<U> { }

impl <T> B for T {}
}])
p_execute()
)
}

#[test]
ifetime_binder_in_enum_where_clause_fail() {
alityTest::new(crates![crate core {
trait A<T> where T: B { }

trait B { }

enum E where for<U> u32: A<U> { }
}])
(expect_test::expect![[r#"
the rule "check crate" at (mod.rs) failed because
  non lifetime binders require #![feature(non_lifetime_binders)]"#]])
}

#[test]
ifetime_binder_in_struct_where_clause_pass() {
alityTest::new(crates![crate core {
#![feature(non_lifetime_binders)]
trait A<T> where T: B { }

trait B { }

struct S<T> where for<U> u32: A<U> { }

impl <T> B for T {}
}])
p_execute()
)
}

#[test]
ifetime_binder_in_struct_where_clause_fail() {
alityTest::new(crates![crate core {
trait A<T> where T: B { }

trait B { }

struct S<T> where for<U> u32: A<U> { }
}])
(expect_test::expect![[r#"
the rule "check crate" at (mod.rs) failed because
  non lifetime binders require #![feature(non_lifetime_binders)]"#]])
}

#[test]
ime_binder_in_where_clause_without_feature_pass() {
alityTest::new(crates![crate core {
trait A<'b> { }

impl<'b> A<'b> for u32 { }

trait WellFormed where for<'b> u32: A<'b> { }
}])
p_execute()
)
}

#[test]
_adt_variant_dup() {
alityTest::new(crates![crate Foo {
enum Bar {
    Baz{},
    Baz{},
}
Proof tree

Source location: tests/basic_tests.rs:149 (all coverage from this test)

#[test]
fn non_lifetime_binder_in_trait_impl_where_clause_pass() {
    FormalityTest::new(crates![crate core {
        #![feature(non_lifetime_binders)]
        trait A<T> where T: B { }

        trait B { }

        impl<T> B for T where for<U> u32: A<U> { }
    }])
    .skip_execute()
    .ok()
}
Proof tree

Source location: tests/basic_tests.rs:179 (all coverage from this test)

#[test]
fn non_lifetime_binder_in_neg_trait_impl_where_clause_pass() {
    FormalityTest::new(crates![crate core {
        #![feature(non_lifetime_binders)]
        trait A<T> where T: B { }

        trait B { }

        impl<T> !A<T> for u32 where for<U> u32: A<U> { }

        impl <T> B for T {}
    }])
    .skip_execute()
    .ok()
}
Proof tree

Source location: tests/basic_tests.rs:209 (all coverage from this test)

#[test]
fn non_lifetime_binder_in_enum_where_clause_pass() {
    FormalityTest::new(crates![crate core {
        #![feature(non_lifetime_binders)]
        trait A<T> where T: B { }

        trait B { }

        enum E where for<U> u32: A<U> { }

        impl <T> B for T {}
    }])
    .skip_execute()
    .ok()
}
Proof tree

Source location: tests/basic_tests.rs:239 (all coverage from this test)

#[test]
fn non_lifetime_binder_in_struct_where_clause_pass() {
    FormalityTest::new(crates![crate core {
        #![feature(non_lifetime_binders)]
        trait A<T> where T: B { }

        trait B { }

        struct S<T> where for<U> u32: A<U> { }

        impl <T> B for T {}
    }])
    .skip_execute()
    .ok()
}
Proof tree

Source location: tests/basic_tests.rs:266 (all coverage from this test)

#[test]
fn lifetime_binder_in_where_clause_without_feature_pass() {
    FormalityTest::new(crates![crate core {
        trait A<'b> { }

        impl<'b> A<'b> for u32 { }

        trait WellFormed where for<'b> u32: A<'b> { }
    }])
    .skip_execute()
    .ok()
}
Proof tree

Source location: tests/codegen.rs:628 (all coverage from this test)

fn main() -> () {
    println!(identity::<S>(7_u32));
}
Proof tree
… (200 of 1508 nodes shown)

Source location: tests/codegen.rs:927 (all coverage from this test)

fn main() -> () {
    println!(identity::<Number>(7_u32));
    println!(identity::<Flag>(true));
    println!(identity::<Number>(9_u32));
}
Proof tree
… (200 of 1710 nodes shown)

Source location: tests/coherence_overlap.rs:237 (all coverage from this test)

#[test]
fn neg_CoreTrait_for_CoreStruct_implies_no_overlap() {
    FormalityTest::new(crates![crate core {
        #![feature(negative_impls)]
        trait CoreTrait {}
        struct CoreStruct {}
        impl !CoreTrait for CoreStruct {}
    },
    crate foo {
        trait FooTrait {}
        impl<T> FooTrait for T where T: CoreTrait {}
        impl FooTrait for CoreStruct {}
    }])
    .skip_execute()
    .ok()
}

Proof trees omitted for the remaining 39 tests; each one is on its test’s page in Coverage by test.


Source location: tests/coherence_overlap.rs:322 (all coverage from this test)

#[test]
fn u32_T_where_T_Not_impls() {
    FormalityTest::new(crates![crate core {
        trait Foo {}
        impl Foo for u32 {}
        impl<T> Foo for T where T: Not {}

        trait Not {}
    }])
    .skip_execute()
    .ok()
}

Source location: tests/coherence_overlap.rs:587 (all coverage from this test)

#[test]
fn is_local_unknowable_trait_ref() {
    FormalityTest::new(crates![crate core {
        trait Project {
            type Assoc: [];
        }

        impl<T> Project for T {
            type Assoc = T;
        }

        trait Foo<U> { }
    },
    crate foo {
        struct LocalType {}

        trait Overlap<U> {}
        impl<T, U> Overlap<U> for T
        where
            <T as Project>::Assoc: Foo<U> {}
        impl<T> Overlap<LocalType> for () {}
    }])
    .skip_execute()
    .ok()
}

Source location: tests/drop.rs:43 (all coverage from this test)


Source location: tests/higher_ranked_where_clauses.rs:12 (all coverage from this test)

fn foo<T>() -> () where for<'a> T: Trait<'a> {}
}])
p_execute()
tc_ok()
);
}

#[test]
ait_bound_at_body_lifetime() {
alityTest::new(crates![crate Foo {
trait Trait<'a> {}
fn needs_one<'x, T>() -> () where T: Trait<'x> {}
fn foo<T>() -> () where for<'a> T: Trait<'a> {
    exists<'r> {
        needs_one::<'r, T>();
    }
}

Source location: tests/higher_ranked_where_clauses.rs:28 (all coverage from this test)

fn foo<T>() -> () where for<'a> T: Trait<'a> {
    exists<'r> {
        needs_one::<'r, T>();
    }
}

Source location: tests/higher_ranked_where_clauses.rs:42 (all coverage from this test)

fn foo<'b, T>() -> () where for<'a> T: Trait<'a> {
    needs_one::<'b, T>();
}

Source location: tests/higher_ranked_where_clauses.rs:56 (all coverage from this test)

fn foo<T>() -> () where for<'a> T: Trait<'a> {
    needs_all::<T>();
}

Source location: tests/higher_ranked_where_clauses.rs:118 (all coverage from this test)

fn foo<T>() -> u32 where for<'a> T: Trait<'a> {
    let v: u32 = 1_u32;
    exists<'r> {
        let r: &'r u32 = first::<'r, T>(&'r v);
        let n: u32 = *r;
        v = 2_u32;
        return n;
    }
}

Source location: tests/mir_typeck.rs:987 (all coverage from this test)

fn foo<'a, T>(v1: &'a T) -> T
where
    T: Copy,
    T: 'a,
{
    exists<'r0> {
        let v2: T = *v1;
        return v2;
    }
}

Source location: tests/mir_typeck.rs:1883 (all coverage from this test)

fn main() -> () { require_marker::<u32>; }
}])
tc_ok()
);
}

#[test]
fn_value_with_forwarded_trait_bound() {
alityTest::new(crates![crate Foo {
trait Marker {}
impl Marker for u32 {}
fn require<T>() -> () where T: Marker {}
fn outer<T>() -> () where T: Marker { require::<T>; }
fn main() -> () { outer::<u32>(); }
}])
tc_ok()
);
}

#[test]
bare_fn_value_with_satisfied_where_clause() {
alityTest::new(crates![crate Foo {
trait Marker {}
impl Marker for u32 {}
fn require() -> () where u32: Marker {}
fn main() -> () { require; }
}])
tc_ok()
);
}

#[test]
fn_value_with_forwarded_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () where 'a: 'b { require::<'a, 'b>; }
fn main() -> () { outer::<'static, 'static>(); }
}])
tc_ok()
);
}

#[test]
fn_value_with_unsatisfied_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () { require::<'a, 'b>; }
fn main() -> () {}
}])
tc_err(expect_test::expect![[r#"
error: lifetime may not live long enough
 --> lib.rs
  |
7 | pub fn outer<'a00, 'a01>() -> () {
  |              ----  ---- lifetime `'a01` defined here
  |              |
  |              lifetime `'a00` defined here
8 |     require::<'a00, 'a01>;
  |     ^^^^^^^^^^^^^^^^^^^^^ requires that `'a00` must outlive `'a01`
  |
  = help: consider adding the following bound: `'a00: 'a01`

error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect!["crates/formality-rust/src/prove/prove_outlives.rs:8:1: no applicable rules for prove_outlives { a: !lt_0, b: !lt_1, assumptions: {}, env: Env { variables: [!lt_0, !lt_1], bias: Soundness, pending: [], allow_pending_outlives: false } }"]);
}

ound assignment of an integer of a different type should fail.
#[test]
compound_add_mismatched_int_types() {
alityTest::new(crates![crate Foo {
fn foo() -> () {
    let x: u32 = 1_u32;
    x += 2_u8;
}

Source location: tests/mir_typeck.rs:1896 (all coverage from this test)

fn main() -> () { outer::<u32>(); }
}])
tc_ok()
);
}

#[test]
bare_fn_value_with_satisfied_where_clause() {
alityTest::new(crates![crate Foo {
trait Marker {}
impl Marker for u32 {}
fn require() -> () where u32: Marker {}
fn main() -> () { require; }
}])
tc_ok()
);
}

#[test]
fn_value_with_forwarded_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () where 'a: 'b { require::<'a, 'b>; }
fn main() -> () { outer::<'static, 'static>(); }
}])
tc_ok()
);
}

#[test]
fn_value_with_unsatisfied_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () { require::<'a, 'b>; }
fn main() -> () {}
}])
tc_err(expect_test::expect![[r#"
error: lifetime may not live long enough
 --> lib.rs
  |
7 | pub fn outer<'a00, 'a01>() -> () {
  |              ----  ---- lifetime `'a01` defined here
  |              |
  |              lifetime `'a00` defined here
8 |     require::<'a00, 'a01>;
  |     ^^^^^^^^^^^^^^^^^^^^^ requires that `'a00` must outlive `'a01`
  |
  = help: consider adding the following bound: `'a00: 'a01`

error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect!["crates/formality-rust/src/prove/prove_outlives.rs:8:1: no applicable rules for prove_outlives { a: !lt_0, b: !lt_1, assumptions: {}, env: Env { variables: [!lt_0, !lt_1], bias: Soundness, pending: [], allow_pending_outlives: false } }"]);
}

ound assignment of an integer of a different type should fail.
#[test]
compound_add_mismatched_int_types() {
alityTest::new(crates![crate Foo {
fn foo() -> () {
    let x: u32 = 1_u32;
    x += 2_u8;
}

Source location: tests/mir_typeck.rs:1908 (all coverage from this test)

fn main() -> () { require; }
}])
tc_ok()
);
}

#[test]
fn_value_with_forwarded_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () where 'a: 'b { require::<'a, 'b>; }
fn main() -> () { outer::<'static, 'static>(); }
}])
tc_ok()
);
}

#[test]
fn_value_with_unsatisfied_lifetime_bound() {
alityTest::new(crates![crate Foo {
fn require<'a, 'b>() -> () where 'a: 'b {}
fn outer<'a, 'b>() -> () { require::<'a, 'b>; }
fn main() -> () {}
}])
tc_err(expect_test::expect![[r#"
error: lifetime may not live long enough
 --> lib.rs
  |
7 | pub fn outer<'a00, 'a01>() -> () {
  |              ----  ---- lifetime `'a01` defined here
  |              |
  |              lifetime `'a00` defined here
8 |     require::<'a00, 'a01>;
  |     ^^^^^^^^^^^^^^^^^^^^^ requires that `'a00` must outlive `'a01`
  |
  = help: consider adding the following bound: `'a00: 'a01`

error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect!["crates/formality-rust/src/prove/prove_outlives.rs:8:1: no applicable rules for prove_outlives { a: !lt_0, b: !lt_1, assumptions: {}, env: Env { variables: [!lt_0, !lt_1], bias: Soundness, pending: [], allow_pending_outlives: false } }"]);
}

ound assignment of an integer of a different type should fail.
#[test]
compound_add_mismatched_int_types() {
alityTest::new(crates![crate Foo {
fn foo() -> () {
    let x: u32 = 1_u32;
    x += 2_u8;
}

Source location: tests/mir_typeck.rs:2160 (all coverage from this test)

fn main() -> () {
    let v0: u32 = 0_u32;
    exists<'r> {
        let v1: &'r u32 = &'r v0;
        needs_all::<&'r u32>(v1);
        v0 = 1_u32;
    }
}

Source location: tests/mir_typeck.rs:2176 (all coverage from this test)

fn caller<'x>(v: &'x u32) -> () where 'x: 'static {
    needs_all::<&'x u32>(v);
}

Source location: tests/outlives.rs:65 (all coverage from this test)

fn f<'a, T>() -> () where T: A, <T as A>::Item: 'a { trusted }
}])
p_execute()
tc_ok()
);
}

aller can use its projection outlives assumption to satisfy a callee's bound.
er function takes a reference that could imply the bound independently.
#[test]
uses_projection_outlives_bound() {
alityTest::new(crates![crate Foo {
trait A { type Item: []; }

fn needs_outlives<'a, T>() -> () where T: A, <T as A>::Item: 'a { trusted }

fn caller<'a, T>() -> () where T: A, <T as A>::Item: 'a {
    needs_outlives::<'a, T>();
}

Source location: tests/outlives.rs:83 (all coverage from this test)

fn caller<'a, T>() -> () where T: A, <T as A>::Item: 'a {
    needs_outlives::<'a, T>();
}

Source location: tests/references.rs:36 (all coverage from this test)


Source location: tests/sized_trait.rs:18 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
)
}

#[test]
less_struct_is_sized() {
alityTest::new(crates![crate Foo {
struct S {}
trait Needs<T> where T: Sized {}
impl Needs<S> for u32 {}
fn main() -> () {}
}])
tc_ok()
)
}

#[test]
lue_trait_param_with_sized_bound_compiles_with_rustc() {
alityTest::new(crates![crate Foo {
fn consume<T>(value: T) -> () where T: Sized {}

trait Consumer<T> where T: Sized {
    fn consume_value(value: T) -> () {}
}

Source location: tests/sized_trait.rs:30 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
)
}

#[test]
lue_trait_param_with_sized_bound_compiles_with_rustc() {
alityTest::new(crates![crate Foo {
fn consume<T>(value: T) -> () where T: Sized {}

trait Consumer<T> where T: Sized {
    fn consume_value(value: T) -> () {}
}

Source location: tests/sized_trait.rs:44 (all coverage from this test)

fn main() -> () { consume::<u32>(22_u32); }
}])
tc_ok()
)
}

#[test]
d_reference_is_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<'a, T> Needs<&'a T> for u32 where T: 'a {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
le_reference_is_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<'a, T> Needs<&'a mut T> for u32 where T: 'a {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_sized_bound_is_forwarded() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_parameter_requires_explicit_sized_bound() {
enerated Rust still gives T an implicit Sized bound until #500 lands.
ormality must already require an explicit bound on this impl.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
defined_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
struct S {}
impl Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
3 | impl Sized for S {}
  | ^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
defined_negative_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
#![feature(negative_impls)]
struct S {}
impl !Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
5 | impl !Sized for S {}
  | ^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
ointers_are_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<*const T> for u32 {}
impl<T> Needs<*mut T> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
and_tuples_of_sized_types_are_sized() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl Needs<()> for u32 {}
impl<T> Needs<(T, bool)> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
_requires_every_element_sized() {
n rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<(T, bool)> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_with_generic_tail_is_sized_if_tail_is() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:55 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
le_reference_is_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<'a, T> Needs<&'a mut T> for u32 where T: 'a {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_sized_bound_is_forwarded() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_parameter_requires_explicit_sized_bound() {
enerated Rust still gives T an implicit Sized bound until #500 lands.
ormality must already require an explicit bound on this impl.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
defined_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
struct S {}
impl Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
3 | impl Sized for S {}
  | ^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
defined_negative_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
#![feature(negative_impls)]
struct S {}
impl !Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
5 | impl !Sized for S {}
  | ^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
ointers_are_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<*const T> for u32 {}
impl<T> Needs<*mut T> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
and_tuples_of_sized_types_are_sized() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl Needs<()> for u32 {}
impl<T> Needs<(T, bool)> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
_requires_every_element_sized() {
n rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<(T, bool)> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_with_generic_tail_is_sized_if_tail_is() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:66 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_sized_bound_is_forwarded() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_parameter_requires_explicit_sized_bound() {
enerated Rust still gives T an implicit Sized bound until #500 lands.
ormality must already require an explicit bound on this impl.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
defined_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
struct S {}
impl Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
3 | impl Sized for S {}
  | ^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
defined_negative_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
#![feature(negative_impls)]
struct S {}
impl !Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
5 | impl !Sized for S {}
  | ^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
ointers_are_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<*const T> for u32 {}
impl<T> Needs<*mut T> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
and_tuples_of_sized_types_are_sized() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl Needs<()> for u32 {}
impl<T> Needs<(T, bool)> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
_requires_every_element_sized() {
n rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<(T, bool)> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_with_generic_tail_is_sized_if_tail_is() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:77 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ic_parameter_requires_explicit_sized_bound() {
enerated Rust still gives T an implicit Sized bound until #500 lands.
ormality must already require an explicit bound on this impl.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<T> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
defined_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
struct S {}
impl Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
3 | impl Sized for S {}
  | ^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
defined_negative_sized_impl_is_rejected() {
alityTest::new(crates![crate Foo {
#![feature(negative_impls)]
struct S {}
impl !Sized for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0322]: explicit impls for the `Sized` trait are not permitted
 --> lib.rs
  |
5 | impl !Sized for S {}
  | ^^^^^^^^^^^^^^^^^ impl of `Sized` not allowed

For more information about this error, try `rustc --explain E0322`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "Sized" at (impls.rs) failed because
  explicit impls for the `Sized` trait are not permitted"#]]);
}

#[test]
ointers_are_sized_without_pointee_bound() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<*const T> for u32 {}
impl<T> Needs<*mut T> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
and_tuples_of_sized_types_are_sized() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl Needs<()> for u32 {}
impl<T> Needs<(T, bool)> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
_requires_every_element_sized() {
n rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<(T, bool)> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_with_generic_tail_is_sized_if_tail_is() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:151 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
and_tuples_of_sized_types_are_sized() {
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl Needs<()> for u32 {}
impl<T> Needs<(T, bool)> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
_requires_every_element_sized() {
n rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<(T, bool)> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_with_generic_tail_is_sized_if_tail_is() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:163 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
_requires_every_element_sized() {
n rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
alityTest::new(crates![crate Foo {
trait Needs<T> where T: Sized {}
impl<T> Needs<(T, bool)> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_with_generic_tail_is_sized_if_tail_is() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:196 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
t_with_generic_tail_requires_sized_tail() {
Tail<T>` is only sized if `T` is.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
trait Needs<T> where T: Sized {}
impl<T> Needs<Tail<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_non_final_field_is_accepted() {
alityTest::new(crates![crate Foo {
struct Good<T> where T: Sized { prefix: T, tail: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:228 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_non_final_field_is_rejected() {
nly the last field of a struct can be unsized.
alityTest::new(crates![crate Foo {
struct Bad<T> { prefix: T, tail: u32 }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_fields_is_sized() {
alityTest::new(crates![crate Foo {
enum Maybe<T> where T: Sized { Just { value: T }, Nothing {} }
trait Needs<T> where T: Sized {}
impl<T> Needs<Maybe<T>> for u32 where T: Sized {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:254 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ed_enum_field_is_rejected() {
num fields must all be sized, even the last one.
alityTest::new(crates![crate Foo {
enum Maybe<T> { Nothing {}, Just { value: T } }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_sized_if_normalized_type_is() {
alityTest::new(crates![crate Foo {
trait Assoc { type Out: []; }
impl Assoc for u32 { type Out = bool; }
trait Needs<T> where T: Sized {}
impl Needs<<u32 as Assoc>::Out> for u32 {}
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:281 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
ction_non_final_field_with_sized_bound_is_accepted() {
he solver ignores bounds on associated types, so `type A: [Sized]` wouldn't help.
alityTest::new(crates![crate Foo {
trait Tr { type A: []; }
struct S<T> where T: Tr, <T as Tr>::A: Sized { a: <T as Tr>::A, b: u32 }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:293 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
et_impl_for_sized_types_overlaps_with_impl_for_struct() {
S` is sized, so both impls apply to it.
alityTest::new(crates![crate Foo {
trait Foo {}
struct S {}
impl<T> Foo for T where T: Sized {}
impl Foo for S {}
}])
tc_err(expect_test::expect![[r#"
error[E0119]: conflicting implementations of trait `Foo` for type `S`
 --> lib.rs
  |
5 | impl<T00> Foo for T00 where T00: Sized {}
  | -------------------------------------- first implementation here
6 |
7 | impl Foo for S {}
  | ^^^^^^^^^^^^^^ conflicting implementation for `S`

For more information about this error, try `rustc --explain E0119`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "different trait" at (coherence.rs) failed because
  condition evaluated to false: `impl_a.trait_id() != impl_b.trait_id()`

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: !ty_0 = S, assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

crates/formality-rust/src/prove/prove_via.rs:9:1: no applicable rules for prove_via { goal: ! Sized(!ty_0), via: Sized(!ty_0), assumptions: {!ty_0 = S, Sized(!ty_0)}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "negative impl" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.neg_impl_decls(&trait_ref.trait_id)`

the rule "not goal" at (coherence.rs) failed because
  failed to prove {!ty_1 = S, Sized(!ty_1)} given {}, got [Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: false, substitution: {} }]

the rule "same impl" at (coherence.rs) failed because
  condition evaluated to false: `impl_a == impl_b`
    impl_a = impl <ty> Foo for ^ty0_0 where ^ty0_0 : Sized { }
    impl_b = impl Foo for S { }"#]]);
}

#[test]
t_tail_is_checked_after_substitution() {
Pair<u32, X>` ends in `X`, which may be unsized.
alityTest::new(crates![crate Foo {
struct Pair<A, B> where A: Sized { first: A, last: B }
trait Needs<T> where T: Sized {}
impl<X> Needs<Pair<u32, X>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
t_tail_is_followed_through_nested_structs() {
Outer<T>` ends in `Tail<T>`, which ends in `T`.
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
trait Needs<T> where T: Sized {}
impl<T> Needs<Outer<T>> for u32 {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
_is_not_sized_if_normalized_type_may_be_unsized() {
<T as Assoc>::Out` normalizes to `T`, which may be unsized.
alityTest::new(crates![crate Foo {
struct W<T> { t: T }
trait Assoc { type Out: []; }
impl<T> Assoc for T { type Out = T; }
trait Needs<T> where T: Sized {}
impl<T> Needs<<T as Assoc>::Out> for W<T> {}
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: false } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
sive_struct_is_not_sized() {
Sized` is inductive, so the cycle through `next` doesn't prove `List: Sized`.
ustc rejects the struct itself (E0072), which formality doesn't check.
alityTest::new(crates![crate Foo {
struct List { next: List }
trait Needs<T> where T: Sized {}
impl Needs<List> for u32 {}
}])
tc_err(expect_test::expect![[r#"
error[E0072]: recursive type `List` has infinite size
 --> lib.rs
  |
1 | pub struct List {
  | ^^^^^^^^^^^^^^^
2 |     pub next: List,
  |               ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
2 |     pub next: Box<List>,
  |               ++++    +

For more information about this error, try `rustc --explain E0072`.
error: could not compile `Foo` (lib) due to 1 previous error
)
(expect_test::expect![[r#"
the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

#[test]
with_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () where T: Sized { consume::<Tail<T>>(value); }
fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:453 (all coverage from this test)

fn main() -> () {}
}])
tc_ok()
);
}

#[test]
requires_sized_struct_argument() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
fn consume<T>(value: T) -> () where T: Sized {}
fn forward<T>(value: Tail<T>) -> () { consume::<Tail<T>>(value); }
}])
tc_ok()
(expect_test::expect![[r#"
crates/formality-rust/src/prove/prove_sized.rs:12:1: no applicable rules for prove_sized { ty: !ty_0, assumptions: {}, env: Env { variables: [!ty_0], bias: Soundness, pending: [], allow_pending_outlives: true } }

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`

the rule "trait implied bound" at (prove_predicate.rs) failed because
  expression evaluated to an empty collection: `decls.trait_invariants()`"#]]);
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_nonfinal_struct_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
struct S<T> where T: Tr { first: <T as Tr>::A, last: u32 }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

 #540: use the associated-type Sized bound; remove should_panic when fixed.
#[test]
_panic(expected = "prove_sized { ty: <!ty_0 as Tr>::A")]
iated_sized_bound_allows_enum_field() {
program = crates![crate Foo {
trait Tr { type A: [Sized]; }
enum E<T> where T: Tr { Some { value: <T as Tr>::A }, None {} }
fn main() -> () {}
}];
heck rustc before the expected formality failure.
(ok, stderr) = formality_rust::to_rust::test_util::run_rustc(&program);
rt!(ok, "{stderr}");
alityTest::new(program).rustc_ok().ok();
}

#[test]
d_struct_sized_bound_executes() {
alityTest::new(crates![crate Foo {
struct Tail<T> { prefix: u32, tail: T }
struct Outer<T> { inner: Tail<T> }
fn consume<T>(value: T) -> u32 where T: Sized { return 7_u32; }
fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/sized_trait.rs:518 (all coverage from this test)

fn main() -> () {
    println!(consume::<Outer<u32>>(Outer::<u32> {
        inner: Tail::<u32> { prefix: 1_u32, tail: 2_u32 }
    }));
}

Source location: tests/traits.rs:11 (all coverage from this test)

fn main() -> () { require_copy::<i128>(); }
}])
p_execute()
tc_ok()
);
}

#[test]
is_copy() {
alityTest::new(crates![crate test {
fn require_copy<T>() -> () where T: Copy { trusted }
fn main() -> () { require_copy::<u128>(); }
}])
p_execute()
tc_ok()
);
}

#[test]
_with_valid_fn() {
alityTest::new(crates![
crate core {
    trait A {
        fn a() -> ();
    }
}

Source location: tests/traits.rs:22 (all coverage from this test)

fn main() -> () { require_copy::<u128>(); }
}])
p_execute()
tc_ok()
);
}

#[test]
_with_valid_fn() {
alityTest::new(crates![
crate core {
    trait A {
        fn a() -> ();
    }
}

Source location: tests/well_formed_trait_ref.rs:19 (all coverage from this test)

#[test]
fn dependent_where_clause() {
    FormalityTest::new(crates![crate foo {
        trait Trait1 {}

        trait Trait2 {}

        struct S1<T> where T: Trait1 {
            dummy: T,
        }

        struct S2<T> where T: Trait1, S1<T> : Trait2 {
            dummy: T,
        }
    }])
    .skip_execute()
    .ok()
}

Source location: tests/well_formed_trait_ref.rs:56 (all coverage from this test)

#[test]
fn lifetime_param() {
    FormalityTest::new(crates![crate foo {
        trait Trait1<'a> {}

        struct S1 {}

        struct S2<'a> where S1: Trait1<'a> {}
    }])
    .skip_execute()
    .ok()
}

Source location: tests/well_formed_trait_ref.rs:71 (all coverage from this test)

#[test]
fn static_lifetime_param() {
    FormalityTest::new(crates![crate foo {
        trait Trait1<'a> {}

        struct S1 {}

        impl Trait1<'static> for S1 {}

        struct S2 where S1: Trait1<'static> {}
    }])
    .skip_execute()
    .ok()
}

Source location: tests/well_formed_trait_ref.rs:86 (all coverage from this test)

#[test]
fn const_param() {
    FormalityTest::new(crates![crate foo {
        trait Trait1<const C> where type_of_const C is u32 {}

        struct S1 {}

        impl Trait1<u32(3)> for S1 {}

        struct S2 where S1: Trait1<u32(3)> {}
    }])
    .skip_execute()
    .ok()
}

How to read this page