Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub use rustc_span::fatal_error::{FatalError, FatalErrorMarker};
use rustc_span::source_map::SourceMap;
use rustc_span::{BytePos, DUMMY_SP, Loc, Span};
pub use snippet::Style;
use tracing::debug;
use tracing::{debug, instrument};

use crate::emitter::TimingEvent;
use crate::registry::Registry;
Expand Down Expand Up @@ -245,6 +245,7 @@ pub(crate) struct SubstitutionHighlight {
impl SubstitutionPart {
/// Try to turn a replacement into an addition when the span that is being
/// overwritten matches either the prefix or suffix of the replacement.
#[instrument(level = "debug", skip(self, sm))]
fn trim_trivial_replacements(self, sm: &SourceMap) -> TrimmedSubstitutionPart {
let mut trimmed_part = TrimmedSubstitutionPart {
original_span: self.span,
Expand Down Expand Up @@ -306,6 +307,16 @@ impl TrimmedSubstitutionPart {
/// `BB` is. Return the length of the prefix, the "trimmed" suggestion, and the length
/// of the suffix.
fn as_substr<'a>(original: &'a str, suggestion: &'a str) -> Option<(usize, &'a str, usize)> {
if suggestion.contains("::")
&& suggestion.ends_with(original)
&& suggestion.len() > original.len()
{
let prefix = &suggestion[..suggestion.len() - original.len()];
if prefix.ends_with("::") && suggestion.chars().next() == original.chars().next() {
return Some((0, prefix, original.len()));
}
}

let common_prefix = original
.chars()
.zip(suggestion.chars())
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/test-attrs/inaccessible-test-modules.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LL | use test as y;
help: consider importing this module instead
|
LL | use test::test as y;
| ++++++
| ++++++

error: aborting due to 2 previous errors

Expand Down
Loading