save-analysis: fix a bracket counting bug
This commit is contained in:
parent
952614bc8b
commit
7ca560d6ab
3 changed files with 23 additions and 14 deletions
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue