Skip to content

Commit 7ca560d

Browse files
committed
save-analysis: fix a bracket counting bug
1 parent 952614b commit 7ca560d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/librustc_trans/save/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
111111
let qualname = format!("::{}", self.analysis.ty_cx.map.path_to_string(item.id));
112112

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

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

121121
Data::VariableData(VariableData {
122122
id: item.id,

src/librustc_trans/save/span_utils.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a> SpanUtils<'a> {
237237

238238
let mut toks = self.retokenise_span(span);
239239
// We keep track of how many brackets we're nested in
240-
let mut bracket_count = 0;
240+
let mut bracket_count: isize = 0;
241241
let mut found_ufcs_sep = false;
242242
loop {
243243
let ts = toks.real_token();
@@ -255,19 +255,16 @@ impl<'a> SpanUtils<'a> {
255255
}
256256
bracket_count += match ts.tok {
257257
token::Lt => 1,
258-
token::Gt => {
259-
// Ignore the `>::` in `<Type as Trait>::AssocTy`.
260-
if !found_ufcs_sep && bracket_count == 0 {
261-
found_ufcs_sep = true;
262-
0
263-
} else {
264-
-1
265-
}
266-
}
258+
token::Gt => -1,
267259
token::BinOp(token::Shl) => 2,
268260
token::BinOp(token::Shr) => -2,
269261
_ => 0
270262
};
263+
// Ignore the `>::` in `<Type as Trait>::AssocTy`.
264+
if !found_ufcs_sep && bracket_count == -1 {
265+
found_ufcs_sep = true;
266+
bracket_count += 1
267+
}
271268
if ts.tok.is_ident() && bracket_count == nesting {
272269
result.push(self.make_sub_span(span, Some(ts.sp)).unwrap());
273270
}

src/test/run-make/save-analysis/foo.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,15 @@ impl Iterator for nofields {
352352
panic!()
353353
}
354354
}
355+
356+
trait Pattern<'a> {
357+
type Searcher;
358+
}
359+
360+
struct CharEqPattern;
361+
362+
impl<'a> Pattern<'a> for CharEqPattern {
363+
type Searcher = CharEqPattern;
364+
}
365+
366+
struct CharSearcher<'a>(<CharEqPattern as Pattern<'a>>::Searcher);

0 commit comments

Comments
 (0)