Skip to content

Commit f493a59

Browse files
committed
use RefCell and Rc
1 parent 1f8553d commit f493a59

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub fn format_expr(
192192
ast::ExprKind::Mac(ref mac) => {
193193
let should_skip = context
194194
.skip_macro_names
195+
.borrow()
195196
.contains(&context.snippet(mac.node.path.span).to_owned());
196197
if should_skip {
197198
None

src/rewrite.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// A generic trait to abstract the rewriting of an element (of the AST).
22

33
use std::cell::RefCell;
4+
use std::rc::Rc;
45

56
use syntax::parse::ParseSess;
67
use syntax::ptr;
@@ -39,7 +40,7 @@ pub struct RewriteContext<'a> {
3940
// Used for `format_snippet`
4041
pub(crate) macro_rewrite_failure: RefCell<bool>,
4142
pub(crate) report: FormatReport,
42-
pub skip_macro_names: Vec<String>,
43+
pub skip_macro_names: Rc<RefCell<Vec<String>>>,
4344
}
4445

4546
impl<'a> RewriteContext<'a> {

src/visitor.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::cell::RefCell;
2+
use std::rc::Rc;
23

34
use syntax::parse::{token, ParseSess};
45
use syntax::source_map::{self, BytePos, Pos, SourceMap, Span};
@@ -67,7 +68,7 @@ pub struct FmtVisitor<'a> {
6768
pub skipped_range: Vec<(usize, usize)>,
6869
pub macro_rewrite_failure: bool,
6970
pub(crate) report: FormatReport,
70-
pub skip_macro_names: Vec<String>,
71+
pub skip_macro_names: Rc<RefCell<Vec<String>>>,
7172
}
7273

7374
impl<'a> Drop for FmtVisitor<'a> {
@@ -441,7 +442,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
441442
self.push_rewrite(item.span, rewrite);
442443
}
443444
};
444-
self.skip_macro_names.clear();
445+
self.skip_macro_names.borrow_mut().clear();
445446
}
446447

447448
pub fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
@@ -620,7 +621,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
620621
skipped_range: vec![],
621622
macro_rewrite_failure: false,
622623
report,
623-
skip_macro_names: vec![],
624+
skip_macro_names: Rc::new(RefCell::new(vec![])),
624625
}
625626
}
626627

@@ -846,7 +847,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
846847
if let token::Token::Ident(_, _) = token {
847848
// FIXME ident.span.lo() and ident.span.hi() are 0
848849
let macro_name = self.get_context().snippet(span).to_owned();
849-
self.skip_macro_names.push(macro_name);
850+
self.skip_macro_names.borrow_mut().push(macro_name);
850851
}
851852
}
852853
}

0 commit comments

Comments
 (0)