mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Fix an arithmetic overflow in reparser
This commit is contained in:
parent
4c7142d0c9
commit
0acb61a911
@ -130,11 +130,11 @@ fn merge_errors(
|
|||||||
if e.offset() <= old_node.range().start() {
|
if e.offset() <= old_node.range().start() {
|
||||||
res.push(e)
|
res.push(e)
|
||||||
} else if e.offset() >= old_node.range().end() {
|
} else if e.offset() >= old_node.range().end() {
|
||||||
res.push(e.add_offset(TextUnit::of_str(&edit.insert) - edit.delete.len()));
|
res.push(e.add_offset(TextUnit::of_str(&edit.insert), edit.delete.len()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for e in new_errors {
|
for e in new_errors {
|
||||||
res.push(e.add_offset(old_node.range().start()));
|
res.push(e.add_offset(old_node.range().start(), 0.into()));
|
||||||
}
|
}
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,10 @@ impl SyntaxError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_offset(mut self, plus_offset: TextUnit) -> SyntaxError {
|
pub fn add_offset(mut self, plus_offset: TextUnit, minus_offset: TextUnit) -> SyntaxError {
|
||||||
self.location = match self.location {
|
self.location = match self.location {
|
||||||
Location::Range(range) => Location::Range(range + plus_offset),
|
Location::Range(range) => Location::Range(range + plus_offset - minus_offset),
|
||||||
Location::Offset(offset) => Location::Offset(offset + plus_offset),
|
Location::Offset(offset) => Location::Offset(offset + plus_offset - minus_offset),
|
||||||
};
|
};
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
0
|
||||||
|
1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
0
|
Loading…
x
Reference in New Issue
Block a user