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:
parent
4459fdb360
commit
d321b85df2
File diff suppressed because it is too large
Load Diff
|
@ -27,12 +27,14 @@ impl FieldMap {
|
|||
if self.is_function {
|
||||
Err(Error::DuplicateArgument {
|
||||
label,
|
||||
locations: vec![*location, location_other],
|
||||
location: *location,
|
||||
duplicate_location: location_other,
|
||||
})
|
||||
} else {
|
||||
Err(Error::DuplicateField {
|
||||
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 => {
|
||||
unknown_labels.push((label.clone(), location));
|
||||
|
||||
|
@ -122,7 +124,8 @@ impl FieldMap {
|
|||
} else {
|
||||
if seen_labels.contains(label) {
|
||||
return Err(Error::DuplicateArgument {
|
||||
locations: vec![location, other_location],
|
||||
location,
|
||||
duplicate_location,
|
||||
label: label.to_string(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -404,6 +404,28 @@ impl Diagnostic for Error {
|
|||
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)]
|
||||
|
|
Loading…
Reference in New Issue