Skip to content

Commit bd09b81

Browse files
committed
fix(test): improve mutants coverage
1 parent 9da763e commit bd09b81

3 files changed

Lines changed: 63 additions & 11 deletions

File tree

src/main.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,5 +438,65 @@ mod test {
438438
10
439439
);
440440
}
441+
442+
#[test]
443+
#[should_panic(expected = "Type")]
444+
fn trait_impl_mismatch() {
445+
run(r#"trait MyTrait {
446+
fn some_method() -> Self;
447+
}
448+
449+
impl MyTrait for u8 {
450+
fn some_method(parameter: bool) -> Self {
451+
10
452+
}
453+
}
454+
455+
fn main() -> u8 {
456+
<u8 as MyTrait>::some_method()
457+
}"#);
458+
}
459+
460+
#[test]
461+
#[should_panic(expected = "type must implement trait")]
462+
fn trait_not_implemented() {
463+
run(r#"trait MyTrait {
464+
fn some_method() -> Self;
465+
}
466+
467+
fn main() -> u8 {
468+
<u8 as MyTrait>::some_method()
469+
}"#);
470+
}
471+
472+
#[test]
473+
fn complex_path_usage() {
474+
assert_eq!(
475+
run(r#"trait MyTrait {
476+
fn some_method() -> Self;
477+
}
478+
479+
impl MyTrait for u8 {
480+
fn some_method() -> Self {
481+
10
482+
}
483+
}
484+
485+
fn fallback() -> u8 {
486+
3
487+
}
488+
489+
fn main() -> u8 {
490+
let get_num = if true {
491+
<u8 as MyTrait>::some_method
492+
} else {
493+
fallback
494+
};
495+
496+
get_num()
497+
}"#),
498+
10
499+
);
500+
}
441501
}
442502
}

src/passes/hir_gen.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ impl FunctionCtx {
561561
dead_code,
562562
reason = "tracking current trait may be useful for diagnostics"
563563
)]
564+
#[mutants::skip(reason = "dead code")]
564565
fn current_trait(&self) -> Option<TraitId> {
565566
match self {
566567
Self::TraitMethod { current_trait, .. } => Some(*current_trait),
@@ -573,6 +574,7 @@ impl FunctionCtx {
573574
dead_code,
574575
reason = "tracking current method may be useful for diagnostics"
575576
)]
577+
#[mutants::skip(reason = "dead code")]
576578
fn current_trait_method(&self) -> Option<TraitMethodId> {
577579
match self {
578580
Self::TraitMethod { method, .. } => Some(*method),

src/util/scopes.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl<B: BindingKind> PartialEq for BindingId<B> {
3939
}
4040
impl<B: BindingKind> Eq for BindingId<B> {}
4141
impl<B: BindingKind> Hash for BindingId<B> {
42+
#[mutants::skip(reason = "tests don't cover hashing")]
4243
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
4344
self.id.hash(state);
4445
}
@@ -71,17 +72,6 @@ impl<B: BindingKind> Binding<B> {
7172
}
7273
}
7374
}
74-
impl<B: BindingKind> TryFrom<ErasedBinding> for Binding<B> {
75-
type Error = ErasedBinding;
76-
77-
fn try_from(binding: ErasedBinding) -> Result<Self, Self::Error> {
78-
if binding.kind == B::get_marker() {
79-
return Err(binding);
80-
}
81-
82-
Ok(Self::new(binding.string))
83-
}
84-
}
8575

8676
/// Type-erased version of [`Binding`], using [`BindingKindMarker`] instead of a generic.
8777
#[derive(Clone, Debug, Hash, PartialEq, Eq)]

0 commit comments

Comments
 (0)