Skip to content

Commit 4b655b9

Browse files
committed
Fix recursive Scope Debug impl
1 parent fb8351c commit 4b655b9

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

vm/src/frame.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,19 @@ impl<'a, T> Iterator for Iter<'a, T> {
7676
}
7777
}
7878

79-
#[derive(Debug, Clone)]
79+
#[derive(Clone)]
8080
pub struct Scope {
8181
locals: RcList<PyObjectRef>,
8282
pub globals: PyObjectRef,
8383
}
8484

85+
impl fmt::Debug for Scope {
86+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87+
// TODO: have a more informative Debug impl that DOESN'T recurse and cause a stack overflow
88+
f.write_str("Scope")
89+
}
90+
}
91+
8592
impl Scope {
8693
pub fn new(locals: Option<PyObjectRef>, globals: PyObjectRef) -> Scope {
8794
let locals = match locals {
@@ -99,10 +106,7 @@ impl Scope {
99106
}
100107

101108
pub fn get_only_locals(&self) -> Option<PyObjectRef> {
102-
match self.locals.iter().next() {
103-
Some(dict) => Some(dict.clone()),
104-
None => None,
105-
}
109+
self.locals.iter().next().cloned()
106110
}
107111

108112
pub fn child_scope_with_locals(&self, locals: PyObjectRef) -> Scope {
@@ -1212,21 +1216,18 @@ impl fmt::Debug for Frame {
12121216
.borrow()
12131217
.iter()
12141218
.map(|elem| format!("\n > {:?}", elem))
1215-
.collect::<Vec<_>>()
1216-
.join("");
1219+
.collect::<String>();
12171220
let block_str = self
12181221
.blocks
12191222
.borrow()
12201223
.iter()
12211224
.map(|elem| format!("\n > {:?}", elem))
1222-
.collect::<Vec<_>>()
1223-
.join("");
1225+
.collect::<String>();
12241226
let local_str = match self.scope.get_locals().payload::<PyDict>() {
12251227
Some(dict) => objdict::get_key_value_pairs_from_content(&dict.entries.borrow())
12261228
.iter()
12271229
.map(|elem| format!("\n {:?} = {:?}", elem.0, elem.1))
1228-
.collect::<Vec<_>>()
1229-
.join(""),
1230+
.collect::<String>(),
12301231
None => panic!("locals unexpectedly not wrapping a dict!",),
12311232
};
12321233
write!(

0 commit comments

Comments
 (0)