Skip to content

Commit 10fbdb8

Browse files
committed
save-analysis: power through bracket mis-counts
Closes #47981 This is pretty unsatisfying since it is working around a span bug. However, I can't track down the span bug and it could be in the parser, proc macro expansion, the user macro, or Syn (or any other library that can manipulate spans). Given that user code can cause this error, I think we need to be more robust here.
1 parent 3ec5a99 commit 10fbdb8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/librustc_save_analysis/span_utils.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'a> SpanUtils<'a> {
115115
// We keep track of the following two counts - the depth of nesting of
116116
// angle brackets, and the depth of nesting of square brackets. For the
117117
// angle bracket count, we only count tokens which occur outside of any
118-
// square brackets (i.e. bracket_count == 0). The intutition here is
118+
// square brackets (i.e. bracket_count == 0). The intuition here is
119119
// that we want to count angle brackets in the type, but not any which
120120
// could be in expression context (because these could mean 'less than',
121121
// etc.).
@@ -151,18 +151,20 @@ impl<'a> SpanUtils<'a> {
151151
}
152152
prev = next;
153153
}
154-
if angle_count != 0 || bracket_count != 0 {
155-
let loc = self.sess.codemap().lookup_char_pos(span.lo());
156-
span_bug!(
157-
span,
158-
"Mis-counted brackets when breaking path? Parsing '{}' \
159-
in {}, line {}",
160-
self.snippet(span),
161-
loc.file.name,
162-
loc.line
163-
);
154+
#[cfg(debug_assertions)] {
155+
if angle_count != 0 || bracket_count != 0 {
156+
let loc = self.sess.codemap().lookup_char_pos(span.lo());
157+
span_bug!(
158+
span,
159+
"Mis-counted brackets when breaking path? Parsing '{}' \
160+
in {}, line {}",
161+
self.snippet(span),
162+
loc.file.name,
163+
loc.line
164+
);
165+
}
164166
}
165-
if result.is_none() && prev.tok.is_ident() && angle_count == 0 {
167+
if result.is_none() && prev.tok.is_ident() {
166168
return Some(prev.sp);
167169
}
168170
result

0 commit comments

Comments
 (0)