Don't allocate for missing or existing members by default

- Missing members are zero in the happy case
- Existing members will always be populated in the happy case, but I
  don't think they improve the error message, so just get rid of it.
This commit is contained in:
Ayaz Hafiz 2022-05-19 18:25:42 -04:00
parent b03e713b7f
commit 768121e431
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 8 additions and 38 deletions

View file

@ -36,7 +36,6 @@ pub enum Unfulfilled {
Incomplete { Incomplete {
typ: Symbol, typ: Symbol,
ability: Symbol, ability: Symbol,
specialized_members: Vec<Loc<Symbol>>,
missing_members: Vec<Loc<Symbol>>, missing_members: Vec<Loc<Symbol>>,
}, },
/// Cannot derive implementation of an ability for a type. /// Cannot derive implementation of an ability for a type.
@ -170,17 +169,15 @@ impl ObligationCache<'_> {
match typ { match typ {
Obligated::Opaque(typ) => { Obligated::Opaque(typ) => {
let members_of_ability = self.abilities_store.members_of_ability(ability).unwrap(); let members_of_ability = self.abilities_store.members_of_ability(ability).unwrap();
let mut specialized_members = Vec::with_capacity(members_of_ability.len()); let mut missing_members = Vec::new();
let mut missing_members = Vec::with_capacity(members_of_ability.len());
for &member in members_of_ability { for &member in members_of_ability {
match self.abilities_store.get_specialization(member, typ) { if self
None => { .abilities_store
let root_data = self.abilities_store.member_def(member).unwrap(); .get_specialization(member, typ)
missing_members.push(Loc::at(root_data.region, member)); .is_none()
} {
Some(specialization) => { let root_data = self.abilities_store.member_def(member).unwrap();
specialized_members.push(Loc::at(specialization.region, member)); missing_members.push(Loc::at(root_data.region, member));
}
} }
} }
@ -190,7 +187,6 @@ impl ObligationCache<'_> {
Unfulfilled::Incomplete { Unfulfilled::Incomplete {
typ, typ,
ability, ability,
specialized_members,
missing_members, missing_members,
}, },
); );

View file

@ -232,7 +232,6 @@ fn report_unfulfilled_ability<'a>(
Unfulfilled::Incomplete { Unfulfilled::Incomplete {
typ, typ,
ability, ability,
specialized_members,
missing_members, missing_members,
} => { } => {
debug_assert!(!missing_members.is_empty()); debug_assert!(!missing_members.is_empty());
@ -254,24 +253,6 @@ fn report_unfulfilled_ability<'a>(
stack.push(alloc.region(lines.convert_region(member.region))); stack.push(alloc.region(lines.convert_region(member.region)));
} }
if !specialized_members.is_empty() {
stack.push(alloc.concat([
alloc.note(""),
alloc.symbol_unqualified(typ),
alloc.reflow(" specializes the following members of "),
alloc.symbol_unqualified(ability),
alloc.reflow(":"),
]));
for spec in specialized_members {
stack.push(alloc.concat([
alloc.symbol_unqualified(spec.value),
alloc.reflow(", specialized here:"),
]));
stack.push(alloc.region(lines.convert_region(spec.region)));
}
}
alloc.stack(stack) alloc.stack(stack)
} }
Unfulfilled::Underivable { Unfulfilled::Underivable {

View file

@ -9379,13 +9379,6 @@ All branches in an `if` must have the same type!
5 le : a, a -> Bool | a has Eq 5 le : a, a -> Bool | a has Eq
^^ ^^
Note: `Id` specializes the following members of `Eq`:
`eq`, specialized here:
9 eq = \@Id m, @Id n -> m == n
^^
"# "#
), ),
) )