Skip to content

Commit c151b28

Browse files
committed
customize debug impl for assoc ty
could be better
1 parent 394ba0c commit c151b28

File tree

7 files changed

+46
-21
lines changed

7 files changed

+46
-21
lines changed

crates/formality-types/src/grammar/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub enum ScalarId {
188188
}
189189

190190
#[term((alias $name $*parameters))]
191-
#[customize(parse)]
191+
#[customize(parse, debug)]
192192
pub struct AliasTy {
193193
pub name: AliasName,
194194
pub parameters: Parameters,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1+
use super::{AliasName, AliasTy, AssociatedTyName};
2+
use std::fmt::Debug;
13

4+
impl Debug for AliasTy {
5+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6+
let AliasTy { name, parameters } = self;
7+
match name {
8+
AliasName::AssociatedTyId(AssociatedTyName { trait_id, item_id }) => {
9+
// Grr, wish we would remember the number of parameters assigned to each position.
10+
write!(
11+
f,
12+
"({:?}::{:?})<{}>",
13+
trait_id,
14+
item_id,
15+
parameters
16+
.iter()
17+
.map(|p| format!("{p:?}"))
18+
.collect::<Vec<String>>()
19+
.join(","),
20+
)
21+
}
22+
}
23+
}
24+
}

tests/associated_type_normalization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn test_mirror_normalizes_u32_to_u32() {
3939
},
4040
known_true: true,
4141
substitution: {
42-
?ty_1 => (alias (Mirror :: Assoc) (rigid (scalar u32))),
42+
?ty_1 => (Mirror::Assoc)<(rigid (scalar u32))>,
4343
},
4444
},
4545
},

tests/coherence_overlap.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ 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#"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-
"#]]
54+
expect_test::expect![[r#"
55+
Err(
56+
"impls may overlap:\nimpl <ty> LocalTrait < > for ^ty0_0 where [^ty0_0 : Iterator < >] { }\nimpl <> LocalTrait < > for (Mirror::T)<(rigid (adt LocalType))> where [] { }",
57+
)
58+
"#]]
5859
.assert_debug_eq(&test_program_ok(&gen_program(
5960
"impl<> Iterator<> for LocalType<> where [] {}",
6061
)));
@@ -111,10 +112,11 @@ fn test_overlap_alias_not_normalizable() {
111112

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

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
115+
expect_test::expect![[r#"
116+
Err(
117+
"impls may overlap:\nimpl <ty> LocalTrait < > for ^ty0_0 where [^ty0_0 : Iterator < >] { }\nimpl <ty> LocalTrait < > for (Mirror::T)<^ty0_0> where [^ty0_0 : Mirror < >] { }",
118+
)
119+
"#]] // FIXME
118120
.assert_debug_eq(&test_program_ok(&gen_program(
119121
"impl<> Iterator<> for u32 where[] {}",
120122
)));

tests/projection.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn normalize_basic() {
3131
},
3232
known_true: true,
3333
substitution: {
34-
?ty_2 => (alias (Iterator :: Item) (rigid (adt Vec) !ty_1)),
34+
?ty_2 => (Iterator::Item)<(rigid (adt Vec) !ty_1)>,
3535
},
3636
},
3737
Constraints {
@@ -110,7 +110,7 @@ fn normalize_basic() {
110110
},
111111
known_true: true,
112112
substitution: {
113-
?ty_2 => (alias (Iterator :: Item) !ty_1),
113+
?ty_2 => (Iterator::Item)<!ty_1>,
114114
},
115115
},
116116
},
@@ -169,8 +169,8 @@ fn normalize_basic() {
169169
},
170170
known_true: true,
171171
substitution: {
172-
?ty_2 => (rigid (adt Vec) (alias (Iterator :: Item) !ty_1)),
173-
?ty_3 => (alias (Iterator :: Item) !ty_1),
172+
?ty_2 => (rigid (adt Vec) (Iterator::Item)<!ty_1>),
173+
?ty_3 => (Iterator::Item)<!ty_1>,
174174
},
175175
},
176176
},
@@ -221,7 +221,7 @@ fn normalize_into_iterator() {
221221
},
222222
known_true: true,
223223
substitution: {
224-
?ty_2 => (alias (IntoIterator :: Item) (rigid (adt Vec) !ty_1)),
224+
?ty_2 => (IntoIterator::Item)<(rigid (adt Vec) !ty_1)>,
225225
},
226226
},
227227
Constraints {
@@ -286,7 +286,7 @@ fn projection_equality() {
286286
},
287287
known_true: true,
288288
substitution: {
289-
?ty_1 => (alias (Trait1 :: Type) (rigid (adt S))),
289+
?ty_1 => (Trait1::Type)<(rigid (adt S))>,
290290
},
291291
},
292292
},
@@ -321,7 +321,7 @@ fn projection_equality() {
321321
},
322322
known_true: true,
323323
substitution: {
324-
?ty_1 => (alias (Trait1 :: Type) (rigid (adt S))),
324+
?ty_1 => (Trait1::Type)<(rigid (adt S))>,
325325
},
326326
},
327327
},
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: orphan_check(impl <> CoreTrait < > for (alias (Unit :: Assoc) (rigid (adt FooStruct))) where [] { })
1+
Error: orphan_check(impl <> CoreTrait < > for (Unit::Assoc)<(rigid (adt FooStruct))> where [] { })
22

33
Caused by:
4-
failed to prove {@ IsLocal(CoreTrait((alias (Unit :: Assoc) (rigid (adt FooStruct)))))} given {}, got {}
4+
failed to prove {@ IsLocal(CoreTrait((Unit::Assoc)<(rigid (adt FooStruct))>))} given {}, got {}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Error: orphan_check(impl <> CoreTrait < > for (alias (Mirror :: Assoc) (rigid (adt CoreStruct))) where [] { })
1+
Error: orphan_check(impl <> CoreTrait < > for (Mirror::Assoc)<(rigid (adt CoreStruct))> where [] { })
22

33
Caused by:
4-
failed to prove {@ IsLocal(CoreTrait((alias (Mirror :: Assoc) (rigid (adt CoreStruct)))))} given {}, got {}
4+
failed to prove {@ IsLocal(CoreTrait((Mirror::Assoc)<(rigid (adt CoreStruct))>))} given {}, got {}

0 commit comments

Comments
 (0)