Skip to content

Commit

Permalink
save-analysis: fix a bracket counting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed May 14, 2015
1 parent 952614b commit 7ca560d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/librustc_trans/save/mod.rs
Expand Up @@ -111,12 +111,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));

// If the variable is immutable, save the initialising expression.
let value = match mt {
ast::MutMutable => String::from_str("<mutable>"),
ast::MutImmutable => self.span_utils.snippet(expr.span),
let (value, keyword) = match mt {
ast::MutMutable => (String::from_str("<mutable>"), keywords::Mut),
ast::MutImmutable => (self.span_utils.snippet(expr.span), keywords::Static),
};

let sub_span = self.span_utils.sub_span_after_keyword(item.span, keywords::Static);
let sub_span = self.span_utils.sub_span_after_keyword(item.span, keyword);

Data::VariableData(VariableData {
id: item.id,
Expand Down
17 changes: 7 additions & 10 deletions src/librustc_trans/save/span_utils.rs
Expand Up @@ -237,7 +237,7 @@ impl<'a> SpanUtils<'a> {

let mut toks = self.retokenise_span(span);
// We keep track of how many brackets we're nested in
let mut bracket_count = 0;
let mut bracket_count: isize = 0;
let mut found_ufcs_sep = false;
loop {
let ts = toks.real_token();
Expand All @@ -255,19 +255,16 @@ impl<'a> SpanUtils<'a> {
}
bracket_count += match ts.tok {
token::Lt => 1,
token::Gt => {
// Ignore the `>::` in `<Type as Trait>::AssocTy`.
if !found_ufcs_sep && bracket_count == 0 {
found_ufcs_sep = true;
0
} else {
-1
}
}
token::Gt => -1,
token::BinOp(token::Shl) => 2,
token::BinOp(token::Shr) => -2,
_ => 0
};
// Ignore the `>::` in `<Type as Trait>::AssocTy`.
if !found_ufcs_sep && bracket_count == -1 {
found_ufcs_sep = true;
bracket_count += 1
}
if ts.tok.is_ident() && bracket_count == nesting {
result.push(self.make_sub_span(span, Some(ts.sp)).unwrap());
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/run-make/save-analysis/foo.rs
Expand Up @@ -352,3 +352,15 @@ impl Iterator for nofields {
panic!()
}
}

trait Pattern<'a> {
type Searcher;
}

struct CharEqPattern;

impl<'a> Pattern<'a> for CharEqPattern {
type Searcher = CharEqPattern;
}

struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);

0 comments on commit 7ca560d

Please sign in to comment.