Skip to content

Commit aee12c6

Browse files
committed
fix ICE when {{root}} appears in import suggestions
1 parent 95a27ad commit aee12c6

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2223,7 +2223,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22232223
match binding.kind {
22242224
NameBindingKind::Import { import, .. } => {
22252225
for segment in import.module_path.iter().skip(1) {
2226-
path.push(segment.ident);
2226+
// Don't include `{{root}}` in suggestions - it's an internal symbol
2227+
// that should never be shown to users.
2228+
if segment.ident.name != kw::PathRoot {
2229+
path.push(segment.ident);
2230+
}
22272231
}
22282232
sugg_paths.push((
22292233
path.iter().cloned().chain(std::iter::once(ident)).collect::<Vec<_>>(),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Issue: https://github.com/rust-lang/rust/issues/150103
2+
// ICE when using `::` at start of nested imports
3+
// caused by `{{root}}` appearing in diagnostic suggestions
4+
5+
mod A {
6+
use Iuse::{ ::Fish }; //~ ERROR failed to resolve: use of unresolved module or unlinked crate
7+
}
8+
9+
mod B {
10+
use A::{::Fish}; //~ ERROR failed to resolve: crate root in paths can only be used in start position
11+
}
12+
13+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `Iuse`
2+
--> $DIR/issue-150103-nested-path-root.rs:5:9
3+
|
4+
LL | use Iuse::{ ::Fish };
5+
| ^^^^ use of unresolved module or unlinked crate `Iuse`
6+
|
7+
help: you might be missing a crate named `Iuse`, add it to your project and import it in your code
8+
|
9+
LL + extern crate Iuse;
10+
|
11+
12+
error[E0433]: failed to resolve: crate root in paths can only be used in start position
13+
--> $DIR/issue-150103-nested-path-root.rs:9:13
14+
|
15+
LL | use A::{::Fish};
16+
| ^ crate root in paths can only be used in start position
17+
18+
error: aborting due to 2 previous errors
19+
20+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)