Skip to content

Commit 4616a4d

Browse files
committed
Render some errors a bit more human readably
1 parent 7c11e92 commit 4616a4d

File tree

8 files changed

+56
-18
lines changed

8 files changed

+56
-18
lines changed

crates/formality-check/src/coherence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,6 @@ impl Check<'_> {
154154

155155
return Ok(());
156156
}
157-
bail!("impls may overlap: `{impl_a:?}` vs `{impl_b:?}`")
157+
bail!("impls may overlap:\n{impl_a:?}\n{impl_b:?}")
158158
}
159159
}

crates/formality-check/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,6 @@ impl Check<'_> {
149149
return Ok(());
150150
}
151151

152-
bail!("failed to disprove {goal:?} given {assumptions:?}, got {cs:?}")
152+
bail!("failed to disprove\n {goal:?}\ngiven\n {assumptions:?}\ngot\n{cs:#?}")
153153
}
154154
}

tests/coherence_overlap.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ fn test_overlap_normalize_alias_to_LocalType() {
5151
// ...but it's an error if LocalType implements Iterator (figuring *this* out also
5252
// requires normalizing).
5353

54-
expect_test::expect![[r#"
55-
Err(
56-
"impls may overlap: `impl <ty> LocalTrait < > for ^ty0_0 where [^ty0_0 : Iterator < >] { }` vs `impl <> LocalTrait < > for (alias (Mirror :: T) (rigid (adt LocalType))) where [] { }`",
57-
)
58-
"#]]
59-
.assert_debug_eq(&test_program_ok(&gen_program("impl<> Iterator<> for LocalType<> where [] {}")));
54+
expect_test::expect![[r#"Err(
55+
"impls may overlap:\nimpl <ty> LocalTrait < > for ^ty0_0 where [^ty0_0 : Iterator < >] { }\nimpl <> LocalTrait < > for (alias (Mirror :: T) (rigid (adt LocalType))) where [] { }",
56+
)
57+
"#]]
58+
.assert_debug_eq(&test_program_ok(&gen_program(
59+
"impl<> Iterator<> for LocalType<> where [] {}",
60+
)));
6061
}
6162

6263
#[test]
@@ -110,11 +111,10 @@ fn test_overlap_alias_not_normalizable() {
110111

111112
// ...as long as there is at least one Iterator impl, however, we do flag an error.
112113

113-
expect_test::expect![[r#"
114-
Err(
115-
"impls may overlap: `impl <ty> LocalTrait < > for ^ty0_0 where [^ty0_0 : Iterator < >] { }` vs `impl <ty> LocalTrait < > for (alias (Mirror :: T) ^ty0_0) where [^ty0_0 : Mirror < >] { }`",
116-
)
117-
"#]] // FIXME
114+
expect_test::expect![[r#"Err(
115+
"impls may overlap:\nimpl <ty> LocalTrait < > for ^ty0_0 where [^ty0_0 : Iterator < >] { }\nimpl <ty> LocalTrait < > for (alias (Mirror :: T) ^ty0_0) where [^ty0_0 : Mirror < >] { }",
116+
)
117+
"#]] // FIXME
118118
.assert_debug_eq(&test_program_ok(&gen_program(
119119
"impl<> Iterator<> for u32 where[] {}",
120120
)));
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
Error: check_trait_impl(impl <ty> Foo < > for ^ty0_0 where [^ty0_0 : Foo < >] { })
22

33
Caused by:
4-
failed to disprove {! Foo(!ty_1)} given {Foo(!ty_1)}, got {Constraints { env: Env { variables: [?ty_1], coherence_mode: false }, known_true: true, substitution: {?ty_1 => (rigid (scalar u32))} }}
4+
failed to disprove
5+
{! Foo(!ty_1)}
6+
given
7+
{Foo(!ty_1)}
8+
got
9+
{
10+
Constraints {
11+
env: Env {
12+
variables: [
13+
?ty_1,
14+
],
15+
coherence_mode: false,
16+
},
17+
known_true: true,
18+
substitution: {
19+
?ty_1 => (rigid (scalar u32)),
20+
},
21+
},
22+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Error: impls may overlap: `impl <ty> FooTrait < > for ^ty0_0 where [^ty0_0 : CoreTrait < >] { }` vs `impl <> FooTrait < > for (rigid (adt CoreStruct)) where [] { }`
1+
Error: impls may overlap:
2+
impl <ty> FooTrait < > for ^ty0_0 where [^ty0_0 : CoreTrait < >] { }
3+
impl <> FooTrait < > for (rigid (adt CoreStruct)) where [] { }
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Error: impls may overlap: `impl <> Foo < > for (rigid (scalar u32)) where [] { }` vs `impl <ty> Foo < > for ^ty0_0 where [] { }`
1+
Error: impls may overlap:
2+
impl <> Foo < > for (rigid (scalar u32)) where [] { }
3+
impl <ty> Foo < > for ^ty0_0 where [] { }
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Error: impls may overlap: `impl <> Foo < > for (rigid (scalar u32)) where [] { }` vs `impl <ty> Foo < > for ^ty0_0 where [^ty0_0 : Is < >] { }`
1+
Error: impls may overlap:
2+
impl <> Foo < > for (rigid (scalar u32)) where [] { }
3+
impl <ty> Foo < > for ^ty0_0 where [^ty0_0 : Is < >] { }
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
Error: check_trait_impl(impl <> Foo < > for (rigid (scalar u32)) where [] { })
22

33
Caused by:
4-
failed to disprove {! Foo((rigid (scalar u32)))} given {}, got {Constraints { env: Env { variables: [], coherence_mode: false }, known_true: true, substitution: {} }}
4+
failed to disprove
5+
{! Foo((rigid (scalar u32)))}
6+
given
7+
{}
8+
got
9+
{
10+
Constraints {
11+
env: Env {
12+
variables: [],
13+
coherence_mode: false,
14+
},
15+
known_true: true,
16+
substitution: {},
17+
},
18+
}

0 commit comments

Comments
 (0)