Skip to content

Commit 0a4988a

Browse files
committed
c2rust-refactor: Print more information on assertion failure in lone()
1 parent 9ae2c2f commit 0a4988a

File tree

1 file changed

+5
-4
lines changed
  • c2rust-refactor/src/util

1 file changed

+5
-4
lines changed

c2rust-refactor/src/util/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use rustc_ast::*;
33
use rustc_span::Symbol;
44
use smallvec::SmallVec;
5+
use std::fmt::Debug;
56

67
pub mod cursor;
78
pub mod dataflow;
@@ -17,16 +18,16 @@ impl<T> Lone<T> for T {
1718
}
1819
}
1920

20-
impl<T> Lone<T> for Vec<T> {
21+
impl<T: Debug> Lone<T> for Vec<T> {
2122
fn lone(mut self) -> T {
22-
assert!(self.len() == 1);
23+
assert!(self.len() == 1, "Vec has multiple elements: {self:#?}");
2324
self.pop().unwrap()
2425
}
2526
}
2627

27-
impl<T> Lone<T> for SmallVec<[T; 1]> {
28+
impl<T: Debug> Lone<T> for SmallVec<[T; 1]> {
2829
fn lone(mut self) -> T {
29-
assert!(self.len() == 1);
30+
assert!(self.len() == 1, "SmallVec has multiple elements: {self:#?}");
3031
self.pop().unwrap()
3132
}
3233
}

0 commit comments

Comments
 (0)