Skip to content

Commit 4034ea3

Browse files
committed
Update substringing when orig & sugg have equal prefixes
1 parent ab92564 commit 4034ea3

File tree

1 file changed

+12
-1
lines changed
  • compiler/rustc_errors/src

1 file changed

+12
-1
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
7575
use rustc_span::source_map::SourceMap;
7676
use rustc_span::{BytePos, DUMMY_SP, Loc, Span};
7777
pub use snippet::Style;
78-
use tracing::debug;
78+
use tracing::{debug, instrument};
7979

8080
use crate::emitter::TimingEvent;
8181
use crate::registry::Registry;
@@ -245,6 +245,7 @@ pub(crate) struct SubstitutionHighlight {
245245
impl SubstitutionPart {
246246
/// Try to turn a replacement into an addition when the span that is being
247247
/// overwritten matches either the prefix or suffix of the replacement.
248+
#[instrument(level = "debug", skip(self, sm))]
248249
fn trim_trivial_replacements(self, sm: &SourceMap) -> TrimmedSubstitutionPart {
249250
let mut trimmed_part = TrimmedSubstitutionPart {
250251
original_span: self.span,
@@ -306,6 +307,16 @@ impl TrimmedSubstitutionPart {
306307
/// `BB` is. Return the length of the prefix, the "trimmed" suggestion, and the length
307308
/// of the suffix.
308309
fn as_substr<'a>(original: &'a str, suggestion: &'a str) -> Option<(usize, &'a str, usize)> {
310+
if suggestion.contains("::")
311+
&& suggestion.ends_with(original)
312+
&& suggestion.len() > original.len()
313+
{
314+
let prefix = &suggestion[..suggestion.len() - original.len()];
315+
if prefix.ends_with("::") && suggestion.chars().next() == original.chars().next() {
316+
return Some((0, prefix, original.len()));
317+
}
318+
}
319+
309320
let common_prefix = original
310321
.chars()
311322
.zip(suggestion.chars())

0 commit comments

Comments
 (0)