Skip to content

Suggest type or module with similar name when code is incorrect #56982

Open
@ariasuni

Description

@ariasuni

Given the following code:

use std::ffi::CString;

fn main() {
    let s = Cstring::new("hello").unwrap();
}

rustc gives me this output:

error[E0433]: failed to resolve: use of undeclared type or module `Cstring`
 --> main.rs:4:13
  |
4 |     let s = Cstring::new("hello").unwrap();
  |             ^^^^^^^ use of undeclared type or module `Cstring`

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

error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.

when it should give something like this:

error[E0433]: failed to resolve: use of undeclared type or module `Cstring`
 --> main.rs:4:13
  |
4 |     let s = Cstring::new("hello").unwrap();
  |             ^^^^^^^ did you mean `CString`?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions