use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AugmentKind {
Augment,
UsesAugment,
}
impl fmt::Display for AugmentKind {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
AugmentKind::Augment => write!(f, "augment"),
AugmentKind::UsesAugment => write!(f, "uses augment"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Diagnostic {
AugmentTargetNotAbsolute { module: String, target: String },
AugmentTargetNotDescendant { module: String, target: String },
AugmentTargetNotFound {
kind: AugmentKind,
module: String,
target: String,
missing: String,
},
AugmentIntoLeaf {
module: String,
target: String,
leaf: String,
},
AugmentDuplicateNode {
module: String,
target: String,
name: String,
},
}
impl fmt::Display for Diagnostic {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Diagnostic::AugmentTargetNotAbsolute { module, target } => write!(
f,
"{module}: augment target \"{target}\" must use the absolute form (leading '/')"
),
Diagnostic::AugmentTargetNotDescendant { module, target } => write!(
f,
"{module}: uses augment target \"{target}\" must use the descendant form \
(no leading '/')"
),
Diagnostic::AugmentTargetNotFound {
kind,
module,
target,
missing,
} => write!(
f,
"{module}: {kind} target \"{target}\" not found \
(no node matching \"{missing}\")"
),
Diagnostic::AugmentIntoLeaf {
module,
target,
leaf,
} => write!(
f,
"{module}: augment cannot add nodes to leaf target \"{leaf}\" ({target})"
),
Diagnostic::AugmentDuplicateNode {
module,
target,
name,
} => write!(
f,
"{module}: augment node \"{name}\" already exists in target \"{target}\"; \
not added"
),
}
}
}