Skip to content

On unresolved names, should the compiler suggest relative paths (super::…) instead of absolute ones if possible? #72136

@leonardo-m

Description

@leonardo-m

This is wrong code:

use std::iter::once;

mod foo {
    fn bar() {
        let _ = once(1);
    }
}

fn main() {}

Rustc currently (1.45.0-nightly 99cb9cc 2020-05-11) gives:

error[E0425]: cannot find function `once` in this scope
 --> ...\test.rs:5:17
  |
5 |         let _ = once(1);
  |                 ^^^^ not found in this scope
  |
help: consider importing one of these items
  |
4 |     use core::iter::once;
  |
4 |     use std::iter::once;
  |

warning: unused import: `std::iter::once`
 --> ...\test.rs:1:5
  |
1 | use std::iter::once;
  |     ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error: aborting due to previous error; 1 warning emitted

But I think it could suggest to write super::once(1); instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-discussionCategory: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions