about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-10-20 10:40:09 +0000
committerbors <bors@rust-lang.org>2022-10-20 10:40:09 +0000
commit53728ff751df4c271d4ea565b6871057a3504fc5 (patch)
tree554ce71e5e7e9b3f2f951f23fb017c36339d7d94 /compiler/rustc_parse/src/parser/expr.rs
parent4b3b731b55a588dd34a75bbb87fdaaec2e3f5707 (diff)
parenteb8aa9759dc99b604145f94e5296b7add60e0a48 (diff)
downloadrust-53728ff751df4c271d4ea565b6871057a3504fc5.tar.gz
rust-53728ff751df4c271d4ea565b6871057a3504fc5.zip
Auto merge of #103185 - chenyukang:yukang/fix-span-next-point, r=davidtwco
Fix the bug of next_point in source_map

There is a bug in `next_point`, the new span won't move to next position when be called in the first time.

For this reason, our current code is working like this:
1. When we really want to move to the next position, we called two times of `next_point`
2. Some code which use `next_point` actually done the same thing with `shrink_to_hi`

This fix make sure when `next_point` is called, span will move with the width at least 1, and also work correctly in the scenario of multiple bytes.

Ref: https://github.com/rust-lang/rust/pull/103140#discussion_r997710998

r? `@davidtwco`
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 11301f03e48..afa116ce1bc 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2172,7 +2172,7 @@ impl<'a> Parser<'a> {
                     },
                 ExprKind::Block(_, None) => {
                     self.sess.emit_err(IfExpressionMissingCondition {
-                        if_span: self.sess.source_map().next_point(lo),
+                        if_span: lo.shrink_to_hi(),
                         block_span: self.sess.source_map().start_point(cond_span),
                     });
                     std::mem::replace(&mut cond, this.mk_expr_err(cond_span.shrink_to_hi()))