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 / assumption

assumption
LineCoverageSource
48✗(a in assumptions)
4935(prove_via(decls, env, assumptions, a, goal) => c)
──────── ("assumption")
5135(prove_predicate(decls, env, assumptions, Predicate::AtomicPredicate(goal)) => c)

35 tests exercised this rule:


Source location: crates/formality-rust/src/prove/test/eq_assumptions.rs:15 (all coverage from this test)

#[test]
fn test_a() {
    test_prove(
        Program::empty(),
        term("{} => {for<T, U> if {T = u32, U = Vec<T>} U = Vec<u32>}"),
    )
    .assert_ok(expect!["{Constraints { env: Env { variables: [], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {} }}"]);
}
Proof tree

Source location: crates/formality-rust/src/prove/test/eq_assumptions.rs:33 (all coverage from this test)

#[test]
fn test_normalize_assoc_ty() {
    test_prove(
        Program::empty(),
        term("{} => {for<T> if { <T as Iterator>::Item = u32 } <T as Iterator>::Item = u32}"),
    )
    .assert_ok(expect!["{Constraints { env: Env { variables: [], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {} }}"]);
}
Proof tree

Source location: crates/formality-rust/src/prove/test/eq_partial_eq.rs:25 (all coverage from this test)

#[test]
fn eq_implies_partial_eq() {
    let assumptions: Predicates = Predicates::t();
    let goal: Predicate = term("for<T> if {Eq(T)} PartialEq(T)");
    let constraints = prove(decls(), (), assumptions, goal);
    constraints.assert_ok(
    expect!["{Constraints { env: Env { variables: [], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {} }}"]);
}
Proof tree

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: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/borrowck.rs:5028 (all coverage from this test)

fn use_it<'a, 'b>() -> u32 {
    exists<'r0> {
        let v: Invariant<'r0> = create_invariant::<'r0>();
        if true {
            return sink::<'a, 'r0>(v);
        } else {
            return sink::<'b, 'r0>(v);
        }
    }
}
Proof tree
… (200 of 1519 nodes shown)

Source location: tests/borrowck.rs:5093 (all coverage from this test)

fn use_it_but_its_the_same_region<'a, 'b>() -> u32 where 'a: 'b, 'b: 'a {
    exists<'r0> {
        let v: Invariant<'r0> = create_invariant::<'r0>();
        if true {
            return sink::<'a, 'r0>(v);
        } else {
            return sink::<'b, 'r0>(v);
        }
    }
}
Proof tree
… (200 of 1527 nodes shown)

Source location: tests/borrowck.rs:5167 (all coverage from this test)

fn f() -> u32 {
    exists<'r0> {
        let v: u32 = 0_u32;
        let w: Wrapper<'r0> = Wrapper::<'r0> { value: &'r0 v };
        return *w.value;
    }
}
Proof tree
… (200 of 1531 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 tree

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()
}

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


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/consts.rs:27 (all coverage from this test)

#[test]
fn ok() {
    FormalityTest::new(crates![crate Foo {
        trait Foo<const C> where type_of_const C is bool {}
        trait Bar<const C> where type_of_const C is u32 {}

        impl<const C> Foo<C> for u32 where type_of_const C is bool {}
    }])
    .skip_execute()
    .ok()
}

Source location: tests/consts.rs:100 (all coverage from this test)

#[test]
fn generic_match() {
    FormalityTest::new(crates![crate Foo {
        trait Foo<const C> where type_of_const C is bool {}

        // Here, the impl matches the trait bound.
        impl<const C> Foo<C> for u32 where type_of_const C is bool {}
    }])
    .skip_execute()
    .ok()
}

Source location: tests/consts.rs:166 (all coverage from this test)


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


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: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/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/pr502_liveness_prototypes.rs:134 (all coverage from this test)

fn f() -> () {
    exists<'r0, 'r1> {
        let v: u32 = 0_u32;
        let r: &'r0 u32 = &'r0 v;
        let p: Pair<'r1> = Pair::<'r1> { a: *r, b: &'r1 mut v };
        println!(p.a);
    }
}

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

#[test]
fn normalize_basic() {
    test_where_clause(
        NORMALIZE_BASIC,
        "forall<T> exists<U> {} => { <Vec<T> as Iterator>::Item = U }",
    )
    .assert_ok(expect_test::expect!["{Constraints { env: Env { variables: [!ty_1, ?ty_2], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {?ty_2 => <Vec<!ty_1> as Iterator>::Item} }, Constraints { env: Env { variables: [!ty_1, ?ty_2], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {?ty_2 => !ty_1} }}"]);

    test_where_clause(
        NORMALIZE_BASIC,
        "forall<T> {} => { Iterator(Vec<T>), <Vec<T> as Iterator>::Item = T }",
    )
    .assert_ok(expect_test::expect!["{Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {} }}"]);

    test_where_clause(
        NORMALIZE_BASIC,
        "forall<T> { Iterator(T), <T as Iterator>::Item = Foo } => { <T as Iterator>::Item = Foo }",
    ).assert_ok(
        expect_test::expect!["{Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {} }}"]
    );

    test_where_clause(
        NORMALIZE_BASIC,
        "forall<T> exists<U> { Iterator(T) } => { <T as Iterator>::Item = U }",
    )
    .assert_ok(expect_test::expect!["{Constraints { env: Env { variables: [!ty_1, ?ty_2], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {?ty_2 => <!ty_1 as Iterator>::Item} }}"]);

    test_where_clause(
        NORMALIZE_BASIC,
        "forall<T> { Iterator(T) } => { <T as Iterator>::Item = <T as Iterator>::Item }",
    )
    .assert_ok(expect_test::expect!["{Constraints { env: Env { variables: [!ty_1], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {} }}"]);

    test_where_clause(
        NORMALIZE_BASIC,
        "forall<T> exists<U> { Iterator(T) } => { <T as Iterator>::Item = <U as Iterator>::Item }",
    ).assert_ok(
    expect_test::expect!["{Constraints { env: Env { variables: [!ty_1, ?ty_2], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {?ty_2 => !ty_1} }, Constraints { env: Env { variables: [!ty_1, ?ty_3, ?ty_2], bias: Soundness, pending: [], allow_pending_outlives: false }, known_true: true, substitution: {?ty_2 => Vec<<!ty_1 as Iterator>::Item>, ?ty_3 => <!ty_1 as Iterator>::Item} }}"]);
}

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


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: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: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/well_formed_struct.rs:17 (all coverage from this test)

fn main() -> () {
    exists<'y> {
        let a: u32 = 22_u32;
        let f: Foo<'y> = Foo::<'y> { y: &'y 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()
}

How to read this page