Skip to content

Using super and self in middle of path gives unhelpful error message #45229

Closed
@Havvy

Description

@Havvy
use a_module::self::AnItem as Test1;
use a_module::super::a_module::AnItem as Test2;

mod a_module {
    struct AnItem;
}

fn main () {}
Current Error Message
Compiling playground v0.0.1 (file:///playground)
error[E0432]: unresolved import `a_module::self`
 --> src/main.rs:1:15
  |
1 | use a_module::self::AnItem as Test1;
  |               ^^^^ Could not find `self` in `a_module`

error[E0432]: unresolved import `a_module::super`
 --> src/main.rs:2:15
  |
2 | use a_module::super::a_module::AnItem as Test2;
  |               ^^^^^ Could not find `super` in `a_module`

warning: unused import: `a_module::self::AnItem as Test1`
 --> src/main.rs:1:5
  |
1 | use a_module::self::AnItem as Test1;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

warning: unused import: `a_module::super::a_module::AnItem as Test2`
 --> src/main.rs:2:5
  |
2 | use a_module::super::a_module::AnItem as Test2;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Ignoring the warnings (they're good warnings), the errors should state that `self` and `super` are only allowed before non-`self` and `super` path components.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyWG-diagnosticsWorking group: Diagnostics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions