about summary refs log tree commit diff
path: root/src
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 /src
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 'src')
-rw-r--r--src/tools/clippy/clippy_utils/src/sugg.rs3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/tools/clippy/clippy_utils/src/sugg.rs b/src/tools/clippy/clippy_utils/src/sugg.rs
index 3c5dd92b9cd..3347342e412 100644
--- a/src/tools/clippy/clippy_utils/src/sugg.rs
+++ b/src/tools/clippy/clippy_utils/src/sugg.rs
@@ -769,8 +769,7 @@ impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
 
     fn suggest_remove_item(&mut self, cx: &T, item: Span, msg: &str, applicability: Applicability) {
         let mut remove_span = item;
-        let hi = cx.sess().source_map().next_point(remove_span).hi();
-        let fmpos = cx.sess().source_map().lookup_byte_offset(hi);
+        let fmpos = cx.sess().source_map().lookup_byte_offset(remove_span.hi());
 
         if let Some(ref src) = fmpos.sf.src {
             let non_whitespace_offset = src[fmpos.pos.to_usize()..].find(|c| c != ' ' && c != '\t' && c != '\n');