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

Negative coverage: prove_predicate / built-in Sized / premise prove_sized(decls, env, assumptions, ty) => c

Premise at line 94. Observed failure causes: failed_judgment.

built-in Sized
LineCoverageSource
92✗(if trait_id.is_sized())
93✗(let (ty,) = parameters.downcast_err::<(Ty,)>()?)
949(prove_sized(decls, env, assumptions, ty) => c)
──────── ("built-in Sized")
9630(prove_predicate(decls, env, assumptions, AtomicPredicate::IsImplemented(TraitRef { trait_id, parameters })) => c)

9 tests failed proving this premise:


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

#[test]
fn generic_parameter_requires_explicit_sized_bound() {
    // Generated Rust still gives T an implicit Sized bound until #500 lands.
    // Formality must already require an explicit bound on this impl.
    FormalityTest::new(crates![crate Foo {
        trait Needs<T> where T: Sized {}
        impl<T> Needs<T> for u32 {}
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn tuple_requires_every_element_sized() {
    // In rustc, `(T, bool)` isn't even well-formed if `T` is unsized.
    FormalityTest::new(crates![crate Foo {
        trait Needs<T> where T: Sized {}
        impl<T> Needs<(T, bool)> for u32 {}
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn struct_with_generic_tail_requires_sized_tail() {
    // `Tail<T>` is only sized if `T` is.
    FormalityTest::new(crates![crate Foo {
        struct Tail<T> { prefix: u32, tail: T }
        trait Needs<T> where T: Sized {}
        impl<T> Needs<Tail<T>> for u32 {}
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn unsized_non_final_field_is_rejected() {
    // Only the last field of a struct can be unsized.
    FormalityTest::new(crates![crate Foo {
        struct Bad<T> { prefix: T, tail: u32 }
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn unsized_enum_field_is_rejected() {
    // Enum fields must all be sized, even the last one.
    FormalityTest::new(crates![crate Foo {
        enum Maybe<T> { Nothing {}, Just { value: T } }
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn struct_tail_is_checked_after_substitution() {
    // `Pair<u32, X>` ends in `X`, which may be unsized.
    FormalityTest::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 {}
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn struct_tail_is_followed_through_nested_structs() {
    // `Outer<T>` ends in `Tail<T>`, which ends in `T`.
    FormalityTest::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 {}
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

#[test]
fn alias_is_not_sized_if_normalized_type_may_be_unsized() {
    // `<T as Assoc>::Out` normalizes to `T`, which may be unsized.
    FormalityTest::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> {}
    }])
    .rustc_ok()
    .err(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()`"#]]);
}
Failed proof tree

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

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 }
    }));
}
Failed proof tree

How to read this page