Skip to content

Commit 1322e47

Browse files
committed
Improve debug logs of find_width_of_character_at_span
1 parent a1fc711 commit 1322e47

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

compiler/rustc_span/src/source_map.rs

+12-17
Original file line numberDiff line numberDiff line change
@@ -964,45 +964,40 @@ impl SourceMap {
964964

965965
/// Finds the width of the character, either before or after the end of provided span,
966966
/// depending on the `forwards` parameter.
967+
#[instrument(skip(self, sp))]
967968
fn find_width_of_character_at_span(&self, sp: Span, forwards: bool) -> u32 {
968969
let sp = sp.data();
969970

970971
if sp.lo == sp.hi && !forwards {
971-
debug!("find_width_of_character_at_span: early return empty span");
972+
debug!("early return empty span");
972973
return 1;
973974
}
974975

975976
let local_begin = self.lookup_byte_offset(sp.lo);
976977
let local_end = self.lookup_byte_offset(sp.hi);
977-
debug!(
978-
"find_width_of_character_at_span: local_begin=`{:?}`, local_end=`{:?}`",
979-
local_begin, local_end
980-
);
978+
debug!("local_begin=`{:?}`, local_end=`{:?}`", local_begin, local_end);
981979

982980
if local_begin.sf.start_pos != local_end.sf.start_pos {
983-
debug!("find_width_of_character_at_span: begin and end are in different files");
981+
debug!("begin and end are in different files");
984982
return 1;
985983
}
986984

987985
let start_index = local_begin.pos.to_usize();
988986
let end_index = local_end.pos.to_usize();
989-
debug!(
990-
"find_width_of_character_at_span: start_index=`{:?}`, end_index=`{:?}`",
991-
start_index, end_index
992-
);
987+
debug!("start_index=`{:?}`, end_index=`{:?}`", start_index, end_index);
993988

994989
// Disregard indexes that are at the start or end of their spans, they can't fit bigger
995990
// characters.
996991
if (!forwards && end_index == usize::MIN) || (forwards && start_index == usize::MAX) {
997-
debug!("find_width_of_character_at_span: start or end of span, cannot be multibyte");
992+
debug!("start or end of span, cannot be multibyte");
998993
return 1;
999994
}
1000995

1001996
let source_len = (local_begin.sf.end_pos - local_begin.sf.start_pos).to_usize();
1002-
debug!("find_width_of_character_at_span: source_len=`{:?}`", source_len);
997+
debug!("source_len=`{:?}`", source_len);
1003998
// Ensure indexes are also not malformed.
1004999
if start_index > end_index || end_index > source_len - 1 {
1005-
debug!("find_width_of_character_at_span: source indexes are malformed");
1000+
debug!("source indexes are malformed");
10061001
return 1;
10071002
}
10081003

@@ -1017,10 +1012,10 @@ impl SourceMap {
10171012
} else {
10181013
return 1;
10191014
};
1020-
debug!("find_width_of_character_at_span: snippet=`{:?}`", snippet);
1015+
debug!("snippet=`{:?}`", snippet);
10211016

10221017
let mut target = if forwards { end_index + 1 } else { end_index - 1 };
1023-
debug!("find_width_of_character_at_span: initial target=`{:?}`", target);
1018+
debug!("initial target=`{:?}`", target);
10241019

10251020
while !snippet.is_char_boundary(target - start_index) && target < source_len {
10261021
target = if forwards {
@@ -1033,9 +1028,9 @@ impl SourceMap {
10331028
}
10341029
}
10351030
};
1036-
debug!("find_width_of_character_at_span: target=`{:?}`", target);
1031+
debug!("target=`{:?}`", target);
10371032
}
1038-
debug!("find_width_of_character_at_span: final target=`{:?}`", target);
1033+
debug!("final target=`{:?}`", target);
10391034

10401035
if forwards { (target - end_index) as u32 } else { (end_index - target) as u32 }
10411036
}

0 commit comments

Comments
 (0)