pub struct Report<T> { /* private fields */ }Expand description
What checking a match found: missing cases, unreachable arms, and redundant or-pattern alternatives.
§Examples
use match_lang::{check, Arm, Model, Pat, Signature};
struct Flag;
impl Model for Flag {
type Ty = ();
fn signature(&self, _: &()) -> Signature<()> {
Signature::Bool
}
fn fields(&self, _: &(), _: u32, _: &mut Vec<()>) {}
}
let arms = [
Arm::new(Pat::bool(true)),
Arm::new(Pat::or([Pat::bool(false), Pat::bool(true)])),
Arm::new(Pat::wild()),
];
let report = check(&Flag, &(), &arms)?;
assert!(report.is_exhaustive());
assert_eq!(report.unreachable(), &[2]);
assert_eq!(report.redundant()[0].arm, 1);
assert_eq!(report.redundant()[0].node, 2); // the second alternative, `true`Implementations§
Source§impl<T> Report<T>
impl<T> Report<T>
Sourcepub fn is_exhaustive(&self) -> bool
pub fn is_exhaustive(&self) -> bool
Whether every value of the scrutinee’s type is matched by some unguarded arm.
§Examples
let guarded = [Arm::guarded(Pat::wild())];
assert!(!check(&Flag, &(), &guarded)?.is_exhaustive());Sourcepub fn missing(&self) -> &[Witness<T>]
pub fn missing(&self) -> &[Witness<T>]
Witnesses of values no unguarded arm matches; empty exactly when the match is exhaustive. There is at least one when it is not, and at most the witness limit. They are a sample chosen to be informative, not an enumeration of every missing value.
§Examples
let report = check(&Flag, &(), &[])?;
let missing: Vec<String> = report.missing().iter().map(|w| w.to_string()).collect();
assert_eq!(missing, ["false", "true"]);Sourcepub fn unreachable(&self) -> &[usize]
pub fn unreachable(&self) -> &[usize]
The indices of arms no value can reach, in ascending order. An arm is unreachable when every value its pattern matches is matched by an earlier unguarded arm, or when its pattern matches no value at all.
§Examples
let arms = [Arm::new(Pat::wild()), Arm::new(Pat::bool(true))];
assert_eq!(check(&Flag, &(), &arms)?.unreachable(), &[1]);Sourcepub fn redundant(&self) -> &[Redundant]
pub fn redundant(&self) -> &[Redundant]
Or-pattern alternatives that no value reaches, inside arms that are themselves reachable, in arm order and then preorder. Only the outermost redundant alternative is reported: alternatives nested inside it are not listed again.
An alternative is redundant when every value it matches is matched by an earlier unguarded arm or, in an unguarded arm, by an earlier alternative of the same arm.
§Examples
// `true | false | true`: node 0 is the or-pattern, 1..=3 its alternatives.
let arms = [Arm::new(Pat::or([Pat::bool(true), Pat::bool(false), Pat::bool(true)]))];
let report = check(&Flag, &(), &arms)?;
assert_eq!(report.redundant(), &[Redundant { arm: 0, node: 3 }]);Sourcepub fn steps(&self) -> u64
pub fn steps(&self) -> u64
The number of steps the check took, against the step limit. Useful to see how close real matches come to the limit.
§Examples
let report = check(&Flag, &(), &[Arm::new(Pat::wild())])?;
assert!(report.steps() > 0);