Skip to content

Commit 9ffa1fb

Browse files
Auto merge of #148061 - faculerena:master, r=<try>
Update substring match for substitutions try-job: aarch64-gnu-llvm-20-1
2 parents 055d0d6 + a57969b commit 9ffa1fb

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ impl TrimmedSubstitutionPart {
303303
/// `BB` is. Return the length of the prefix, the "trimmed" suggestion, and the length
304304
/// of the suffix.
305305
fn as_substr<'a>(original: &'a str, suggestion: &'a str) -> Option<(usize, &'a str, usize)> {
306+
// Case for import paths where the suggestion shares a prefix with the original.
307+
// Without this, suggesting `std::sync` for `sync` would incorrectly highlight `td::s`
308+
// instead of `std::` because of the common 's' prefix. See #148070.
309+
if suggestion.contains("::")
310+
&& suggestion.ends_with(original)
311+
&& suggestion.len() > original.len()
312+
&& let prefix = &suggestion[..suggestion.len() - original.len()]
313+
&& prefix.ends_with("::")
314+
&& suggestion.chars().next() == original.chars().next()
315+
{
316+
return Some((0, prefix, original.len()));
317+
}
318+
306319
let common_prefix = original
307320
.chars()
308321
.zip(suggestion.chars())
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// https://github.com/rust-lang/rust/issues/148070
2+
#![no_main]
3+
use stat; //~ ERROR unresolved import `stat`
4+
use str; //~ ERROR unresolved import `str`
5+
use sync; //~ ERROR unresolved import `sync`
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
error[E0432]: unresolved import `stat`
2+
--> $DIR/same-prefix-unresolved-import-148070.rs:3:5
3+
|
4+
LL | use stat;
5+
| ^^^^ no `stat` in the root
6+
|
7+
help: consider importing this struct instead
8+
|
9+
LL | use std::os::linux::raw::stat;
10+
| +++++++++++++++++++++
11+
12+
error[E0432]: unresolved import `str`
13+
--> $DIR/same-prefix-unresolved-import-148070.rs:4:5
14+
|
15+
LL | use str;
16+
| ^^^ no `str` in the root
17+
|
18+
help: a similar name exists in the module
19+
|
20+
LL - use str;
21+
LL + use std;
22+
|
23+
help: consider importing one of these items instead
24+
|
25+
LL | use std::primitive::str;
26+
| ++++++++++++++++
27+
LL | use std::str;
28+
| +++++
29+
30+
error[E0432]: unresolved import `sync`
31+
--> $DIR/same-prefix-unresolved-import-148070.rs:5:5
32+
|
33+
LL | use sync;
34+
| ^^^^ no `sync` in the root
35+
|
36+
help: consider importing this module instead
37+
|
38+
LL | use std::sync;
39+
| +++++
40+
41+
error: aborting due to 3 previous errors
42+
43+
For more information about this error, try `rustc --explain E0432`.

tests/ui/test-attrs/inaccessible-test-modules.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | use test as y;
1313
help: consider importing this module instead
1414
|
1515
LL | use test::test as y;
16-
| ++++++
16+
| ++++++
1717

1818
error: aborting due to 2 previous errors
1919

0 commit comments

Comments
 (0)