Refactor type errors back into macro annotations

Far less verbose than defining classes by hand, plus, it allows to have everything about a single error be co-located. And finally, it allows to use 'related', 'label' and so on more easily.
This commit is contained in:
KtorZ 2023-01-20 20:08:40 +01:00
parent 4459fdb360
commit d321b85df2
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 716 additions and 1102 deletions

File diff suppressed because it is too large Load Diff

View File

@ -27,12 +27,14 @@ impl FieldMap {
if self.is_function { if self.is_function {
Err(Error::DuplicateArgument { Err(Error::DuplicateArgument {
label, label,
locations: vec![*location, location_other], location: *location,
duplicate_location: location_other,
}) })
} else { } else {
Err(Error::DuplicateField { Err(Error::DuplicateField {
label, label,
locations: vec![*location, location_other], location: *location,
duplicate_location: location_other,
}) })
} }
} }
@ -102,7 +104,7 @@ impl FieldMap {
} }
}; };
let (position, other_location) = match self.fields.get(label) { let (position, duplicate_location) = match self.fields.get(label) {
None => { None => {
unknown_labels.push((label.clone(), location)); unknown_labels.push((label.clone(), location));
@ -122,7 +124,8 @@ impl FieldMap {
} else { } else {
if seen_labels.contains(label) { if seen_labels.contains(label) {
return Err(Error::DuplicateArgument { return Err(Error::DuplicateArgument {
locations: vec![location, other_location], location,
duplicate_location,
label: label.to_string(), label: label.to_string(),
}); });
} }

View File

@ -404,6 +404,28 @@ impl Diagnostic for Error {
Error::UnknownPackageVersion { .. } => None, Error::UnknownPackageVersion { .. } => None,
} }
} }
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
match self {
Error::DuplicateModule { .. } => None,
Error::FileIo { .. } => None,
Error::ImportCycle { .. } => None,
Error::List { .. } => None,
Error::Parse { .. } => None,
Error::Type { error, .. } => error.related(),
Error::StandardIo(_) => None,
Error::MissingManifest { .. } => None,
Error::TomlLoading { .. } => None,
Error::Format { .. } => None,
Error::ValidatorMustReturnBool { .. } => None,
Error::WrongValidatorArity { .. } => None,
Error::TestFailure { .. } => None,
Error::Http { .. } => None,
Error::ZipExtract { .. } => None,
Error::JoinError { .. } => None,
Error::UnknownPackageVersion { .. } => None,
}
}
} }
#[derive(thiserror::Error)] #[derive(thiserror::Error)]